Skip to content

Commit 853a606

Browse files
committed
Switch by default to the openai demo account
1 parent 48ef273 commit 853a606

File tree

5 files changed

+47
-34
lines changed

5 files changed

+47
-34
lines changed

README.md

+27-9
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ This project consists of several microservices:
7979
- **Customers Service**: Manages customer data.
8080
- **Vets Service**: Handles information about veterinarians.
8181
- **Visits Service**: Manages pet visit records.
82+
- **GenAI Service**: Provides a chatbot interface to the application.
8283
- **API Gateway**: Routes client requests to the appropriate services.
8384
- **Config Server**: Centralized configuration management for all services.
8485
- **Discovery Server**: Eureka-based service registry.
@@ -102,16 +103,33 @@ Spring Petclinic integrates a Chatbot that allows you to interact with the appli
102103
3. Is there an owner named Betty?
103104
4. Which owners have dogs?
104105
5. Add a dog for Betty. Its name is Moopsie.
105-
6. Create a new owner
106+
6. Create a new owner.
107+
108+
![Screenshot of the chat dialog](docs/spring-ai.png)
109+
110+
This `spring-petlinic-genai-service` microservice currently supports **OpenAI** (default) or **Azure's OpenAI** as the LLM provider.
111+
In order to start the microservice, perform the following steps:
112+
113+
1. Decide which provider you want to use. By default, the `spring-ai-openai-spring-boot-starter` dependency is enabled.
114+
You can change it to `spring-ai-azure-openai-spring-boot-starter`in the `pom.xml`.
115+
2. Create an OpenAI API key or a Azure OpenAI resource in your Azure Portal.
116+
Refer to the [OpenAI's quickstart](https://platform.openai.com/docs/quickstart) or [Azure's documentation](https://learn.microsoft.com/en-us/azure/ai-services/openai/) for further information on how to obtain these.
117+
You only need to populate the provider you're using - either openai, or azure-openai.
118+
If you don't have your own OpenAI API key, don't worry!
119+
You can temporarily use the `demo` key, which OpenAI provides free of charge for demonstration purposes.
120+
This `demo` key has a quota, is limited to the `gpt-4o-mini` model, and is intended solely for demonstration use.
121+
With your own OpenAI account, you can test the `gpt-4o` model by modifying the `deployment-name` property of the `application.yml` file.
122+
3. Export your API keys and endpoint as environment variables:
123+
* either OpenAI:
124+
```bash
125+
export OPENAI_API_KEY="your_api_key_here"
126+
```
127+
* or Azure OpenAI:
128+
```bash
129+
export AZURE_OPENAI_ENDPOINT="https://your_resource.openai.azure.com"
130+
export AZURE_OPENAI_KEY="your_api_key_here"
131+
```
106132

107-
![alt text](docs/spring-ai.png)
108-
109-
This Microservice currently supports OpenAI or Azure's OpenAI as the LLM provider.
110-
In order to enable Spring AI, perform the following steps:
111-
112-
1. Decide which provider you want to use. By default, the `spring-ai-azure-openai-spring-boot-starter` dependency is enabled. You can change it to `spring-ai-openai-spring-boot-starter`in `pom.xml`.
113-
2. Copy `src/main/resources/creds-template.yaml` into `src/main/resources/creds.yaml`, and edit its contents with your API key and API endpoint. Refer to OpenAI's or Azure's documentation for further information on how to obtain these. You only need to populate the provider you're using - either openai, or azure-openai.
114-
3. Boot the `spring-petclinic-genai-service` microservice.
115133
## In case you find a bug/suggested improvement for Spring Petclinic Microservices
116134

117135
Our issue tracker is available here: https://github.com/spring-petclinic/spring-petclinic-microservices/issues

spring-petclinic-genai-service/pom.xml

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
<properties>
1818
<docker.image.exposed.port>8081</docker.image.exposed.port>
1919
<docker.image.dockerfile.dir>${basedir}/../docker</docker.image.dockerfile.dir>
20-
<spring-ai.version>1.0.0-M3</spring-ai.version>
20+
<spring-ai.version>1.0.0-M4</spring-ai.version>
2121
</properties>
2222

2323
<dependencies>
2424
<!-- Spring Boot -->
2525
<dependency>
2626
<groupId>org.springframework.ai</groupId>
27-
<artifactId>spring-ai-azure-openai-spring-boot-starter</artifactId>
27+
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
28+
<!-- artifactId>spring-ai-azure-openai-spring-boot-starter</artifactId-->
2829
</dependency>
2930
<dependency>
3031
<groupId>org.springframework.boot</groupId>
@@ -168,7 +169,7 @@
168169
</snapshots>
169170
</repository>
170171
</repositories>
171-
172+
172173
<profiles>
173174
<profile>
174175
<id>buildDocker</id>

spring-petclinic-genai-service/src/main/java/org/springframework/samples/petclinic/genai/PetclinicChatClient.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,22 @@ public PetclinicChatClient(ChatClient.Builder builder, ChatMemory chatMemory) {
3737
you don't know the answer, then ask the user a followup question to try and clarify the question they are asking.
3838
If you do know the answer, provide the answer but do not provide any additional followup questions.
3939
When dealing with vets, if the user is unsure about the returned results, explain that there may be additional data that was not returned.
40-
Only if the user is asking about the total number of all vets, answer that there are a lot and ask for some additional criteria.
40+
Only if the user is asking about the total number of all vets, answer that there are a lot and ask for some additional criteria.
4141
For owners, pets or visits - provide the correct data.
4242
""")
4343
.defaultAdvisors(
4444
// Chat memory helps us keep context when using the chatbot for up to 10 previous messages.
4545
new MessageChatMemoryAdvisor(chatMemory, DEFAULT_CHAT_MEMORY_CONVERSATION_ID, 10), // CHAT MEMORY
4646
new SimpleLoggerAdvisor()
4747
)
48+
.defaultFunctions("listOwners", "addOwnerToPetclinic", "addPetToOwner", "listVets")
4849
.build();
4950
}
5051

5152
@PostMapping("/chatclient")
5253
public String exchange(@RequestBody String query) {
5354
try {
54-
//All chatbot messages go through this endpoint
55+
//All chatbot messages go through this endpoint
5556
//and are passed to the LLM
5657
return
5758
this.chatClient

spring-petclinic-genai-service/src/main/resources/application.yml

+13-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,27 @@ spring:
77
active: production
88
config:
99
import: optional:configserver:${CONFIG_SERVER_URL:http://localhost:8888/},optional:classpath:/creds.yaml
10-
#These apply when using spring-ai-azure-openai-spring-boot-starter
1110
ai:
1211
chat:
1312
client:
1413
enabled: true
14+
# These apply when using spring-ai-azure-openai-spring-boot-starter
1515
azure:
1616
openai:
17+
api-key: ${AZURE_OPENAI_KEY}
18+
endpoint: ${AZURE_OPENAI_ENDPOINT}
1719
chat:
1820
options:
19-
functions: listOwners,addOwnerToPetclinic,addPetToOwner,listVets
2021
temperature: 0.7
22+
deployment-name: gpt-4o
23+
# These apply when using spring-ai-openai-spring-boot-starter
24+
openai:
25+
api-key: ${OPENAI_API_KEY:demo}
26+
chat:
27+
options:
28+
temperature: 0.7
29+
model: gpt-4o-mini
30+
2131

2232
logging:
2333
level:
@@ -40,4 +50,4 @@ server:
4050
eureka:
4151
client:
4252
serviceUrl:
43-
defaultZone: http://discovery-server:8761/eureka/
53+
defaultZone: http://discovery-server:8761/eureka/

spring-petclinic-genai-service/src/main/resources/creds-template.yaml

-17
This file was deleted.

0 commit comments

Comments
 (0)