diff --git a/README.md b/README.md index c7d3e4a4415..c1d5310f9b7 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ You can find more details in the [Reference Documentation](https://docs.spring.i - [Audio Transcription](https://docs.spring.io/spring-ai/reference/api/audio/transcriptions.html) - [Text to Speech](https://docs.spring.io/spring-ai/reference/api/audio/speech.html) - [Moderation](https://docs.spring.io/spring-ai/reference/api/index.html#api/moderation) + - **Latest Models**: GPT-5, and other cutting-edge models for advanced AI applications. * 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. * [Structured Outputs](https://docs.spring.io/spring-ai/reference/api/structured-output-converter.html) - Mapping of AI Model output to POJOs. * 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*. diff --git a/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java b/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java index 9f2e8a9ebdb..1c4a06b0b89 100644 --- a/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java +++ b/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java @@ -468,6 +468,33 @@ public enum ChatModel implements ChatModelDescription { */ GPT_4_1("gpt-4.1"), + /** + * GPT-5 is the next-generation flagship model with enhanced capabilities + * for complex reasoning and problem-solving tasks. + *

+ * Note: GPT-5 models require temperature=1.0 (default value). Custom temperature + * values are not supported and will cause errors. + *

+ * Model ID: gpt-5 + *

+ * See: gpt-5 + */ + GPT_5("gpt-5"), + + /** + * GPT-5 (2025-08-07) is a specific snapshot of the GPT-5 model from + * August 7, 2025, providing enhanced capabilities for complex reasoning and + * problem-solving tasks. + *

+ * Note: GPT-5 models require temperature=1.0 (default value). Custom temperature + * values are not supported and will cause errors. + *

+ * Model ID: gpt-5-2025-08-07 + *

+ * See: gpt-5 + */ + GPT_5_2025_08_07("gpt-5-2025-08-07"), + /** * GPT-4o (“o” for “omni”) is the versatile, high-intelligence flagship * model. It accepts both text and image inputs, and produces text outputs diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/api/OpenAiApiIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/api/OpenAiApiIT.java index e45b0537eed..dcd12d890eb 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/api/OpenAiApiIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/api/OpenAiApiIT.java @@ -23,6 +23,8 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import reactor.core.publisher.Flux; import org.springframework.ai.openai.api.OpenAiApi.ChatCompletion; @@ -156,4 +158,18 @@ void streamOutputAudio() { .hasMessageContaining("400 Bad Request from POST https://api.openai.com/v1/chat/completions"); } + @ParameterizedTest(name = "{0} : {displayName}") + @EnumSource(names = {"GPT_5", "GPT_5_2025_08_07"}) + void chatCompletionEntityWithNewModels(OpenAiApi.ChatModel modelName) { + ChatCompletionMessage chatCompletionMessage = new ChatCompletionMessage("Hello world", Role.USER); + ResponseEntity response = this.openAiApi + .chatCompletionEntity(new ChatCompletionRequest(List.of(chatCompletionMessage), modelName.getValue(), 1.0, false)); + + assertThat(response).isNotNull(); + assertThat(response.getBody()).isNotNull(); + assertThat(response.getBody().choices()).isNotEmpty(); + assertThat(response.getBody().choices().get(0).message().content()).isNotEmpty(); + assertThat(response.getBody().model()).containsIgnoringCase(modelName.getValue()); + } + } diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc index 424fe8966bd..d13e4dff92a 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-chat.adoc @@ -179,6 +179,11 @@ The `JSON_SCHEMA` type enables link:https://platform.openai.com/docs/guides/stru | 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 |==== +[NOTE] +==== +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. +==== + NOTE: You can override the common `spring.ai.openai.base-url` and `spring.ai.openai.api-key` for the `ChatModel` and `EmbeddingModel` implementations. The `spring.ai.openai.chat.base-url` and `spring.ai.openai.chat.api-key` properties, if set, take precedence over the common properties. 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: * Retrieve the API key from a secure key store * Rotate API keys dynamically * Implement custom API key selection logic -