Skip to content

Commit dfbea8c

Browse files
tzolovmarkpollack
authored andcommitted
Add Azure OpenAI Chat and Embedding Options
- Add AzureOpenAiChatOptions - Add default options field to AzureOpenAiChatClient. - Impl runtime (e.g. prompt) and default options on call. - Add options field to the AzureOpenAiChatProperties. - Add AzureOpenAiEmbeddingOptions - Add default options field to AzureOpenAiEmbeddingClient. - Impmlement runtime and default option merging on embedding request. - Add options field to AzureOpenAiEmbeddingProperties. - Add Unit and ITs. - Split the azure-openai.adoc into ./clients/azure-openai-chat.adoc and ./embeddings/azure-openai-embeddings.adoc. - Provide detailed explanation how to use the chat and embedding clients manually or via the auto-configuration. - Add protable ChatOptions support
1 parent ca7e3e4 commit dfbea8c

File tree

19 files changed

+1147
-288
lines changed

19 files changed

+1147
-288
lines changed
Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,9 @@
1-
# 1. Azure OpenAI
1+
# Azure OpenAI
22

33
Provides Azure OpenAI Chat and Embedding clients.
44
Leverages the native [OpenAIClient](https://learn.microsoft.com/en-us/java/api/overview/azure/ai-openai-readme?view=azure-java-preview#streaming-chat-completions) to interact with the [Amazon AI Studio models and deployment](https://oai.azure.com/).
55

6-
## 1.1 Prerequisites
6+
Find additional information:
77

8-
1. Azure Subscription: You will need an [Azure subscription](https://azure.microsoft.com/en-us/free/) to use any Azure service.
9-
2. Azure AI, Azure OpenAI Service: Create [Azure OpenAI](https://portal.azure.com/#create/Microsoft.CognitiveServicesOpenAI).
10-
Once the service is created, obtain the endpoint and apiKey from the `Keys and Endpoint` section under `Resource Management`.
11-
3. Use the [Azure Ai Studio](https://oai.azure.com/portal) to deploy the models you are going to use.
12-
13-
## 1.2 AzureOpenAiChatClient
14-
15-
[AzureOpenAiChatClient](./src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatClient.java) implements the Spring-Ai `ChatClient` and `StreamingChatClient` on top of the `OpenAIClient`.
16-
17-
[AzureOpenAiEmbeddingClient](./src/main/java/org/springframework/ai/azure/openai/AzureOpenAiEmbeddingClient.java) implements the Spring-Ai `EmbeddingClient` on top of the `OpenAIClient`.
18-
19-
20-
You can configure the AzureOpenAiChatClient and AzureOpenAiEmbeddingClientlike this:
21-
22-
```java
23-
@Bean
24-
public OpenAIClient openAIClient() {
25-
return new OpenAIClientBuilder()
26-
.credential(new AzureKeyCredential({YOUR_AZURE_OPENAI_API_KEY}))
27-
.endpoint({YOUR_AZURE_OPENAI_ENDPOINT})
28-
.buildClient();
29-
}
30-
31-
@Bean
32-
public AzureOpenAiChatClient cohereChatClient(OpenAIClient openAIClient) {
33-
return new AzureOpenAiChatClient(openAIClient)
34-
.withModel("gpt-35-turbo")
35-
.withMaxTokens(200)
36-
.withTemperature(0.8);
37-
}
38-
39-
@Bean
40-
public AzureOpenAiEmbeddingClient cohereEmbeddingClient(OpenAIClient openAIClient) {
41-
return new AzureOpenAiEmbeddingClient(openAIClient, "text-embedding-ada-002-v1");
42-
}
43-
```
44-
45-
## 1.3 Azure OpenAi Auto-Configuration and Spring Boot Starter
46-
47-
You can leverage the `spring-ai-azure-openai-spring-boot-starter` Boot starter.
48-
For this add the following dependency:
49-
50-
```xml
51-
<dependency>
52-
<artifactId>spring-ai-azure-openai-spring-boot-starter</artifactId>
53-
<groupId>org.springframework.ai</groupId>
54-
<version>0.8.0-SNAPSHOT</version>
55-
</dependency>
56-
```
57-
58-
Use the `AzureOpenAiConnectionProperties` to configure the Azure OpenAI access:
59-
60-
| Property | Description | Default |
61-
| ------------- | ------------- | ------------- |
62-
| spring.ai.azure.openai.apiKey | Azure AI Open AI credentials api key. | From the Azure AI OpenAI `Keys and Endpoint` section under `Resource Management` |
63-
| spring.ai.azure.openai.endpoint | Azure AI Open AI endpoint. | From the Azure AI OpenAI `Keys and Endpoint` section under `Resource Management` |
64-
65-
Use the `AzureOpenAiChatProperties` to configure the Chat client:
66-
67-
| Property | Description | Default |
68-
| ------------- | ------------- | ------------- |
69-
| spring.ai.azure.openai.chat.model | The model id to use. | gpt-35-turbo |
70-
| spring.ai.azure.openai.chat.temperature | Controls the randomness of the output. Values can range over [0.0,1.0] | 0.7 |
71-
| spring.ai.azure.openai.chat.topP | An alternative to sampling with temperature called nucleus sampling. | |
72-
| spring.ai.azure.openai.chat.maxTokens | The maximum number of tokens to generate. | |
73-
74-
Use the `AzureOpenAiEmbeddingProperties` to configure the Embedding client:
75-
76-
| Property | Description | Default |
77-
| ------------- | ------------- | ------------- |
78-
| spring.ai.azure.openai.embedding.model | The model id to use for embedding | text-embedding-ada-002 |
8+
- [Azure OpenAi Chat Client](https://docs.spring.io/spring-ai/reference/api/clients/azure-openai-chat.html)
9+
- [Azure OpenAi Embeddings Client](https://docs.spring.io/spring-ai/reference/api/embeddings/azure-openai-embeddings.html)

0 commit comments

Comments
 (0)