Commit Graph

638 Commits

Author SHA1 Message Date
Christian Tzolov
710bb05f19 feat(vertex-ai): Refactor Gemini for new tool calling API
- Migrate from function calling to tool calling API
- Add support for Gemini 2.0 models (flash, flash-lite)
- Implement JSON schema to OpenAPI schema conversion
- Add builder pattern for improved configuration
- Deprecate legacy function calling constructors and methods
- Update default model to GEMINI_2_0_FLASH
- Add comprehensive test coverage for tool calling
- Upgrade victools dependency to 4.37.0
- Update the Vertex Tool calling docs

Part of the #2207 epic

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-12 22:48:24 -05:00
Christian Tzolov
a8e305d28a refactor(bedrock): Migrate from function calling to tool calling
- Replace function calling with tool calling in BedrockProxyChatModel
- Deprecate function calling related code and APIs
- Add new tool calling manager and options
- Update builder pattern to remove "with" prefix from methods
- Update tests and documentation for tool calling

Part of the #2207 epic

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-12 18:29:48 +00:00
Ilayaperumal Gopinathan
7e4b90dc48 AzureOpenAI - Adopt ToolCallingManager API
- Use the new ToolCallingManager API for AzureOpenAI chat model
 - Add Builder to construct AzureOpenAI chat model instance
   - Deprecate existing constructors
 - Update documentation about the change

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-02-12 12:17:25 +00:00
Thomas Vitale
6c3a2c39fc Mistral AI - Adopt ToolCallingManager API
- Update MistralAiChatModel to use the new ToolCallingManager API, while ensuring full API backward compatibility.
- Introduce Builder to instantiate a new MistralAiChatModel since the number of overloaded constructors is growing too big.
- Update documentation about tool calling and Mistral AI support for that.
- Add extra validation to ensure the uniqueness of tool names when aggregated from different sources.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-02-12 11:56:03 +01:00
pbakker
b936a9c429 Possible fix for issue #2218, allowing to disable setting the Authorization header.
Signed-off-by: pbakker <pbakker@netflix.com>
2025-02-12 10:34:06 +00:00
Ricken Bazolo
e92616b10e fix(mistral) Added index of tool call in the list of tool calls
Additiona fixes: API key validation and tool calling backward compatibility

- Fix API key validation in OpenAiApi builder
- Standardize API key validation using Assert.notNull
- Add backward compatibility support for FunctionCallback in tool calling
- Update integration tests to use LegacyToolCallingManager

Co-authored-by:Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Ricken Bazolo <ricken.bazolo@gmail.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-11 14:10:51 +01:00
Thomas Vitale
52198ed9d7 OpenAI - Adopt ToolCallingManager API
- Update OpenAiChatModel to use the new ToolCallingManager API, while ensuring full API backward compatibility.
- Introduce Builder to instantiate a new OpenAiChatModel since the number of overloaded constructors is growing too big.
- Update documentation about tool calling and OpenAI support for that.
- Add extra validation to ensure the uniqueness of tool names when aggregated from different sources.
- Ensure consistent merging of options, following Spring Boot strategy.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-02-11 10:54:43 +01:00
Ilayaperumal Gopinathan
4874374507 Mistral chat model enum cleanup
- Remove deprecated models
 - Add suggestions from @apappascs
2025-02-08 08:16:01 +00:00
Ricken Bazolo
99e90e2d91 Mistral API versions added
Signed-off-by: Ricken Bazolo <ricken.bazolo@gmail.com>
2025-02-08 07:52:55 +00:00
Ilayaperumal Gopinathan
3ae9503c3e Fix BedrockConverseChatClientIT
- Use FunctionCallingOptions for the chat options as the BedrockConverseChatModel isn't updated with the latest changes on ToolCallingOptions
2025-02-06 18:44:32 +00:00
Thomas Vitale
01632c5d20 Add merge for missing Ollama options
When fields in OllamaOptions are marked as ignored in Jackson, they require explicit merge of runtime and default options.
Added tests to validate the different merge combinations for all tool-related options.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-02-06 10:13:40 +01:00
Thomas Vitale
ecae493704 Fix handling of nullable fields in OllamaChatModel deprecated constructor (#2174)
Fix gh-2172

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-02-05 23:29:01 -05:00
Ilayaperumal Gopinathan
1c6132caf4 Update to Spring Boot 3.4.2 for dependency management (#2176)
- Spring AI's dependencies management to derive from Spring Boot 3.4.2
    - Remove explicit versioning of dependencies
  - Update upgrade notes for Spring Boot 3.4.2
  - Fix ElasticSearch client changes with the latest dependency derived from Spring Boot 3.4.2
2025-02-05 23:25:18 -05:00
Mark Pollack
fc2690cdf8 Add flexible API key management for OpenAI
Introduces a new API key interface that allows users to customize how
API keys are provided and managed in their Spring AI applications. This
change improves security and flexibility by:

- Adding core ApiKey interface and SimpleApiKey implementation
- Adding builder pattern for OpenAiApi creation
- Deprecating public constructors in favor of builder API (since 1.0.0.M6)
- Added docs

The new system enables users to implement their own key management
strategies while maintaining backward compatibility with property-based
configuration.
2025-02-05 14:57:41 -05:00
Ricken Bazolo
45421b1c93 improved ability to use openAiApi to support DeepSeek
Signed-off-by: Ricken Bazolo <ricken.bazolo@gmail.com>
2025-02-05 16:13:50 +00:00
Alexandros Pappas
35101e75ae feat: Add reasoningEffort parameter to OpenAI API and Chat Options
This commit introduces the `reasoningEffort` parameter to the OpenAI API integration, allowing control over the reasoning effort used by models like `o1-mini`.

Changes:
- Adds `reasoningEffort` field to `OpenAiApi.ChatCompletionRequest`.
- Adds `reasoningEffort` field and builder method to `OpenAiChatOptions`.

Signed-off-by: Alexandros Pappas <apappascs@gmail.com>

Signed-off-by: Alexandros Pappas <apappascs@gmail.com>
2025-02-05 13:01:29 +00:00
Alexandros Pappas
74178b9f0e feat: Update OpenAI Chat Models to Latest Versions and Improve Documentation
This commit comprehensively updates the OpenAiApi `ChatModel` enum to include all the latest OpenAI chat completion models and enhances the documentation.

Signed-off-by: Alexandros Pappas <alexandros.pappas@yiluhub.com>
2025-02-05 10:40:09 +00:00
Thomas Vitale
560baaae5a Advancing Tool Support - Part 5
* Introduced new ToolParam annotation for defining a description for tool parameters and marking them as (non)required.
* Improved the JSON Schema generation for tools, solving inconsistencies between methods and functions, and ensuring a predictable outcome.
* Added support for returning tool results directly to the user instead of passing them back to the model. Introduced new ToolExecutionResult API to propagate this information.
* Consolidated naming of tool-related options in ToolCallingChatOptions.
* Fixed varargs issue in ChatClient when passing ToolCallback[].
* Introduced new documentation for the tool calling capabilities in Spring AI, and deprecated the old one.
* Bumped jsonschema dependency to 4.37.0.

Relates to gh-2049

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-02-04 12:59:17 +01:00
Ilayaperumal Gopinathan
c5becf7429 Fixes for Integration Tests
- Multi modality image tests to assert with containsAny instead of contains specific values
 - Expand Mistral functionCall test's usage metrics range
2025-02-03 23:42:37 +00:00
Ilayaperumal Gopinathan
2932769883 Switch back to use slf4j logging
- Revert the changes to update to use Apache Commons Logging and re-add the previously used slf4j logging
2025-02-03 15:31:43 -05:00
Ilayaperumal Gopinathan
54463e6622 Fix EmbeddingIT#defaultEmbedding test
- Use text-embedding-ada-002-v2 as OpenAI routes to text-embedding-ada-002-v2 by default
2025-02-03 14:03:42 +00:00
Ilayaperumal Gopinathan
ca27895da4 Remove deprecated Amazon Bedrock chat models
- Amzon Bedrock chat models were deprecated to support Amazon Bedrock Converse API for the chat models.
 - This PR removes all the references of the deprecated Amazon Bedrock chat models
   - Remove Amazon Bedrock chat models for anthropic, anthropic3, cohere, jurassic2, titan
      - Remove API, chat options and model
      - Remove tests and doc references
   - Update the doc to reflect the changes
   - Update upgrade notes

Resolves #2124

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-01-31 16:11:52 -05:00
Mark Pollack
cc730268e7 Fix race condition waiting for status of ollama model pull success status 2025-01-31 11:11:44 -05:00
Ilayaperumal Gopinathan
a61437df6e Fix usage metrics for the MistralAiChatModelIT tests 2025-01-31 14:40:46 +00:00
Thomas Vitale
b902ca2afb Advancing Tool Support - Part 4
* Adopted new tool calling logic in OllamaChatModel, while maintaining full API backward compatibility thanks to the LegacyToolCallingManager.
* Improved efficiency and robustness of merging options in prompts for Ollama.
* Update Ollama Autoconfiguration to use the new ToolCallingManager.
* Improved troubleshooting for new tool calling APIs and finalised changes for full backward compatibility.
* Updated Ollama Testcontainers dependency to 0.5.7.

Relates to gh-2049

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-01-30 17:34:24 +01:00
Ilayaperumal Gopinathan
97f7768054 Fix required POM attributes for maven staging deployment 2025-01-29 18:58:38 +00:00
Christian Tzolov
bb3fde3622 Fix logger reformating error 2025-01-29 19:57:46 +01:00
Christian Tzolov
f36b73cce2 refactor: migrate from functions to tools terminology
Refactors the test codebase to use tools instead of functions.

- Rename FunctionCallback to FunctionToolCallback
- Rename FunctionCallingOptions to ToolCallingChatOptions
- Update API methods from functions() to tools()
- Deprecate function-related methods in favor of tool alternatives
- Refactor MethodToolCallback implementation with improved builder pattern
- Update all tests to use new tool-based APIs
- Add funcs to tools migration guide

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-01-29 19:50:41 +01:00
Assassinxc
62ce753b12 Add dimensions option for ZhiPuAi embedding model
- Add dimentions options
 - Add doc for ZhiPuAi embedding dimensions option

Signed-off-by: Assassinxc <330109311@qq.com>
2025-01-29 11:51:30 +00:00
Ilayaperumal Gopinathan
14ec6b2dc0 Use Usage#getCompletionTokens instead of deprecated Usage#getGenerationTokens 2025-01-29 10:58:57 +00:00
Ilayaperumal Gopinathan
78a58a15e8 Update commons logging for the latest changes 2025-01-29 10:21:20 +00:00
Ilayaperumal Gopinathan
b03a6c9ef8 Fix the default value of OpenAI chat option
- The OpenAI chat option metadata can be set only when the store value is enabled.
 - Change the default value from empty map to null
2025-01-28 20:01:12 +00:00
Ilayaperumal Gopinathan
fe323fbad1 Support store and metadata OpenAI chat options
- Add store and metadata as OpenAI Chat options
 - Add test

Resolves #2103
2025-01-28 12:39:36 -05:00
Ilayaperumal Gopinathan
8303a52611 Use Apache Commons Logging
- Remove existing spring-boot-starter-logging
 - Update to use Springframework's LogAccessor to use commons logging

Resolves #2095
2025-01-28 11:00:05 +00:00
Alexandros Pappas
bada403643 Add documentation how to use the OpenAI client to access DeepSeek
Signed-off-by: Alexandros Pappas <alexandros.pappas@yiluhub.com>
2025-01-27 16:45:00 -05:00
Ilayaperumal Gopinathan
4b64aa0ca6 Refactor Usage handling
- Remove model specific Usage implementations
- Add `Object getNativeUsage()` to Usage interface
  - This will allow the model specific Usage data to be returned
  - At the client side, client needs to cast the return type of `getNativeUsage` into the corresponding Usage returned by the model API
- Rename `generationTokens` to `completionTokens`
  - Since `completion` token name is more common among the models, renaming generation tokens into completion tokens
  - Maintain JSON deserialization compatibility for legacy `generationTokens` field
  - Remove deprecated Long-based constructors to avoid API ambiguity
- Change the prompt, completion and total token return types from Long to Integer
  - This is a breaking change that requires updating all constructor calls
  - Integer is sufficient for token counts and aligns better with most model APIs
- Use DefaultUsage for most of the model specific usage handling
  - When initializing set the native usage to the model specific usage type
  - Ensure immutability by making all fields final and removing setters
  - Add comprehensive test coverage for all functionality including edge cases

Resolves #1407
2025-01-27 16:29:07 -05:00
Christian Tzolov
39be9aeba2 Fix tools test configuration 2025-01-26 07:28:51 +01:00
Mark Pollack
7521cab9db Remove deprecated methods/classes from spring-ai-core 2025-01-24 13:37:14 -05:00
Alexandros Pappas
bb6b8cc20f Refactor OpenAIAudio builder methods
- Refactor the builder methods to remove `with` as the prefix.
- Introduce new methods with updated naming conventions.
- Deprecate the existing `with*` methods to maintain backward compatibility.

Signed-off-by: Alexandros Pappas <alexandros.pappas@yiluhub.com>
2025-01-24 11:47:04 +00:00
Ilayaperumal Gopinathan
f5761de087 Fix Moonshot Chat model toolcalling token usage
- Accumulate the token usage when toolcalling is invoked
   - Fix both call() and stream() methods
     - Add `usage` field to the Chat completion choice as the usage is returned via Choice
 - Add Mootshot chatmodel ITs for functioncalling tests

Move the tests into MoonshotChatModelFunctionCallingIT
2025-01-21 11:28:29 +00:00
Alexandros Pappas
1280c2a3ba feat(minimax): add support for MiniMax-Text-01 model
This commit adds support for the MiniMax-Text-01 model,
which is recommended for general scenarios due to its
longer context window.

The new model is added to the ChatModel enum as MiniMax_Text_01.

Signed-off-by: Alexandros Pappas <alexandros.pappas@yiluhub.com>
2025-01-20 10:24:29 +00:00
Ricken Bazolo
a0e0508cc0 Resolve Mistral AI Function Call issue and activate testing.
Signed-off-by: Ricken Bazolo <ricken.bazolo@gmail.com>
2025-01-20 10:01:56 +00:00
dafriz
9d95f0f7c9 Add o1 model to OpenAI ChatModel enum 2025-01-17 16:17:06 +00:00
jitokim
18a1bc1821 Add New Version of Minimax ChatModel
Signed-off-by: jitokim <pigberger70@gmail.com>
2025-01-17 16:08:29 +00:00
pir
7e303a06e5 Add additional OpenAI TTS Voice options
- Add OpenAI TTS Voice Unit Test
2025-01-17 13:31:39 +00:00
Andreas Köninger
510d51a5e6 Azure OpenAI: add logprobs to ChatGenerationMetadata
Signed-off-by: Andreas Köninger <andiveloper1@gmail.com>
2025-01-17 13:10:10 +00:00
Alexandros Pappas
7d53ef2056 chore: replace all instances of 'final static' with 'static final' 2025-01-15 15:16:12 +00:00
Ilayaperumal Gopinathan
3c539a37a3 Remove deprecated methods from models 2025-01-06 16:59:33 -05:00
Ilayaperumal Gopinathan
977500f7a1 Remove deprecated classes and methods in spring-ai-core
* Remove use of Document.getContext method from spring-ai-core, use getText
* Remove deprecated ChatOptionsBuilder class
* Remove deprecated FunctionCallingOptionsBuilder class
2025-01-06 16:57:55 -05:00
Ilayaperumal Gopinathan
823766f436 Fix OpenAiChatModelIT#streamingWithTokenUsage
- Modify the streaming vs call usage assertion to match the close to 25% value
   - This change is done because the OpenAI chat response for call and stream invocation results in slight change in usage.
2025-01-02 15:38:18 +00:00