|
35 | 35 |
|
36 | 36 | import org.springframework.ai.azure.openai.metadata.AzureOpenAiChatResponseMetadata;
|
37 | 37 | import org.springframework.ai.chat.ChatClient;
|
| 38 | +import org.springframework.ai.chat.ChatOptions; |
38 | 39 | import org.springframework.ai.chat.ChatResponse;
|
39 | 40 | import org.springframework.ai.chat.Generation;
|
40 | 41 | import org.springframework.ai.chat.StreamingChatClient;
|
|
43 | 44 | import org.springframework.ai.chat.metadata.PromptMetadata;
|
44 | 45 | import org.springframework.ai.chat.metadata.PromptMetadata.PromptFilterMetadata;
|
45 | 46 | import org.springframework.ai.chat.prompt.Prompt;
|
| 47 | +import org.springframework.ai.model.ModelOptionsUtils; |
46 | 48 | import org.springframework.util.Assert;
|
47 | 49 |
|
48 | 50 | /**
|
@@ -128,8 +130,7 @@ public Flux<ChatResponse> stream(Prompt prompt) {
|
128 | 130 |
|
129 | 131 | return Flux.fromStream(chatCompletionsStream.stream()
|
130 | 132 | // Note: the first chat completions can be ignored when using Azure OpenAI
|
131 |
| - // service which is a |
132 |
| - // known service bug. |
| 133 | + // service which is a known service bug. |
133 | 134 | .skip(1)
|
134 | 135 | .map(ChatCompletions::getChoices)
|
135 | 136 | .flatMap(List::stream)
|
@@ -161,12 +162,14 @@ ChatCompletionsOptions toAzureChatCompletionsOptions(Prompt prompt) {
|
161 | 162 | }
|
162 | 163 |
|
163 | 164 | if (prompt.getOptions() != null) {
|
164 |
| - if (prompt.getOptions() instanceof AzureOpenAiChatOptions runtimeOptions) { |
| 165 | + if (prompt.getOptions() instanceof ChatOptions runtimeOptions) { |
| 166 | + AzureOpenAiChatOptions updatedRuntimeOptions = ModelOptionsUtils.copyToTarget(runtimeOptions, |
| 167 | + ChatOptions.class, AzureOpenAiChatOptions.class); |
165 | 168 | // JSON merge doesn't due to Azure OpenAI service bug:
|
166 | 169 | // https://github.com/Azure/azure-sdk-for-java/issues/38183
|
167 | 170 | // options = ModelOptionsUtils.merge(runtimeOptions, options,
|
168 | 171 | // ChatCompletionsOptions.class);
|
169 |
| - options = merge(runtimeOptions, options); |
| 172 | + options = merge(updatedRuntimeOptions, options); |
170 | 173 | }
|
171 | 174 | else {
|
172 | 175 | throw new IllegalArgumentException("Prompt options are not of type ChatCompletionsOptions:"
|
|
0 commit comments