Commit Graph

652 Commits

Author SHA1 Message Date
Alexandros Pappas
092bbae5a1 feat: Add equals, hashCode, deep copy, and tests to AnthropicChatOptions
This commit enhances `AnthropicChatOptions` by:

- Adding `equals` and `hashCode` methods for proper object comparison.
- Implementing a deep `copy()` method, creating new instances of mutable collections (List, Set, Map, Metadata) to prevent shared state.
- Adding `AnthropicChatOptionsTests` to verify `copy()`, builders, setters, and default values.

Signed-off-by: Alexandros Pappas <apappascs@gmail.com>
2025-03-02 12:43:09 +01:00
Christian Tzolov
041d94f0c9 feat(anthropic): add support for custom HTTP headers in Anthropic API requests (#2343)
Add the ability to specify custom HTTP headers for Anthropic API requests through AnthropicChatOptions.
This allows users to override or add headers for authentication, tracking, or other API-specific requirements.

- Add httpHeaders field to AnthropicChatOptions with appropriate getters/setters
- Implement header merging between default and runtime options
- Update AnthropicApi to accept additional HTTP headers in API calls
- Add integration test demonstrating API key override via custom headers
- Update documentation with the new configuration property

Resolves #2335

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-28 09:57:10 -05:00
蕭洛
6be3d0a809 Add new Ollama models: LLAMA3_2_3B
Signed-off-by: 蕭洛 <799332391@qq.com>
2025-02-27 11:16:07 +00:00
Christian Tzolov
82d98b6b48 fix: reverse ToolContext validation logic in MethodToolCallback
Changes the validation logic in MethodToolCallback to check if a ToolContext is required by the method but not provided,
rather than checking if a ToolContext is provided but not supported by the method.
This ensures methods that expect a ToolContext parameter receive one.

Updates tests cases to reflect the new validation logic

Resolves #2337

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-27 11:07:54 +01:00
Christian Tzolov
3dfea48249 feat(anthropic): update to Claude 3.7 Sonnet and refactor API
- Add support for Claude 3.7 Sonnet model and make it the default
- Rename function-related APIs to tool-related APIs for consistency:
- Change functionCallbacks to toolCallbacks
- Change function to toolNames
- Replace FunctionCallingOptions with ToolCallingChatOptions
- Refactor AnthropicChatModel instantiation to use builder pattern
- Update tests to use latest model versions instead of dated versions

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-26 22:36:52 -05:00
Alexandros Pappas
c623264666 refactor: replace wildcard imports with explicit class imports
Signed-off-by: Alexandros Pappas <apappascs@gmail.com>
2025-02-14 14:12:43 +00:00
ogirardot
dd9e574092 fix(spring-ai-azure-openai): last chat completions can have null deltas
Signed-off-by: ogirardot <olivier.girardot@arkhn.com>
2025-02-14 07:55:18 +00:00
Christian Tzolov
e4d8a9c3ef fix(vertex-ai): Invert proxyToolCalls flag to match internal tool execution behavior
The proxyToolCalls flag was incorrectly mapped to internalToolExecutionEnabled. This change inverts the boolean value to
properly reflect that proxy tool calls are the opposite of internal tool execution.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-14 00:20:52 +01:00
Christian Tzolov
1fdda61db8 feat(autoconfigure): Support both FunctionCallback and ToolCallback in ToolCallingAutoConfiguration
- Extends the ToolCallingAutoConfiguration to support both FunctionCallback and ToolCallback types.
- The toolCallbackResolver bean now handles both callback types through ObjectProvider injection.
- Added comprehensive tests to verify the resolution of multiple function and tool callbacks.
- Introduce new StaticToolCallbackProvider implementation
- Update ToolCallbackProvider to return FunctionCallback[]
- Migrate from List to ToolCallbackProvider in configurations
- Update tests to use new provider pattern
- Enhance tool callback providers to support multiple clients
  - Refactor AsyncMcpToolCallbackProvider and SyncMcpToolCallbackProvider to handle multiple MCP clients
  - Add ToolCallbackProvider support to ChatClient API
  - Deprecate direct tool callback list methods in favor of providers
  - Fix typos in Closeable class names
  - Update MCP documentation with new examples and usage patterns

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-13 20:31:20 +01:00
Ilayaperumal Gopinathan
a528253ab0 Use ApiKey for OpenAI Image/Audio/Moderation APIs
- Update to use ApiKey when instantiating OpenAI Image/Audio/Moderation APIs
 - Add Builders for OpenAI Image/Audio/Moderation APIs and deprecate existing constructors
 - Add/update tests
 - Replace hasText check with notNull for ApiKey with String value

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-02-13 13:24:48 +01:00
Christian Tzolov
c19287d808 feat(bedrock): Add StopReason check for tool execution
Add StopReason.TOOL_USE validation before executing tools to ensure proper tool execution flow.
Remove unused commented code and improve code formatting.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-13 10:31:02 +01:00
Thomas Vitale
b7dcfc1198 Anthropic - Adopt ToolCallingManager API
- Update AnthropicChatModel to use the new ToolCallingManager API, while ensuring full API backward compatibility.
- Introduce Builder to instantiate a new AnthropicChatModel since the number of overloaded constructors is growing too big.
- Update documentation about tool calling and Anthropic support for that.

Part of the #2207 epic

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-02-13 09:48:34 +01:00
Christian Tzolov
8463454a87 docs: enhance Vertex AI Gemini documentation and code organization
- Add javadoc for VertexAiGeminiChatModel including features, examples, and cross-references
- Document JsonSchemaConverter and VertexToolCallingManager classes and methods
- Fix formatter annotation placement in VertexAiGeminiChatOptions

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-13 09:21:49 +01:00
Christian Tzolov
3393e98bdb refactor: Use centralized JsonParser utility instead of local ObjectMapper instance
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-13 08:48:35 +01:00
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