Skip to content

Commit 0b7318f

Browse files
committed
Add GPT-5 model support and temperature documentation
GPT-5 models (gpt-5, gpt-5-2025-08-07) only support temperature=1.0 and will error with other values. This change adds a parameterized test to validate both models work correctly and updates documentation to warn users about this temperature requirement. - Add chatCompletionEntityWithNewModels test in OpenAiApiIT - Set temperature to 1.0 for GPT-5 compatibility - Add NOTE section in openai-chat.adoc about temperature restriction
1 parent c893629 commit 0b7318f

File tree

2 files changed

+21
-1
lines changed
  • models/spring-ai-openai/src/test/java/org/springframework/ai/openai/api
  • spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat

2 files changed

+21
-1
lines changed

models/spring-ai-openai/src/test/java/org/springframework/ai/openai/api/OpenAiApiIT.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.junit.jupiter.api.Disabled;
2424
import org.junit.jupiter.api.Test;
2525
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
26+
import org.junit.jupiter.params.ParameterizedTest;
27+
import org.junit.jupiter.params.provider.ValueSource;
2628
import reactor.core.publisher.Flux;
2729

2830
import org.springframework.ai.openai.api.OpenAiApi.ChatCompletion;
@@ -156,4 +158,18 @@ void streamOutputAudio() {
156158
.hasMessageContaining("400 Bad Request from POST https://api.openai.com/v1/chat/completions");
157159
}
158160

161+
@ParameterizedTest(name = "{0} : {displayName}")
162+
@ValueSource(strings = { "gpt-5", "gpt-5-2025-08-07" })
163+
void chatCompletionEntityWithNewModels(String modelName) {
164+
ChatCompletionMessage chatCompletionMessage = new ChatCompletionMessage("Hello world", Role.USER);
165+
ResponseEntity<ChatCompletion> response = this.openAiApi
166+
.chatCompletionEntity(new ChatCompletionRequest(List.of(chatCompletionMessage), modelName, 1.0, false));
167+
168+
assertThat(response).isNotNull();
169+
assertThat(response.getBody()).isNotNull();
170+
assertThat(response.getBody().choices()).isNotEmpty();
171+
assertThat(response.getBody().choices().get(0).message().content()).isNotEmpty();
172+
assertThat(response.getBody().model()).containsIgnoringCase(modelName);
173+
}
174+
159175
}

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ The `JSON_SCHEMA` type enables link:https://platform.openai.com/docs/guides/stru
179179
| spring.ai.openai.chat.options.proxy-tool-calls | If true, the Spring AI will not handle the function calls internally, but will proxy them to the client. Then is the client's responsibility to handle the function calls, dispatch them to the appropriate function, and return the results. If false (the default), the Spring AI will handle the function calls internally. Applicable only for chat models with function calling support | false
180180
|====
181181

182+
[NOTE]
183+
====
184+
When using GPT-5 models (`gpt-5`, `gpt-5-2025-08-07`), the temperature parameter must be set to `1.0` (the default value). These models do not support custom temperature values and will return an error if any other temperature value is specified.
185+
====
186+
182187
NOTE: You can override the common `spring.ai.openai.base-url` and `spring.ai.openai.api-key` for the `ChatModel` and `EmbeddingModel` implementations.
183188
The `spring.ai.openai.chat.base-url` and `spring.ai.openai.chat.api-key` properties, if set, take precedence over the common properties.
184189
This is useful if you want to use different OpenAI accounts for different models and different model endpoints.
@@ -644,4 +649,3 @@ This is useful when you need to:
644649
* Retrieve the API key from a secure key store
645650
* Rotate API keys dynamically
646651
* Implement custom API key selection logic
647-

0 commit comments

Comments
 (0)