Commit Graph

711 Commits

Author SHA1 Message Date
Soby Chacko
f18aac07b7 GH-2518: Remove requestOptions from observation context objects
Fixes: #2518

Issue: https://github.com/spring-projects/spring-ai/issues/2518

This commit removes the deprecated requestOptions field from ChatModelObservationContext
and EmbeddingModelObservationContext classes. Instead of passing options separately,
the code now retrieves them directly from the request objects (prompt.getOptions() or
embeddingRequest.getOptions()).

Key changes:
- Removed requestOptions parameter from observation context builders
- Updated all model implementations to stop passing options separately
- Fixed EmbeddingRequest handling in several model implementations
- Added buildEmbeddingRequest method in models to properly merge options

This change simplifies the API and removes duplication, as options are already
available in the request objects themselves.

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-28 16:44:13 +01:00
Ilayaperumal Gopinathan
8deb23afe1 Removing deprecated constructors and methods
- VectorStoreChatMemoryAdvisor constructors
- "withX" methods in AnthropicApi
- Deprecated function methods in VertexAiGeminiChatOptions
- Deprecated test methods
- Removed deprecation from Document.getContentFormatter
- Removed withEmbedding method in SimpleVectorStoreContent")

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-28 10:28:22 -04:00
Ilayaperumal Gopinathan
7f0a97d4a7 Remove FunctionCallbackResolver from chat model autoconfigurations
- FunctionCallbackResolver is deprecated and replaced by ToolCallingManager's ToolCallbackResolver

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-28 08:01:59 +01:00
Thomas Vitale
0024e4dd49 Chat Memory Enhancements
* ChatMemory will become a generic interface to implement different memory management strategies. It’s been moved from the “”spring-ai-client-chat” package to “spring-ai-model” package while retaining the same package, so it’s transparent to users.
* A MessageWindowChatMemory has been introduced to provide support for a chat memory that keeps at most N messages in the memory.
* A ChatMemoryRepository interface has been introduced to support different storage strategies for the chat memory. It’s meant to be used as part of a ChatMemory implementation. This is different than before, where the storage-specific implementation was directly tied to the ChatMemory. This design is familiar to Spring users since it’s used already in the ecosystem. The goal was to use a programming model similar to Spring Session and Spring Data.
* The JdbcChatMemory has been supersed by JdbcChatMemoryRepository.
* A ChatMemory bean is auto-configured for you whenever using one of the Spring AI Model starters. By default, it uses the MessageWindowChatMemory implementation and stores the conversation history in memory. If a different repository is already configured (e.g., Cassandra, JDBC, or Neo4j), Spring AI will use that instead.
* First-class documentation has been introduced to describe the ChatMemory API and related features.
* All the changes introduced in this PR are backward-compatible.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-04-25 15:53:20 -04:00
Ilayaperumal Gopinathan
9692ebd7b4 Refactor toolcalling support for ZhipuAI
- Update ZhipuAI Chat Model to use ToolCalling Manager and ToolExecutionEligibilityPredicate
 - Update ZhipuAI ChatOptions to implement ToolCallingChatOptions
 - Update Autoconfiguration for ZhipuAI model to use ToolCallingAutoconfiguration
 - Update tests

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-25 19:47:34 +01:00
Ilayaperumal Gopinathan
49e1dd10a9 Refactor toolcalling support for Minimax
- Update Minimax Chat Model to use ToolCalling Manager and ToolExecutionEligibilityPredicate
 - Update Minimax ChatOptions to implement ToolCallingChatOptions
 - Update Autoconfiguration for MinimaxChat model to use ToolCallingAutoconfiguration
 - Update tests

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-25 19:47:34 +01:00
Mark Pollack
98052624b1 Remove Qianfan and Moonshot model modules
Drop support for the Qianfan and Moonshot models by removing their modules from the build.

These integrations are now maintained in the community repositories:
https://github.com/spring-ai-community/qianfan
https://github.com/spring-ai-community/moonshot
2025-04-25 14:02:23 -04:00
Mark Pollack
ff52859b2d migrate remaining moonshot modules to community repo 2025-04-25 13:05:11 -04:00
Soby Chacko
687dea52e0 Update Bedrock runtime from 2.29.29 to 2.31.26
- Update bedrockruntime.version to 2.31.26 in root pom.xml
- Standardize AWS SDK dependencies in bedrock-converse module to use
  bedrockruntime.version property instead of awssdk.version
- Affected dependencies: bedrockruntime, sts, netty-nio-client

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-23 12:36:28 -04:00
Ilayaperumal Gopinathan
c0bc6231a5 Remove FunctionCallback deprecations
- Remove the super type FunctionCallingOptions from ToolCallingChatOptions

        - Move toolContext builder methods into ToolCallingChatOptions

    - Remove Model chat options' function specific usages

        - Replace them with tooling:

              FunctionCallback -> ToolCallback
              functions -> toolNames
        - Remove proxyToolCalls use

        - Remove deprecated methods

     - Update ChatClient methods

        - Replace FunctionCallback -> ToolCallback

        - Remove deprecated methods

     - Update DefaultChatClient

        - functionNames -> toolNames
        - functionCallbacks -> toolCallbacks

     - Update AdviseRequest

        - functionNames -> toolNames
        - functionCallbacks -> toolCallbacks
        - Remove FunctionCallingOptions and replace it with ToolCallingOptions

      - Remove FunctionCallingHelper

      - Update DefaultToolCallingChatOptions, ToolCallbackResolvers, ToolCallbackProvider to use Tool calling types

     - Update documentation

     - Remove VertexAiGeminiChatModelFunctionCallingIT and adjust MistralAiApiToolFunctionCallIT

Resolves #2528
Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-18 10:55:55 +02:00
Soby Chacko
3756e16526 Upgrade azure-open-ai-client to 1.0.0-beta.16
Adjust MergeUtils to accommodate API changes:
- Update ChatCompletions constructor parameter list to remove the usage argument
- Move usage assignment to post-construction via reflection

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-17 17:07:11 -04:00
ddobrin
6e0c09838f Fixes #2185 - googleSearchRetrieval(true) causes INVALID_ARGUMENT error with Gemini 2.0 (use google_search instead) 2025-04-17 14:22:30 -04:00
ddobrin
53359fd9e6 Fixes #2185 - googleSearchRetrieval(true) causes INVALID_ARGUMENT error with Gemini 2.0 (use google_search instead) 2025-04-17 14:22:30 -04:00
Thomas Vitale
1f59ccadad Make ChatClient and Advisor APIs more robust - Part 1
- Introduce “ChatClientRequest” and “ChatClientResponse” for propagating requests/responses in a ChatClient advisor chain.
- Structure a Prompt at the beginning of the chain, to ensure a consistent view across execution chain and observations. Any template is rendered at the beginning so that every advisor doesn’t have to do it again.
- Improve observations to include the complete view of the prompt messages, instead of only considering userText and systemText.
- Remove legacy “around” advisor type concept.
- Keep backward compatibility for AdvisedRequest, AdvisedResponse, and legacy Advisor APIs.

Relates to gh-2655

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-04-17 13:31:26 +02:00
Alexandros Pappas
593083980b Docs: Update OpenAI chat model definitions
Sync the ChatModel enum with the latest OpenAI documentation:
- Reorganize models into categories.
- Add new models (o4-mini, o3, o1-pro, gpt-4.1 series, realtime previews).
- Update descriptions, context windows, max tokens, and knowledge cutoffs.
- Add links to official model documentation.
- Remove deprecated/preview models.

Signed-off-by: Alexandros Pappas <apappascs@gmail.com>
2025-04-17 11:22:16 +01:00
Soby Chacko
53a7af500b Addressing the remaining checkstyle failures
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-15 11:04:03 +01:00
Ilayaperumal Gopinathan
76a1dbe747 Fix ToolCallingChatOptions isInternalToolExecutionEnabled
- The ModelOptionsUtils merges the ToolCallingChatOptions with the provider chat options
   - The underlying beanwrapper implementation expects the boolean option to have the getter method starting with "get" instad of "is" which makes the current `isInternalToolExecutionEnabled` not used by the merge operation at all. To fix this, rename the `isInternalToolExecutionEnabled` method to `getInternalToolExecutionEnabled` and deprecate the existing `isInternalToolExecutionEnabled` method.

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-15 10:14:57 +02:00
Tran Ngoc Nhan
257c91ccf2 Fix typo (#2719)
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
2025-04-14 16:35:06 +01:00
Gareth Evans
91937d0dce fix: predicate should be wired in even if toolCallingManager is not null
Signed-off-by: Gareth Evans <gareth@bryncynfelin.co.uk>
2025-04-14 12:05:18 +02:00
Soby Chacko
d9e7ace996 Miscellaneous checkstyle fixes
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-14 09:48:03 +01:00
Ilayaperumal Gopinathan
bda702e8e1 Next development version 2025-04-10 20:23:38 +01:00
Ilayaperumal Gopinathan
584138af28 Release version 1.0.0-M7 2025-04-10 20:23:07 +01:00
Ilayaperumal Gopinathan
352c0d83be Update TitanEmbeddingBedrockApi for TitanEmbeddingResponse
- Update the fields successCount, failureCount and results

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-10 19:41:24 +01:00
Eddú Meléndez
eef5f74b4c Add support for Docker Model Runner
- Docker Desktop 4.40 has released a Docker Model Runner, which is OpenAI compatible.
- Add docs for Docker Model Runner

Signed-off-by: Eddú Meléndez <eddu.melendez@gmail.com>
2025-04-10 11:58:25 -04:00
gongzhongqiang
923e09a1b0 feat(ollama): Add min_p parameter for improved sampling control
- Add min_p option
- Add qwq model

Signed-off-by: gongzhongqiang <gongzhongqiang@apache.org>
2025-04-10 11:20:13 +01:00
Soby Chacko
186175a96d Refactor RuntimeHints to scan entire packages for JsonInclude annotations (#2681)
- Replace class-by-class scanning with comprehensive package-level scanning to capture
  all JSON-annotated classes within each model's package hierarchy.
- Update tests to verify registered types and add specific type assertions.

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-09 19:22:35 -04:00
Soby Chacko
b8a1b9fcc4 Split META-INF.spring in watsonx model into two separate directories - META-INF/spring (#2682)
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-09 19:12:28 -04:00
Soby Chacko
b313645148 Model update in VertexAiGeminiChatModelIT from GEMINI_2_5_PRO to GEMINI_2_0_FLASH
Update gemini-2.5-pro-exp-03-25 to gemini-2.5-pro-exp-03-28

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-09 16:33:44 -04:00
jonghoon park
14e7033a8e refactor(openai): change voice parameter to string in OpenAI Audio Speech API (#2395)
This change modifies the voice parameter in OpenAI Audio Speech API from using the
Voice enum directly to using the string value of the enum. This provides more
flexibility for handling voice options, especially for custom voices or when voice
names come from configuration.

- Change voice parameter type from Voice enum to String
- Add overloaded methods to accept both enum and string values
- Update tests and documentation to reflect these changes

Signed-off-by: jonghoon park <dev@jonghoonpark.com>
2025-04-09 21:10:31 +02:00
Ricken Bazolo
3fcb10a326 feat(mistral-ai): Add moderation model support (#2201)
Implement MistralAI moderation capabilities to detect potentially harmful content.
This allows Spring AI applications to use Mistral's content moderation services
to identify and filter inappropriate content before processing

- Add MistralAiModerationApi for interacting with Mistral's moderation endpoints
- Create MistralAiModerationModel implementing the ModerationModel interface
- Add configuration properties and auto-configuration for the moderation model
- Extend Categories and CategoryScores with additional moderation categories
- Add integration tests to verify moderation functionality

Signed-off-by: Ricken Bazolo <ricken.bazolo@gmail.com>
2025-04-09 19:51:34 +02:00
Ilayaperumal Gopinathan
d30631e699 Google Vertex AI toolcalling token usage
- Accumulate token usage metrics when toolcalling is used
 - Fix for both call() and stream() methods
 - Add/update tests

Resolves #1992

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-09 12:44:08 -04:00
Alexandros Pappas
4f67959645 feat: Enhance Anthropic integration with Thinking
- The `thinking` option is added to `AnthropicChatOptions` and `ChatCompletionRequest`.
- The `AnthropicApi` and `AnthropicChatModel` now handle `THINKING` and `REDACTED_THINKING` content blocks in responses.  New tests verify parsing of these blocks.
- Updated method signatures on ChatCompletionRequestBuilder, deprecating old builders with `with*` prefix in favor of those without.

Signed-off-by: Alexandros Pappas <apappascs@gmail.com>
2025-04-09 18:38:10 +02:00
Josh Long
fbec267eca first cut of aot improvements
Signed-off-by: Josh Long <54473+joshlong@users.noreply.github.com>
2025-04-08 19:25:39 +01:00
Christian Tzolov
0d748e2b87 feat(tool): Add ToolExecutionEligibilityChecker interface
Introduce a new ToolExecutionEligibilityChecker interface to provide a more flexible way to determine
when tool execution should be performed based on model responses. This abstraction replaces the
hardcoded logic previously scattered across the codebase.

- Adds a new ToolExecutionEligibilityChecker interface in spring-ai-core
- Integrates the checker into OpenAiChatModel with appropriate defaults
- Updates OpenAiChatAutoConfiguration to support the new interface
- Provides a default implementation that maintains backward compatibility

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>

refactor: Replace ToolExecutionEligibilityChecker with ToolExecutionEligibilityPredicate

- Replacing ToolExecutionEligibilityChecker with ToolExecutionEligibilityPredicate
- Changing from Function<ChatResponse, Boolean> to BiPredicate<ChatOptions, ChatResponse>
- Adding a DefaultToolExecutionEligibilityPredicate implementation
- Updating AnthropicChatModel and OpenAiChatModel to use the new predicate
- Updating auto-configurations to inject the new predicate
- Adding comprehensive tests for the new predicate implementation

The new approach provides a cleaner and more consistent way to determine when tool execution should be performed based on both prompt options and chat responses.

Add Bedrock Converse support

add mistral support

Add ollama and vertex gemini

add ToolExecutionEligibilityPredicate docs

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-08 15:22:53 +01:00
samuel-taleez
fbd03b7f55 feat(mistral-schema): allow custom structured output with json schema (#2211)
Signed-off-by: krsamuel <samuel.t.kerr@gmail.com>
2025-04-08 11:59:57 +02:00
Soby Chacko
717e419515 Rename spring-ai parent from spring-ai to spring-ai-parent
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-04 12:43:22 -04:00
Soby Chacko
d94a3c9f40 Moving LoggingMarkers and ResourceUtils from spring-ai-client-chat to spring-ai-commons
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-04 12:43:22 -04:00
Mark Pollack
76d6e7d6d0 Update docs based on module refactorings 2025-04-04 12:43:22 -04:00
Mark Pollack
72e746db13 Move chat based enrichers to a new package to avoid conflicts with other enrichers in different modules 2025-04-04 12:43:22 -04:00
Mark Pollack
d45ff8e984 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-04 11:44:38 -04:00
Mark Pollack
e3f9b7c16b rename spring-ai-core to spring-ai-client-chat 2025-04-04 11:44:38 -04:00
Soby Chacko
3233e10054 Migrage reader/transformer/writer packages from core to commons
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-04 11:44:38 -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