Skip to content

Commit 1a3ed95

Browse files
markpollacksobychacko
authored andcommitted
feat: add GPT-5 model enum support and update documentation
- Add GPT_5 and GPT_5_2025_08_07 enum constants to ChatModel in OpenAiApi.java - Update OpenAiApiIT test to use enum constants instead of hardcoded strings - Enhance README.md to highlight support for latest models including GPT-5 - Include JavaDoc documentation with temperature requirement notes (1.0) 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 Fixes GPT-5 model integration with proper type-safe enum constants
1 parent b51daa9 commit 1a3ed95

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ You can find more details in the [Reference Documentation](https://docs.spring.i
2323
- [Audio Transcription](https://docs.spring.io/spring-ai/reference/api/audio/transcriptions.html)
2424
- [Text to Speech](https://docs.spring.io/spring-ai/reference/api/audio/speech.html)
2525
- [Moderation](https://docs.spring.io/spring-ai/reference/api/index.html#api/moderation)
26+
- **Latest Models**: GPT-5, and other cutting-edge models for advanced AI applications.
2627
* Portable API support across AI providers for both synchronous and streaming options. Access to [model-specific features](https://docs.spring.io/spring-ai/reference/api/chatmodel.html#_chat_options) is also available.
2728
* [Structured Outputs](https://docs.spring.io/spring-ai/reference/api/structured-output-converter.html) - Mapping of AI Model output to POJOs.
2829
* Support for all major [Vector Database providers](https://docs.spring.io/spring-ai/reference/api/vectordbs.html) such as *Apache Cassandra, Azure Vector Search, Chroma, Elasticsearch, Milvus, MongoDB Atlas, MariaDB, Neo4j, Oracle, PostgreSQL/PGVector, PineCone, Qdrant, Redis, and Weaviate*.

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,33 @@ public enum ChatModel implements ChatModelDescription {
468468
*/
469469
GPT_4_1("gpt-4.1"),
470470

471+
/**
472+
* <b>GPT-5</b> is the next-generation flagship model with enhanced capabilities
473+
* for complex reasoning and problem-solving tasks.
474+
* <p>
475+
* Note: GPT-5 models require temperature=1.0 (default value). Custom temperature
476+
* values are not supported and will cause errors.
477+
* <p>
478+
* Model ID: gpt-5
479+
* <p>
480+
* See: <a href="https://platform.openai.com/docs/models/gpt-5">gpt-5</a>
481+
*/
482+
GPT_5("gpt-5"),
483+
484+
/**
485+
* <b>GPT-5 (2025-08-07)</b> is a specific snapshot of the GPT-5 model from August
486+
* 7, 2025, providing enhanced capabilities for complex reasoning and
487+
* problem-solving tasks.
488+
* <p>
489+
* Note: GPT-5 models require temperature=1.0 (default value). Custom temperature
490+
* values are not supported and will cause errors.
491+
* <p>
492+
* Model ID: gpt-5-2025-08-07
493+
* <p>
494+
* See: <a href="https://platform.openai.com/docs/models/gpt-5">gpt-5</a>
495+
*/
496+
GPT_5_2025_08_07("gpt-5-2025-08-07"),
497+
471498
/**
472499
* <b>GPT-4o</b> (“o” for “omni”) is the versatile, high-intelligence flagship
473500
* model. It accepts both text and image inputs, and produces text outputs

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.EnumSource;
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+
@EnumSource(names = { "GPT_5", "GPT_5_2025_08_07" })
163+
void chatCompletionEntityWithNewModels(OpenAiApi.ChatModel modelName) {
164+
ChatCompletionMessage chatCompletionMessage = new ChatCompletionMessage("Hello world", Role.USER);
165+
ResponseEntity<ChatCompletion> response = this.openAiApi.chatCompletionEntity(
166+
new ChatCompletionRequest(List.of(chatCompletionMessage), modelName.getValue(), 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.getValue());
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)