You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiEmbeddingClient.java
Copy file name to clipboardExpand all lines: models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/AzureEmbeddingsOptionsTests.java
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/azure-openai-chat.adoc
+97-98Lines changed: 97 additions & 98 deletions
Original file line number
Diff line number
Diff line change
@@ -4,78 +4,22 @@ Azure's OpenAI offering, powered by ChatGPT, extends beyond traditional OpenAI c
4
4
5
5
Azure offers Java developers the opportunity to leverage AI's full potential by integrating it with an array of Azure services, which includes AI-related resources such as Vector Stores on Azure.
6
6
7
-
== Getting Started
7
+
== Pre-requisites
8
8
9
9
Obtain your Azure OpenAI `endpoint` and `api-key` from the Azure OpenAI Service section on the link:https://portal.azure.com[Azure Portal].
10
10
11
-
=== Configure the Azure OpenAI Chat Client Manually
12
-
13
-
Add the `spring-ai-azure-openai` dependency to your project's Maven `pom.xml` file:
NOTE: The `spring-ai-azure-openai` dependency also provide the access to the `AzureOpenAiChatClient`. For more information about the `AzureOpenAiChatClient` refer to the link:../clients/azure-openai-chat.html[Azure OpenAI Chat] section.
33
-
34
-
Next, create an `AzureOpenAiChatClient` instance and use it to generate text responses:
var chatClient = new AzureOpenAiChatClient(openAIClient).withDefaultOptions(
44
-
AzureOpenAiChatOptions.builder()
45
-
.withModel("gpt-35-turbo")
46
-
.withTemperature(0.4)
47
-
.withMaxTokens(200)
48
-
.build());
49
-
50
-
ChatResponse response = chatClient.call(
51
-
new Prompt("Generate the names of 5 famous pirates."));
52
-
53
-
// Or with streaming responses
54
-
Flux<ChatResponse> response = chatClient.stream(
55
-
new Prompt("Generate the names of 5 famous pirates."));
56
-
57
-
----
58
-
59
-
NOTE: the `gpt-35-turbo` is actually the `Deployment Name` as presented in the Azure AI Portal.
60
-
61
-
The `AzureOpenAiChatOptions` provides the configuration information for the chat requests.
62
-
The `AzureOpenAiChatOptions` offers a builder to create the options.
63
-
64
-
At start time use the `AzureOpenAiChatClient#withDefaultOptions()` to configure the default options used for all char requests.
65
-
Furthermore, at runtime, you can override the default options by passing a `AzureOpenAiChatOptions` instance with your to the `Prompt` request.
11
+
Spring AI defines a configuration property named `spring.ai.azure.openai.api-key` that you should set to the value of the `API Key` obtained from Azure.
12
+
There is also a configuration property named `spring.ai.azure.openai.endpoint` that you should set to the endpoint URL obtained when provisioning your model in Azure.
66
13
67
-
For example to override the default model name for a specific request:
14
+
Exporting environment variables is one way to set these configuration properties:
Spring AI provides Spring Boot auto-configuration for the Azure OpenAI Chat Client.
81
25
To enable it add the following dependency to your project's Maven `pom.xml` file:
@@ -98,20 +42,38 @@ dependencies {
98
42
}
99
43
----
100
44
101
-
Spring AI defines a configuration property named `spring.ai.azure.openai.api-key` that you should set to the value of the `API Key` obtained from Azure.
102
-
There is also a configuration property named `spring.ai.azure.openai.endpoint` that you should set to the endpoint URL obtained when provisioning your model in Azure.
45
+
=== Chat Properties
103
46
104
-
Exporting environment variables is one way to set these configuration properties:
47
+
The prefix `spring.ai.azure.openai` is the property prefix to configure the connection to Azure OpenAI.
| spring.ai.azure.openai.api-key | The Key from Azure AI OpenAI `Keys and Endpoint` section under `Resource Management` | -
54
+
| spring.ai.azure.openai.endpoint | The endpoint from the Azure AI OpenAI `Keys and Endpoint` section under `Resource Management` | -
55
+
|====
111
56
112
-
The `spring.ai.azure.openai.chat.options.*` properties are used to configure the default options used for all chat requests.
57
+
The prefix `spring.ai.azure.openai.chat` is the property prefix that configures the `ChatClient` implementation for Azure OpenAI.
113
58
114
-
==== Sample Code
59
+
[cols="3,5,3"]
60
+
|====
61
+
| Property | Description | Default
62
+
63
+
| spring.ai.azure.openai.chat.options.model | * The model name to provide as part of this completions request. Not applicable to Azure OpenAI, where deployment information should be included in the Azure resource URI that's connected to.
64
+
| gpt-35-turbo
65
+
| spring.ai.azure.openai.chat.options.maxTokens | The maximum number of tokens to generate. | -
66
+
| spring.ai.azure.openai.chat.options.temperature | The sampling temperature to use that controls the apparent creativity of generated completions. Higher values will make output more random while lower values will make results more focused and deterministic. It is not recommended to modify temperature and top_p for the same completions request as the interaction of these two settings is difficult to predict. | 0.7
67
+
| spring.ai.azure.openai.chat.options.topP | An alternative to sampling with temperature called nucleus sampling. This value causes the model to consider the results of tokens with the provided probability mass. | -
68
+
| spring.ai.azure.openai.chat.options.logitBias | A map between GPT token IDs and bias scores that influences the probability of specific tokens appearing in a completions response. Token IDs are computed via external tokenizer tools, while bias scores reside in the range of -100 to 100 with minimum and maximum values corresponding to a full ban or exclusive selection of a token, respectively. The exact behavior of a given bias score varies by model. | -
69
+
| spring.ai.azure.openai.chat.options.user | An identifier for the caller or end user of the operation. This may be used for tracking or rate-limiting purposes. | -
70
+
| spring.ai.azure.openai.chat.options.n | The number of chat completions choices that should be generated for a chat completions response. | -
71
+
| spring.ai.azure.openai.chat.options.stop | A collection of textual sequences that will end completions generation. | -
72
+
| spring.ai.azure.openai.chat.options.presencePenalty | A value that influences the probability of generated tokens appearing based on their existing presence in generated text. Positive values will make tokens less likely to appear when they already exist and increase the model's likelihood to output new topics. | -
73
+
| spring.ai.azure.openai.chat.options.frequencyPenalty | A value that influences the probability of generated tokens appearing based on their cumulative frequency in generated text. Positive values will make tokens less likely to appear as their frequency increases and decrease the likelihood of the model repeating the same statements verbatim. | -
74
+
|====
75
+
76
+
=== Sample Code
115
77
116
78
This will create a `ChatClient` implementation that you can inject into your class.
117
79
Here is an example of a simple `@Controller` class that uses the `ChatClient` implementation.
@@ -143,34 +105,71 @@ public class ChatController {
143
105
}
144
106
----
145
107
146
-
== Azure OpenAI Chat Properties
108
+
== Manual Configuration
147
109
148
-
The prefix `spring.ai.azure.openai` is the property prefix to configure the connection to Azure OpenAI.
110
+
Add the `spring-ai-azure-openai` dependency to your project's Maven `pom.xml` file:
111
+
[source, xml]
112
+
----
113
+
<dependency>
114
+
<groupId>org.springframework.ai</groupId>
115
+
<artifactId>spring-ai-azure-openai</artifactId>
116
+
<version>0.8.0-SNAPSHOT</version>
117
+
</dependency>
118
+
----
149
119
150
-
[cols="3,5,3"]
151
-
|====
152
-
| Property | Description | Default
120
+
or to your Gradle `build.gradle` build file.
153
121
154
-
| spring.ai.azure.openai.api-key | The Key from Azure AI OpenAI `Keys and Endpoint` section under `Resource Management` | -
155
-
| spring.ai.azure.openai.endpoint | The endpoint from the Azure AI OpenAI `Keys and Endpoint` section under `Resource Management` | -
NOTE: The `spring-ai-azure-openai` dependency also provide the access to the `AzureOpenAiChatClient`. For more information about the `AzureOpenAiChatClient` refer to the link:../clients/azure-openai-chat.html[Azure OpenAI Chat] section.
158
130
159
-
The prefix `spring.ai.azure.openai.chat` is the property prefix that configures the `ChatClient` implementation for Azure OpenAI.
131
+
Next, create an `AzureOpenAiChatClient` instance and use it to generate text responses:
| spring.ai.azure.openai.chat.options.model | * The model name to provide as part of this completions request. Not applicable to Azure OpenAI, where deployment information should be included in the Azure resource URI that's connected to.
166
-
| gpt-35-turbo
167
-
| spring.ai.azure.openai.chat.options.maxTokens | The maximum number of tokens to generate. | -
168
-
| spring.ai.azure.openai.chat.options.temperature | The sampling temperature to use that controls the apparent creativity of generated completions. Higher values will make output more random while lower values will make results more focused and deterministic. It is not recommended to modify temperature and top_p for the same completions request as the interaction of these two settings is difficult to predict. | 0.7
169
-
| spring.ai.azure.openai.chat.options.topP | An alternative to sampling with temperature called nucleus sampling. This value causes the model to consider the results of tokens with the provided probability mass. | -
170
-
| spring.ai.azure.openai.chat.options.logitBias | A map between GPT token IDs and bias scores that influences the probability of specific tokens appearing in a completions response. Token IDs are computed via external tokenizer tools, while bias scores reside in the range of -100 to 100 with minimum and maximum values corresponding to a full ban or exclusive selection of a token, respectively. The exact behavior of a given bias score varies by model. | -
171
-
| spring.ai.azure.openai.chat.options.user | An identifier for the caller or end user of the operation. This may be used for tracking or rate-limiting purposes. | -
172
-
| spring.ai.azure.openai.chat.options.n | The number of chat completions choices that should be generated for a chat completions response. | -
173
-
| spring.ai.azure.openai.chat.options.stop | A collection of textual sequences that will end completions generation. | -
174
-
| spring.ai.azure.openai.chat.options.presencePenalty | A value that influences the probability of generated tokens appearing based on their existing presence in generated text. Positive values will make tokens less likely to appear when they already exist and increase the model's likelihood to output new topics. | -
175
-
| spring.ai.azure.openai.chat.options.frequencyPenalty | A value that influences the probability of generated tokens appearing based on their cumulative frequency in generated text. Positive values will make tokens less likely to appear as their frequency increases and decrease the likelihood of the model repeating the same statements verbatim. | -
176
-
|====
140
+
var chatClient = new AzureOpenAiChatClient(openAIClient).withDefaultOptions(
141
+
AzureOpenAiChatOptions.builder()
142
+
.withModel("gpt-35-turbo")
143
+
.withTemperature(0.4)
144
+
.withMaxTokens(200)
145
+
.build());
146
+
147
+
ChatResponse response = chatClient.call(
148
+
new Prompt("Generate the names of 5 famous pirates."));
149
+
150
+
// Or with streaming responses
151
+
Flux<ChatResponse> response = chatClient.stream(
152
+
new Prompt("Generate the names of 5 famous pirates."));
153
+
154
+
----
155
+
156
+
NOTE: the `gpt-35-turbo` is actually the `Deployment Name` as presented in the Azure AI Portal.
157
+
158
+
=== Chat Options
159
+
160
+
The `AzureOpenAiChatOptions` provides the configuration information for the chat requests.
161
+
The `AzureOpenAiChatOptions` offers a builder to create the options.
162
+
163
+
At start time use the `AzureOpenAiChatClient` constructor to set the default options used for all char requests.
164
+
At runtime, you can override the default options by passing a `AzureOpenAiChatOptions` instance with your to the `Prompt` request.
165
+
166
+
For example to override the default model name for a specific request:
0 commit comments