Commit Graph

725 Commits

Author SHA1 Message Date
Mark Pollack
091fca2d16 refactor(client): rename overloaded tools methods in prompt builder
Renames the ambiguous overloaded `tools` methods in `ChatClient.PromptRequestSpec`
to `toolNames` and `toolCallbacks` respectively. This improves clarity
and prevents potential issues with method dispatching based on argument types.

Updates relevant code examples and adds documentation to upgrade notes.

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-04-30 10:42:46 -04:00
Ilayaperumal Gopinathan
ec95eeb250 Revert "Add default ChatOptions to Prompt"
This reverts commit 4eeeb83d3f.

Revert "Make ImageOptions non-null when constructing ImagePrompt"

This reverts commit 0c0787b849.

Need to review more the impact of making these options not null.

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-30 10:21:52 -04:00
Berjan Jonker
af0303f65a Make responseMessage in AzureOpenAiChatModel.buildGeneration null-safe
Signed-off-by: Berjan Jonker <berjanjonker@users.noreply.github.com>
2025-04-30 09:53:23 -04:00
Thomas Vitale
5527d037f2 Configure TemplateRenderer in ChatClient
- Extend the ChatClient with a new templateRenderer() method to pass a custom TemplateRenderer object used to render user and system templates.
- Evolve the QuestionAnswerAdvisor to accept a PromptTemplate for customising the RAG prompt and templating logic while maintaining backward compatibility.
- Introduce integration tests for the QuestionAnswerAdvisor.
- Document the TemplateRenderer API and how to use it to build PromptTemplate with custom templating logic.
- Document how to customise the templating logic used internally by the ChatClient via the TemplateRendererAPI.

Add validation tests and improve PromptTemplate resource handling

Enhance robustness and reliability of the PromptTemplate class with better
resource handling and comprehensive input validation:

- Add dedicated validation tests for builder methods with null/invalid inputs
- Improve renderResource method to gracefully handle edge cases:
  - Null resources return empty string
  - ByteArrayResource handling with proper charset (UTF-8)
  - Empty resources check with proper existence test
  - Better error handling with logging instead of exception propagation
- Add input validation assertions to all Builder methods
- Fix typo in deprecated annotation comment ("fahvor" → "favor")

Update documentation to clarify template rendering in different contexts:
- Add clear notes about TemplateRenderer usage in ChatClient vs Advisors
- Document how advisor template customization differs from ChatClient template rendering
- Add comprehensive API upgrade notes for template-related deprecations
- Include detailed migration examples for PromptTemplate and QuestionAnswerAdvisor

Fixes gh-355, gh-1687, gh-2448, gh-1849, gh-1428

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-04-29 16:21:10 -04:00
jonghoonpark
c6ccc1a4a3 Make allow image url for Anthropic API
Signed-off-by: jonghoonpark <dev@jonghoonpark.com>
2025-04-29 18:12:08 +01:00
“claudio-code”
d7eb9bb32e Added the possibility to configure the path together with the base-url
Signed-off-by: “claudio-code” <suporte2424@outlook.com>
2025-04-29 17:39:16 +01:00
jonghoonpark
f5ac94c8e8 Add a missing getter to the CategoryScores class (#2939)
Signed-off-by: jonghoon park <dev@jonghoonpark.com>
2025-04-29 14:32:06 +01:00
jonghoonpark
b8be96cf79 apply builder pattern to AnthropicApi
Signed-off-by: jonghoonpark <dev@jonghoonpark.com>
2025-04-29 12:18:50 +01:00
jonghoon park
d48f4f63db apply builder pattern to OllamaApi
Signed-off-by: jonghoon park <dev@jonghoonpark.com>
2025-04-29 11:16:52 +01:00
Changho Kim
2e0017db49 fix: Typo at the codebase
fix: correct name typo from 'AsynClients' to 'AsyncClients'

fix: correct name typo from 'Autoconfiguration' to 'AutoConfiguration', 'optoins' to 'options'

fix: correct name typo from 'Differnt' to 'Different'

fix: correct name typo from 'Compatability' to 'Compatibility'

fix: correct name typo from 'Evalutaor' to 'Evaluator'

fix: correct name typo from 'Empyt' to 'Empty'

fix: correct name typo from 'Chroma Vecor Store' to 'Chroma Vector Store'

fix: correct name typo from 'Specificaiton' to 'Specification'

fix: correct name typo from 'applicaiton' to 'application'

fix: correct name typo from 'apropriate' to 'appropriate'

fix: correct name typo from 'asigned' to 'assigned'

fix: correct name typo from 'capabilitity' to 'capability'

fix: correct name typo from 'configuraiton' to 'configuration'

fix: correct name typo from 'conntection' to 'connection'

fix: correct name typo from 'curent' to 'current'

fix: correct name typo from 'customised' to 'customized'

Signed-off-by: Changho Kim <dukso4885@gmail.com>
2025-04-29 10:13:21 +01:00
Seunghyeon Ji
b74e30816c Add three request body parameters to Mistral AI Chat Completion
Add presence_penalty, frequency_penalty, and n parameters
Following Mistral AI API specifications as referenced in https://docs.mistral.ai/api/#tag/chat

Rename Builder method N() to n()

Signed-off-by: Seunghyeon Ji <3aroa2@gmail.com>
2025-04-28 19:05:51 -04:00
Mark Pollack
783e21966b Remove deprecated code in observation context
-  The commit removes deprecated methods and parameters, including
-  requestOptions in image observation context and proxyToolCalls in Vertex AI
-  Gemini options. Updates code to use ImagePrompt.getOptions() instead of
-  the separate parameter for more consistent API design.
2025-04-28 13:21:51 -04:00
Ilayaperumal Gopinathan
f0702c343b Remove deprecated FunctionCallback references
- Remove the deprecated FunctionCallback related classes, references
 - Replace them with the corresponding ToolCallback usage

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-28 12:19:52 -04:00
Alexandros Pappas
dc5922fe9a feat: Add equals, hashCode, deep copy, and tests to OCICohereChatOptions (#2361)
This commit enhances OCICohereChatOptions by:

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

Signed-off-by: Alexandros Pappas <apappascs@gmail.com>
2025-04-28 17:03:53 +01:00
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