-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add support for OpenAI Java SDK (official Java library from OpenAI) #4688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
With today's commit, we now have:
And some basic shared configuration, that will be improved next, so we're ready for the more complex stuff (ChatModel). |
|
The setup logic for the OpenAI SDK should be very similar to this class from LangChain4, because it's basically doing the same thingj: I'm very careful before taking code from another project, but I believe this is fine: I'm the author of that other class, so I have the copyright on this code. Also, it's simple logic to connect to Azure/GitHub Models/OpenAI, nothing that is very specific or critical. However, if this causes problems:
Happy to discuss this if needed. |
|
Argh, I updated my fork and now my commit history is all wrong!!!! I'll do my best to fix this. |
fddc244 to
149aa9c
Compare
|
I had to force push my fork, sorry if anyone had this pulled on their side! I'll check if everything is good, otherwise I have a backup on my laptop. |
9b39b0c to
e916e07
Compare
|
Thanks @tzolov for our discussion -> I've just added a few more tests, I've put this "ready for review" and I'll be happy to discuss this with you |
|
I've fixed some of the Checkstyle issues but there's a ton of them, so this is far from finished. Does it really make sense to follow of all of those rules? |
tzolov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdubois thanks for the great work! The preliminary review looks very good. Almost ready :)
Here are my observations and suggestions so far:
Naming Convention
- Please replace the
officialsuffix withsdkthroughout (artifacts, packages, and class names) - Examples:
spring-ai-openai-sdk,.openaisdk.,OpenAiSdkChatModel
Test Failures
OpenAiOfficialEmbeddingIT#defaultEmbedding- receives "text-embedding-ada-002-v2" instead of expected "text-embedding-ada-002"OpenAiOfficialImageModelObservationIT- passes individually but fails in full test suite with:InvalidObservation: Metrics backends may require that all observations with the same name have the same set of low cardinality keys...(observation mismatch between image and other operations)- Haven't tested the Azure OpenAI support yet (don't have an azure account for testing yet)
Additional Items
- Checkstyle - Issues need resolution
- Missing Documentation - Please add OpenAI SDK docs similar to https://docs.spring.io/spring-ai/reference/api/chat/openai-chat.html
- I've attached, an initial version (
openai-sdk-chat.adoc) - add it to/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/and link innav.adoc - Build with:
./mvnw -pl spring-ai-docs antora
- I've attached, an initial version (
- Missing Auto-configurations - I'd recommend adding these in a separate PR
- Missing Audio (Speech/Transcription) and Moderation API integration - can be added in follow-up PRs
openai-sdk-chat.RENAME_EXT_TO_adoc.md
401dce6 to
bc8d3e3
Compare
|
@jdubois, |
|
Also fixed the audio output support: 9427442 |
|
Thanks a lot @tzolov ! |
|
|
@tzolov concerning the remaining issues in your review:
|
|
@jdubois |
|
@jdubois I've updated the openai-sdk chat docs: https://github.com/jdubois/spring-ai/blob/openaiofficial/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/openai-sdk-chat.adoc. Usually the README contains only a reference to the official doc page. If you want you can generate the docs with In the meantime I will try to add doc pages for the opneai-sdk embedding and image models. |
|
I've pushed the openai-skd-embedding.adoc and openai-sdk-image.adoc as well. |
Fix spring-projects#3368 Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- Add support for ImageModel - Refactor the existing code now that we have support for 2 models Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- Added support for authentication with OpenAI, Azure OpenAI and GitHub models. - Added support for complex OpenAI client configuration - Refactored the existing code to use those new methods Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
Create the OpenAiOfficialChatOptions class to prepare for the implementation of the Chat Model Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
Create the OpenAiOfficialChatModel class: - This is a first implementation that is not of good quality yet - Tests do not pass yet Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- Improve authentication, mostly with Azure OpenAI Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- First tests passing for ChatModel Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- More tests passing for ChatModel Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- More tests passing for ChatModel Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- More tests passing for ChatModel Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- Change default temperature from 0.7 to 1.0 in OpenAiSdkChatProperties to align with OpenAI defaults - Add support for audio output modalities with new AudioParameters type - Introduce Voice enum (ALLOY, ASH, BALLAD, CORAL, ECHO, FABLE, ONYX, NOVA, SAGE, SHIMMER) - Introduce AudioResponseFormat enum (MP3, FLAC, OPUS, PCM16, WAV, AAC) - Replace ChatCompletionAudioParam with custom AudioParameters record - Add outputModalities field to support text and audio output combinations - Enhance buildGeneration method to handle audio content in responses - Extract audio data from base64 encoded response - Create Media objects with proper MIME types - Include audio transcript and metadata (audioId, audioExpiresAt) - Improve chunkToChatCompletion to handle missing choices in streaming responses - Add integration tests for audio output (blocking and streaming) - Update documentation for output-audio and stream-options configuration - Add streamUsage helper method to StreamOptions builder Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
- Fix test with the default Embedding model Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- Added authentication support in the *Options classes - Added documentation for authentication in the README.md file - Added Chat Models in the configuration script Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- Reactored Azure OpenAI to Microsoft Foundry (new name announced last week) Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- Change test case as the default URL for GitHub Models changed Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- Update the custom HTTP Headers Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- Fix the custom HTTP Headers Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
- Improve authentication Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
- Fix OpenAiOfficialImageModelObservationIT Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
- Support GitHub Models for specific orgs Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
Signed-off-by: Julien Dubois <julien.dubois@gmail.com>
cadcfbd to
e88c09f
Compare
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
tzolov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Introduces support for the official OpenAI Java SDK (openai-java) as an alternative to the existing Spring AI OpenAI implementation. New modules: - models/spring-ai-openai-sdk: Core SDK implementation - auto-configurations/models/spring-ai-autoconfigure-model-openai-sdk: Auto-configuration - spring-ai-spring-boot-starters/spring-ai-starter-model-openai-sdk: Starter module Features: - OpenAiSdkChatModel/OpenAiSdkChatOptions with streaming, tool calling, and multimodal support - OpenAiSdkEmbeddingModel/OpenAiSdkEmbeddingOptions with configurable dimensions - OpenAiSdkImageModel/OpenAiSdkImageOptions with DALL-E integration - Native support for OpenAI, Microsoft Foundry (Azure), and GitHub Models - Auto-detection of service provider based on base URL - Passwordless authentication for Microsoft Foundry (via azure-identity) - Comprehensive test suite with integration tests - Complete documentation for Chat, Embedding, and Image models - Update AiProvider enum to include OPENAI_SDK - Update SpringAIModels constants - Update documentation navigation and model comparison table Fix #3368 Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com> Signed-off-by: Julien Dubois <julien.dubois@gmail.com> Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
|
Great stuff. Thanks @jdubois |
|
Rebased, squashed and merged at 15df47d |
|
Awesome, thanks for all your help @tzolov !!! |
Introduces support for the official OpenAI Java SDK (openai-java) as an alternative to the existing Spring AI OpenAI implementation. New modules: - models/spring-ai-openai-sdk: Core SDK implementation - auto-configurations/models/spring-ai-autoconfigure-model-openai-sdk: Auto-configuration - spring-ai-spring-boot-starters/spring-ai-starter-model-openai-sdk: Starter module Features: - OpenAiSdkChatModel/OpenAiSdkChatOptions with streaming, tool calling, and multimodal support - OpenAiSdkEmbeddingModel/OpenAiSdkEmbeddingOptions with configurable dimensions - OpenAiSdkImageModel/OpenAiSdkImageOptions with DALL-E integration - Native support for OpenAI, Microsoft Foundry (Azure), and GitHub Models - Auto-detection of service provider based on base URL - Passwordless authentication for Microsoft Foundry (via azure-identity) - Comprehensive test suite with integration tests - Complete documentation for Chat, Embedding, and Image models - Update AiProvider enum to include OPENAI_SDK - Update SpringAIModels constants - Update documentation navigation and model comparison table Fix spring-projects#3368 Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com> Signed-off-by: Julien Dubois <julien.dubois@gmail.com> Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This follows the discussion on ticket #3368
This is a draft PR as the work is pretty big, I'll start with the simpler implementations (Embeddings) and finish with the more complex one (Chat).