Commit Graph

676 Commits

Author SHA1 Message Date
Soby Chacko
bd82e73193 Rename spring-ai parent from spring-ai to spring-ai-parent
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-03 10:11:03 -04:00
Soby Chacko
ee5f9f361c Moving LoggingMarkers and ResourceUtils from spring-ai-client-chat to spring-ai-commons
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-03 10:11:03 -04:00
Mark Pollack
676c139efb Update docs based on module refactorings 2025-04-03 10:11:03 -04:00
Mark Pollack
2467359ade Move chat based enrichers to a new package to avoid conflicts with other enrichers in different modules 2025-04-03 10:11:03 -04:00
Mark Pollack
278db764b3 Refactorings
- Avoid overlapping package names
  Changed in spring-ai-commons package from org.sf.ai.model to org.sf.ai.content
  Refactor advisor module name to be spring-ai-advisors-vector-store
    Moved advisors into org.springframework.ai.chat.client.advisor.vectorstore

- Created top level memory directory
- Create new module spring-ai-model-chat-memory-neo4j and moved neo4j memory classes out of the vectorstore module
  Updated neo4j autoconfiguation
2025-04-03 10:11:03 -04:00
Mark Pollack
85555003ad rename spring-ai-core to spring-ai-client-chat 2025-04-03 10:11:03 -04:00
Soby Chacko
9875aaf1ca Migrage reader/transformer/writer packages from core to commons
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-03 10:11:03 -04:00
Alexandros Pappas
8f20aabfdc feat: Add equals, hashCode, deep copy, tests to OpenAiChatOptions
This commit enhances OpenAiChatOptions by:
- Updating copy() method, creating new instances of mutable collections (List, Set, Map, Metadata) to prevent shared state.
- Adding OpenAiChatOptionsTests to verify copy(), builders, setters, and default values.

Signed-off-by: Alexandros Pappas <apappascs@gmail.com>
2025-04-03 10:45:47 +01:00
Yanming Zhou
20c4954521 Fix typo in prompt system messages for the models' tests
Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
2025-04-03 07:50:57 +01:00
rmalara
2517ca8020 GH-2609: Fix the thread leak issue in VertexAiTextEmbeddingModel
Fixes: #2609

https://github.com/spring-projects/spring-ai/issues/2609

The PredictionServiceClient was not being closed. Connections are kept open preventing resources from being disposed properly.

Signed-off-by: rmalara <rmalara@interactions.com>
Signed-off-by: Rodrigo Malara <rodrigomalara@gmail.com>
2025-04-02 18:17:57 -04:00
mawenhao
e888895a4e fix(openai): prevent incorrect ToolCall merging caused by empty id and name strings
Empty tool call id and name strings causing improper ToolCall merging during OpenAI stream
processing, resulting in incorrect function calling responses. This fix ensures both null
and empty strings are properly validated before merging operations.

Fixes GH-2417 (https://github.com/spring-projects/spring-ai/issues/2417)
Fixes GH-2423 (https://github.com/spring-projects/spring-ai/issues/2423)

Signed-off-by: Wenhao Ma <296232679@qq.com>
2025-04-01 11:01:38 +01:00
gabriel duncan
64a4f79783 Add missing audio formats for OpenAIAudio API
- Add missing formats "wav" and "pcm" which OpenAI supports but SpringAI does not have serializers for

Signed-off-by: gabriel duncan <gabrielduncan@Mac.attlocal.net>
2025-04-01 10:27:26 +01:00
Thomas Vitale
24fb447227 openai: Adopt new strategy for ObservationContext
Relates to gh-2518

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-03-27 11:53:28 +00:00
Thomas Vitale
3d1825dd05 ollama: Adopt new strategy for ObservationContext
Relates to gh-2518

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-03-27 11:29:14 +00:00
Thomas Vitale
20deb0e653 mistral: Adopt new strategy for ObservationContext
Relates to gh-2518

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-03-27 09:40:27 +00:00
Christian Tzolov
fc955c74eb feat(mcp): Refactor MCP server API to use Specification pattern
- Rename Registration classes to Specification (SyncToolRegistration → SyncToolSpecification)
- Update transport classes to use Provider suffix (WebFluxSseServerTransport → WebFluxSseServerTransportProvider)
- Add exchange parameter to handler methods for better context passing
- Introduce McpBackwardCompatibility class to maintain backward compatibility
- Update MCP Server documentation to reflect new API patterns
- Add tests for backward compatibility
- Update mcp version to 0.8.0
- Add mcp 0.8.0 breaking change note-

The changes align with the MCP specification evolution while maintaining backward compatibility through deprecated APIs.

refactor: Extract MCP tool callback configuration into separate auto-configuration

Extracts the MCP tool callback functionality from McpClientAutoConfiguration into a
new dedicated McpToolCallbackAutoConfiguration that is disabled by default.

- Created new McpToolCallbackAutoConfiguration class that handles tool callback registration
- Made tool callbacks opt-in by requiring explicit configuration with spring.ai.mcp.client.toolcallback.enabled=true
- Removed deprecated tool callback methods from McpClientAutoConfiguration
- Updated ClientMcpTransport references to McpClientTransport to align with MCP library changes
- Added tests for the new auto-configuration and its conditions

refactor: standardize tool names to use underscores instead of hyphens

- Change separator in McpToolUtils.prefixedToolName from hyphen to underscore
- Add conversion of any remaining hyphens to underscores in formatted tool names
- Update affected tests to reflect the new naming convention
- Add comprehensive tests for McpToolUtils.prefixedToolName method
- Add integration test for payment transaction tools with Vertex AI Gemini

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-25 14:23:12 -04:00
Alexandros Pappas
1f2713801c chore: remove unused imports (#2470)
Signed-off-by: Alexandros Pappas <apappascs@gmail.com>
2025-03-17 15:53:52 +00:00
shown
0164b5dcf9 optimize: OpenAI chat model code cleanup (#2483)
* optimize: use already defined variables

Signed-off-by: yuluo-yx <yuluo08290126@gmail.com>
2025-03-17 15:51:10 +00:00
jonghoon park
77ee57cec0 allow null usage for openai embedding model
Signed-off-by: jonghoon park <dev@jonghoonpark.com>
2025-03-17 15:43:27 +00:00
Alexandros Pappas
bc375ab961 This commit enhances AzureOpenAiChatOptions 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 `AzureOpenAiChatOptionsTests` to verify `copy()`, builders, setters, and default values.

Signed-off-by: Alexandros Pappas <apappascs@gmail.com>
2025-03-13 11:39:49 +01:00
Gareth Evans
beb81ef409 chore: add missing toolCallbacks(vargs) to vertex chat options
Signed-off-by: Gareth Evans <gareth@bryncynfelin.co.uk>
2025-03-13 07:57:10 +01:00
Ilayaperumal Gopinathan
ded9facfe5 Remove deprecations from 1.0.0-M6
- Remove deprecations from models, vector stores and usage
- Deprecations from FunctionCallback and ObservationContext/Convention will be in a separate PR

Models updates
  - Remove AbstractToolCallSupport from the models which use ToolCallingManager
  - Remove deprecated constructors and their usage
  - Remove FunctionCallbackResolver and FunctionCallbacks usage in the models

- Add back deprecations for VectorStoreChatMemoryAdvisor until builder is fixed

- Update OpenAiPaymentTransactionIT to use ToolCallbackResolver in config

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-03-11 10:42:03 -04:00
Dariusz Jędrzejczyk
28bceb3ac5 Prevent blocking event loop calling tools
When streaming happens on an event loop, due to the fact that currently
tools can only be synchronous and blocking, every tool call needs to be
offloaded to a blocking-safe Scheduler.

Resolves #2341

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-03-10 14:08:56 +01:00
jonghoon park
29fde4f7f1 Make allow negative keep alive value with OllamaEmbeddingModel
Signed-off-by: jonghoon park <dev@jonghoonpark.com>
2025-03-03 10:33:32 +00:00
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