├── .devcontainer ├── Dockerfile ├── devcontainer.json └── scripts │ ├── onCreateCommand.sh │ └── postCreateCommand.sh ├── .gitignore ├── README.md └── setup └── spring-cli └── spring-cli-0.7.0.jar /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/ubuntu/.devcontainer/base.Dockerfile 2 | 3 | # [Choice] Ubuntu version (use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon): ubuntu-22.04, ubuntu-20.04, ubuntu-18.04 4 | ARG VARIANT="jammy" 5 | FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT} 6 | 7 | RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 8 | && apt-get -y install --no-install-recommends direnv 9 | 10 | 11 | # Install httpie 12 | RUN curl -SsL https://packages.httpie.io/deb/KEY.gpg | sudo gpg --dearmor -o /usr/share/keyrings/httpie.gpg && \ 13 | echo "deb [arch=amd64 signed-by=/usr/share/keyrings/httpie.gpg] https://packages.httpie.io/deb ./" > /etc/apt/sources.list.d/httpie.list && \ 14 | apt-get update -q && \ 15 | apt-get install -yq httpie 16 | 17 | # Add alias for spring 18 | RUN echo 'alias spring="java -jar /workspaces/spring-ai-azure-workshop/setup/spring-cli/spring-cli-0.7.0.jar"' >> /etc/bash.bashrc 19 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: 2 | // https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/ubuntu 3 | { 4 | "name": "acme-fitness-store", 5 | "build": { 6 | "dockerfile": "Dockerfile", 7 | // Update 'VARIANT' to pick an Ubuntu version: jammy / ubuntu-22.04, focal / ubuntu-20.04, bionic /ubuntu-18.04 8 | // Use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon. 9 | "args": { 10 | "VARIANT": "ubuntu-22.04" 11 | } 12 | }, 13 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 14 | // "forwardPorts": [], 15 | "onCreateCommand": "./.devcontainer/scripts/onCreateCommand.sh", 16 | // Use 'postCreateCommand' to run commands after the container is created. 17 | // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. 18 | "remoteUser": "vscode", 19 | "hostRequirements": { 20 | "cpus": 2 21 | }, 22 | "containerEnv": { 23 | "GRADLE_USER_HOME": "/home/vscode", // required because the java feature is not setting this correctly 24 | "M2": "/home/vscode" // required because the java feature is not setting this correctly 25 | }, 26 | "features": { 27 | "azure-cli": "latest", 28 | "docker-from-docker": "latest", 29 | "node": "lts", 30 | "ghcr.io/devcontainers/features/java:1": { 31 | "version": "17", 32 | "installGradle": true, 33 | "installMaven": true 34 | } 35 | }, 36 | "postCreateCommand": "./.devcontainer/scripts/postCreateCommand.sh" 37 | 38 | 39 | } -------------------------------------------------------------------------------- /.devcontainer/scripts/onCreateCommand.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x 4 | 5 | az extension add --name spring 6 | 7 | -------------------------------------------------------------------------------- /.devcontainer/scripts/postCreateCommand.sh: -------------------------------------------------------------------------------- 1 | alias spring="java -jar /workspaces/spring-ai-azure-workshop/setup/spring-cli/spring-cli-0.7.0.jar" 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### STS ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | 15 | ### IntelliJ IDEA ### 16 | .idea 17 | *.iws 18 | *.iml 19 | *.ipr 20 | 21 | ### NetBeans ### 22 | /nbproject/private/ 23 | /nbbuild/ 24 | /dist/ 25 | /nbdist/ 26 | /.nb-gradle/ 27 | build/ 28 | !**/src/main/**/build/ 29 | !**/src/test/**/build/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | 34 | # Compiled class file 35 | *.class 36 | 37 | # Log file 38 | *.log 39 | 40 | # BlueJ files 41 | *.ctxt 42 | 43 | # Mobile Tools for Java (J2ME) 44 | .mtj.tmp/ 45 | 46 | # Package Files # 47 | *.jar 48 | *.war 49 | *.nar 50 | *.ear 51 | *.zip 52 | *.tar.gz 53 | *.rar 54 | 55 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 56 | hs_err_pid* 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spring-ai-workshop 2 | Workshop material for Spring AI 3 | 4 | The workshop uses the Spring CLI project. If you are not using GitHub codespaces, [download the Spring CLI](https://github.com/spring-projects-experimental/spring-cli/releases). 5 | You can browse the [Spring CLI Documentation](https://docs.spring.io/spring-cli/reference/0.7-SNAPSHOT/index.html) to learn more about its features. 6 | 7 | A quick summary is that the Spring CLI provides a command line application named `spring` 8 | 9 | You will create the code for Exercise #1, the "Hello World" AI project, using the command `spring boot new`. See below. 10 | 11 | The code for additional exercises will use the command `spring boot add` 12 | 13 | To access the projects used in these exercises, we first need to add the `ai-azure-catalog`. 14 | 15 | 16 | You will also need to have the `curl` like tool [httpie](https://httpie.io/docs/cli/installation) installed. 17 | 18 | Now, let's get started! 19 | 20 | ## Add exercises to the spring project catalog 21 | 22 | ```shell 23 | spring project-catalog add azure-ai https://github.com/rd-1-2022/ai-azure-catalog 24 | ``` 25 | 26 | ## Exercise #1 - Create the first Hello World project 27 | 28 | Create a new project using the following command. You can pick a different 29 | 30 | * name: The following example uses the name `myai` as the project name 31 | * package name: The following example uses the name `com.xkcd.ai` in honor of [XKCD](https://xkcd.com/). 32 | 33 | ```shell 34 | spring boot new myai ai-azure-hello-world --package-name com.xkcd.ai 35 | ``` 36 | 37 | You will now have a project with the structure shown below 38 | 39 | 40 | ```shell 41 | cd myai 42 | ``` 43 | 44 | ```shell 45 | $ tree 46 | . 47 | ├── mvnw 48 | ├── mvnw.cmd 49 | ├── pom.xml 50 | ├── README.md 51 | └── src 52 | └── main 53 | ├── java 54 | │   └── com 55 | │   └── xkcd 56 | │   └── ai 57 | │   ├── Application.java 58 | │   └── helloworld 59 | │   ├── Completion.java 60 | │   └── SimpleAiController.java 61 | └── resources 62 | └── application.properties 63 | ``` 64 | 65 | Follow the instuctions in `README.md` to complete the exercise. 66 | 67 | ## Exercise #2 - Prompt Templating 68 | 69 | ** MAKE SURE YOU ARE IN THE ROOT OF THE JAVA PROJECT ** 70 | 71 | Now add the code for Prompt Templating 72 | 73 | ```shell 74 | spring boot add ai-azure-prompt-templating 75 | ``` 76 | 77 | Look at the `README-ai-azure-prompt-templating.md` file for instructions. 78 | 79 | Your directory tree should look like: 80 | 81 | ```shell 82 | $ tree 83 | . 84 | ├── mvnw 85 | ├── mvnw.cmd 86 | ├── pom.xml 87 | ├── README-ai-azure-prompt-templating.md 88 | ├── README.md 89 | └── src 90 | └── main 91 | ├── java 92 | │   └── com 93 | │   └── xkcd 94 | │   └── ai 95 | │   ├── Application.java 96 | │   ├── helloworld 97 | │   │   ├── Completion.java 98 | │   │   └── SimpleAiController.java 99 | │   └── prompttemplate 100 | │   └── PromptTemplateController.java 101 | └── resources 102 | ├── application.properties 103 | └── prompts 104 | └── joke-prompt.st 105 | ``` 106 | 107 | ## Exercise #3 - Prompt Roles 108 | 109 | Now add the code for the Prompt Roles exercise. 110 | 111 | ```shell 112 | spring boot add ai-azure-prompt-roles 113 | ``` 114 | 115 | Look at the `README-ai-azure-prompt-roles.md` file for instructions. 116 | 117 | 118 | ## Exercise #4 - Output Parser 119 | 120 | Now add the code for Output Parser exercise. 121 | 122 | ```shell 123 | spring boot add ai-azure-output-parser 124 | ``` 125 | 126 | Look at the `README-ai-azure-output-parser.md` file for instructions. 127 | 128 | ## Exercise #5 - Chains 129 | 130 | Now add the code for Chains exercise. 131 | 132 | ```shell 133 | spring boot add ai-azure-chains 134 | ``` 135 | 136 | Look at the `README-ai-azure-chains.md` file for instructions. 137 | 138 | 139 | ## Exercise #6 - Stuff the Prompt 140 | 141 | Now add the code for the Stuff the Prompt exercise. 142 | 143 | ```shell 144 | spring boot add ai-azure-stuff-prompt 145 | ``` 146 | Look at the `README-ai-azure-chains.md` file for instructions. 147 | 148 | ## Exercise #7 - Retrieval Augmented Generation 149 | 150 | Now add the code for the Retrieval Augmented Generation exercise. 151 | 152 | ```shell 153 | spring boot add ai-azure-rag 154 | ``` 155 | Look at the `README-ai-azure-retrieval-augmented-generation.md` file for instructions. 156 | -------------------------------------------------------------------------------- /setup/spring-cli/spring-cli-0.7.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/markpollack/spring-ai-azure-workshop/65fc7cc9ba12acb91f6b034711f544502bebd4fc/setup/spring-cli/spring-cli-0.7.0.jar --------------------------------------------------------------------------------