Commit Graph

779 Commits

Author SHA1 Message Date
Andrei Shakirin
0bbccf8ca0 fix: #2146 getting default AWS region using DefaultAwsRegionProviderChain
Signed-off-by: Andrei Shakirin <andrei.shakirin@gmail.com>
2025-05-17 09:11:36 +02:00
Christian Tzolov
5d6bbd9368 refactor: update dependencies to use spring-ai-model and spring-ai-commons
Replace spring-ai-client-chat dependency with spring-ai-model in model implementations
and memory repositories, and with spring-ai-commons in document readers. This change
improves the dependency structure by having components depend on the appropriate
abstraction level.

Additional changes:
- Add slf4j-api dependency to pdf-reader and spring-ai-retry
- Move spring-ai-client-chat to test scope in spring-ai-ollama
- Fix XML formatting in some pom.xml files

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-05-16 19:58:11 +02:00
Jhzlo
8a5f68d655 refactor: remove redundant samples() method
samples() duplicates N(), both setting the same field.
Keeping only N() simplifies the builder API and aligns with ImageOptions.

Signed-off-by: Jhzlo <kjh0010703@naver.com>
2025-05-16 12:57:47 -04:00
Jhzlo
2721c9e676 refactor: simplify stylePreset merge logic in StabilityAiImageOptions builder
Replaces redundant or conflicting stylePreset assignments with a single mergeOption call using runtime style and default stylePreset.

Signed-off-by: Jhzlo <kjh0010703@naver.com>
2025-05-16 12:50:20 -04:00
Mark Pollack
2f5d53fde0 Fix VectorStoreChatMemoryAdvisor streaming bug
- Override adviseStream method in VectorStoreChatMemoryAdvisor to properly handle streaming responses
- Add tests to verify the fix works with both normal and problematic streaming scenarios

Fixes #3152

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-05-16 14:08:20 +01:00
Soby Chacko
368be3a04f Fixing miscellaneous checkstyle errors
Enabling checkstyle by default in the project build

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-05-16 11:08:33 +01:00
Jhzlo
e14e788a47 fix: add @JsonProperty for response_format
Ensures the response_format field is correctly serialized for Stability AI API.

Signed-off-by: Jhzlo <kjh0010703@naver.com>
2025-05-14 12:31:23 -04:00
LingXiao Qi
55ac78046d fix: OpenAiApi comment (#3165)
Signed-off-by: lingxiao <lotus0721@outlook.com>
2025-05-14 14:21:16 +01:00
Ilayaperumal Gopinathan
f2940cffce Next development version 2025-05-13 19:06:16 +01:00
Ilayaperumal Gopinathan
30a9638de8 Release version 1.0.0-RC1 2025-05-13 19:05:52 +01:00
Mark Pollack
f5f02129b5 Fix MessageChatMemoryAdvisor in streaming case.
- The fix overrides the adviseStream method to use ChatClientMessageAggregator to properly aggregate streaming chunks before storing them in memory, similar to how PromptChatMemoryAdvisor handles streaming responses
- Added test

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-05-13 11:31:34 -04:00
Ilayaperumal Gopinathan
c646dfe9a8 Fix BedrockTitanEmbeddingModelIT
- Create ObservationRegistry bean for the tests

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-05-13 07:33:59 +01:00
Mark Pollack
59b36d14da Remove deepseek options form openaiapi
- These options are exclusive to deepseek and can be added to the deepseek model
2025-05-12 23:22:12 -04:00
Mark Pollack
848a3fd31f refactor: Simplify chat memory advisor hierarchy and remove deprecated API
- Remove deprecated ChatMemory.get(String conversationId, int lastN) method

- Replace AbstractChatMemoryAdvisor with BaseChatMemoryAdvisor interface in api package
- Make constructors private in all memory advisor implementations to enforce builder usage
- Rename CHAT_MEMORY_CONVERSATION_ID_KEY to CONVERSATION_ID and move to ChatMemory interface
- In VectorStoreChatMemoryAdvisor:
  - Rename DEFAULT_CHAT_MEMORY_RESPONSE_SIZE (100) to DEFAULT_TOP_K (20)
  - Rename builder method chatMemoryRetrieveSize() to topK()
  - Remove systemTextAdvise() builder method
- In PromptChatMemoryAdvisor:
  - Remove systemTextAdvise() builder method
  - Fix bug where only the last user message was stored from prompts with multiple messages
- Enhance logging in memory advisors to aid in debugging
- Add comprehensive tests for all advisor implementations:
  - Unit tests for builder behavior
  - Integration tests for the various chat memory advisors

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-05-12 19:41:18 -04:00
jonghoon park
0c95cc396f GH-3118: Fix NPE in OpenAIChatModel compatible streaming api with vertex ai gemini
Fixes: #3118

Signed-off-by: jonghoon park <dev@jonghoonpark.com>
2025-05-12 19:20:09 -04:00
Tran Ngoc Nhan
7aa440e6bc Fix typos
Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
2025-05-12 13:31:40 +01:00
lambochen
7739e1e54c OpenAiImageModel support configure imagesPath
Signed-off-by: lambochen <lambochen@yeah.net>
2025-05-12 17:31:49 +08:00
Soby Chacko
15eb24cd91 GH-2168: Fix task type property name in Vertex AI embedding requests
Fixes: #2168

- Change property name from 'taskType' to 'task_type' in VertexAiEmbeddingUtils to match Google API expectations
- Add integration tests to verify task type behavior matches Google SDK
- Add missing auto truncate option copying in VertexAiTextEmbeddingOptions

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-05-10 16:21:09 -04:00
ddobrin
72a2862bce Fixes #3083 Update Google dependencies and model versions
Signed-off-by: ddobrin <ddobrin@google.com>
2025-05-10 16:43:00 +01:00
PSriVarshan
a36c70976c Add observability to Bedrock Titan Embedding model
Signed-off-by: PSriVarshan <psvvarshan@gmail.com>
2025-05-10 16:38:37 +01:00
Christian Tzolov
ad783d9867 Additional tests for the #1878
Add additional integration tests to ensure that the #1878 issue is resolved

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-05-10 16:51:40 +02:00
Christian Tzolov
5f6c618f76 feat: Add support for generic argument types in tool callbacks
- Enhance MethodToolCallback to properly handle generic types by using parameterized types
- Add unit tests for generic type handling (List, Map<String,Integer>, nested generics)
- Add integration tests for both Anthropic and OpenAI clients to verify tool calls with generic argument types

Resolves #2462

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-05-10 09:13:22 -04:00
Barsha Ghosh
9de13d1b2f GH-2342: Remove unused json-path dependency in spring-ai-openai
Signed-off-by: Barsha Ghosh <barshaghosh.721@gmail.com>

Use the proper StringUtils in OpenAiAudioSpeechModel

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-05-09 20:19:10 -04:00
Christian Tzolov
d5bbb131bf feat(bedrock): add tests for tool annotation and supplier-based tool calling
Add integration tests for BedrockNovaChatClient that verify:

- Tool annotation for method without input arguments.
- Supplier-based tool calling implementation.

Related to #1878

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-05-09 19:49:59 +02:00
nlinhvu
f2df87b567 Fix Gemini Tool Calling for texts returned from MethodToolCallback
Signed-off-by: nlinhvu <nlinhvu.dev@gmail.com>
2025-05-09 12:02:02 +02:00
Yanming Zhou
5b2f5eebb5 Add JsonIgnoreProperties to DeepSeek Model Response objects
Continue of commit 53019c69d1

See GH-3026

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
2025-05-09 07:43:50 +01:00
Ilayaperumal Gopinathan
53019c69d1 Add JsonIgnoreProperties to Model Response objects
- For all the model response API objects, add `@JsonIgnoreProperties(ignoreUnknown = true)`
   which provides flexibility to ignore any unknown properties which come as part of the response

Resolves #3026

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-05-08 19:56:13 -04:00
Mark Pollack
9774b4eedc feat: add mutate functionality for OpenAiApi and OpenAiChatModel builders
- Introduced mutate() methods to OpenAiApi and OpenAiChatModel, enabling creation of new builder instances from existing objects.
- Allows safe modification and copying of configuration for APIs and models.
- Refactored internal fields and getters to support mutation/copy patterns.
- Updated integration tests to leverage mutate for dynamic client creation.
2025-05-08 17:46:51 -04:00
Alexandros Pappas
6c9b4d6cd4 feat: OpenAI Web Search Annotations
This PR adds support for retrieving web search annotations from the OpenAI API, as described in their [web search documentation](https://platform.openai.com/docs/guides/web-search).  This allows us to access citation URLs and their context within generated responses when using models like `gpt-4o-search-preview`.

**Changes:**

*   Added `annotations` (with `Annotation` and `UrlCitation` records) to `ChatCompletionMessage` in `OpenAiApi.java`.
*   Updated `OpenAiChatModel` to populate the `annotations` field (via metadata) for both regular and streaming responses.
*   Added integration tests (`webSearchAnnotationsTest`, `streamWebSearchAnnotationsTest`) to `OpenAiChatModelIT.java`.
*   Added `GPT_4_O_SEARCH_PREVIEW` and `GPT_4_O_MINI_SEARCH_PREVIEW` to `OpenAiApi.ChatModel`.
*   Added `WebSearchOptions` and related records to `OpenAiApi`.
*   Minor updates to `ChatCompletionRequest` and its `Builder`.

Resolves #2449

Signed-off-by: Alexandros Pappas <apappascs@gmail.com>
2025-05-08 18:41:47 +01:00
Andres da Silva Santos
fb402a6718 Support reasoning_effort in AzureOpenAiChatOptions
* Adds reasoningEffort field to AzureOpenAiChatOptions builder, copy, equals, hashCode
* Propagates value to ChatCompletionsOptions

Fixes #2703

Signed-off-by: Andres da Silva Santos <40636137+andresssantos@users.noreply.github.com>
2025-05-08 17:45:58 +01:00
Mark Pollack
ebfa5b9b2c refactor: remove inter package dependency cycles in spring-ai-model
Remove circular dependencies:

Move utility classes from various packages to dedicated support packages:
- Move ToolCallbacks from ai.tool to ai.support
- Move UsageUtils to UsageCalculator in ai.support
- Move tool.util to tool.support
- Create new ToolDefinitions utility class

Support packages for the classes in question is more idomatic in spring than util packages.

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-05-08 12:20:27 +01:00
Mikhail Mazurkevich
e6fbc28a5b [anthropic] fix issue #1370 with tool call duplication
Without this fix during the stream event handling when `EventType.MESSAGE_STOP` occurs, the latest content block was resent again and it caused to the additional tool call(if it was the latest event)

[anthropic] Replace `switchMap` -> `flatMap` to avoid cancellation of the original request

Previously, internalStream used switchMap to process ChatCompletionResponses,
which caused the active stream (including potential recursive calls) to be
canceled whenever a new response arrived. This led to incomplete processing
of streaming tool calls and unexpected behavior when handling tool_use events.

Replaced switchMap with flatMap to ensure that each response is fully processed
without being interrupted, allowing recursive internalStream calls to complete
as expected.

Without this fix during the stream event handling when `EventType.MESSAGE_STOP` occurs, the latest content block was resent again and it caused to the additional tool call(if it was the latest event)

Signed-off-by: Mikhail Mazurkevich <Mikhail.Mazurkevich@jetbrains.com>
2025-05-08 10:12:07 +01:00
Mark Pollack
a5920a17fa Add core deepseek classes
Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-05-07 21:27:39 -04:00
Soby Chacko
d781199b48 GH-1378: Add parameter warnings and implement penalty options for Vertex AI Gemini
Fixes: #1378

- Add warnings for unsupported frequency/presence penalty in Anthropic API
- Add warnings for unsupported frequency/presence penalty and topK in BedrockProxyChatModel
- Add warning for unsupported topK in OpenAI chat models
- Implement frequency and presence penalty parameters for Vertex AI Gemini model
- Update Vertex AI Gemini options and tests

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-05-07 17:44:31 -04:00
Mark Pollack
0e15197298 Refactor StTemplateRenderer: rename supportStFunctions to validateStFunctions and improve variable extraction
- Renamed all occurrences of supportStFunctions to validateStFunctions for clarity.
- Updated default field, constructor, and builder method to use new naming.
- Improved getInputVariables logic to better distinguish variables, function calls, and property access.
- Ensured built-in functions accessed as properties are only skipped when validateStFunctions is true.
- Enhanced builder usage to reflect new flag and naming.
- More tests added

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-05-07 17:01:44 -04:00
Dariusz Jędrzejczyk
97f90b19d6 Fix mutating global RestClient and WebClient builders (#3020)
Since the builders for HTTP clients are mutable and shared, they should
only be configured with globally applicable settings. The current use
leaks specific details into other usages and affects newly instantiated
clients. This PR applies the clone() method right before mutation
happens as it probably is the strategy that avoids multiple unnecessary
copies.

feat: improve RestClient and WebClient instantiation and configuration across AI modules

- Ensure RestClient.Builder and WebClient.Builder are properly cloned before setting base URLs and headers in Mistral, OpenAI, and Ollama API classes to prevent side effects.
- Add WebClientAutoConfiguration to auto-configuration classes for Anthropic and Mistral AI modules.
- Update Mistral AI auto-configuration to inject and use WebClient.Builder.
- Clean up test and annotation usage (remove unnecessary @Nullable, fix test builder usage in AnthropicApiIT).
- Improve consistency and reliability of HTTP client configuration across model integrations.

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-05-07 18:15:55 +02:00
Mark Pollack
10ff11da14 Add regression test for MessageChatMemoryAdvisor with Prompt message list (GH-2339)
- Adds an integration test to verify that MessageChatMemoryAdvisor works correctly when a Prompt is initialized with a List<Message>.
- References and confirms the fix for [https://github.com/spring-projects/spring-ai/issues/2339.](https://github.com/spring-projects/spring-ai/issues/2339.)

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-05-06 18:58:06 -04:00
Thomas Vitale
4fe74d886e Remove deprecations in ChatClient and Advisors
* Update remaining Advisors and related classes to use the new APIs.
* In AbstractChatMemoryAdvisor, the “doNextWithProtectFromBlockingBefore()” protected method has been changed from accepting AdvisedRequest to ChatClientRequest. It’s a breaking change since the alternative was not part of M8.
* MessageAggregator has a new method to aggregate messages from ChatClientRequest. The previous method aggregating messages from AdvisedRequest has been removed. Warning since it wasn’t marked as deprecated in M8.
* In SimpleLoggerAdvisor, the “requestToString” input argument needs to be updated to use ChatClientRequest. It’s a breaking change since the alternative was not part of M8. Same thing about the constructor.
* The “getTemplateRenderer” method has been removed from BaseAdvisorChain. Each Advisor is encouraged to accept a PromptTemplate to achieve self-contained prompt augmentation operations.
* Remove deprecations in ChatClient and Advisors, and update tests accordingly.
* When building a Prompt from the ChatClient input, the SystemMessage passed via systemText() is placed first in the message list. Before, it was put last, resulting in errors with several model providers.

Relates to gh-2655

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-05-06 09:58:06 +01:00
Solomon Hsu
271d78142f Add 'capabilities' field to ShowModelResponse in OllamaApi
This update enables deserialization of the 'capabilities' field from the JSON response.

Signed-off-by: Solomon Hsu <solnone@gmail.com>
2025-05-06 01:19:06 -04:00
nlinhvu
39759b02ba Update vertexai-gemini-chat.adoc, VertexAi ChatModels docs and fix typo for spring-ai-vertex-ai-gemini
Signed-off-by: nlinhvu <nlinhvu.dev@gmail.com>
2025-05-06 01:17:32 -04:00
jonghoonpark
9ca3a7d15f Refactor OpenAiImageOptions and enhance test coverage
This commit makes several improvements to the OpenAiImageOptions class:

1. Remove all deprecated methods from OpenAiImageOptions.Builder:
   - Removed withN(), withModel(), withQuality(), withResponseFormat(),
     withWidth(), withHeight(), withStyle(), and withUser() methods
   - These were marked as @Deprecated(forRemoval = true, since = "1.0.0-M8")

2. Align OpenAiImageOptions structure with OpenAiChatOptions:
   - Added fromOptions() static method for creating copies
   - Added copy() instance method
   - Updated Builder class to match pattern in OpenAiChatOptions
   - Changed Builder field from private final to protected
   - Added Builder constructor that takes an existing options object

3. Enhance setSize() method to maintain consistency:
   - Updated setSize() to parse the size string and update width/height properties
   - Added proper error handling for invalid formats
   - Ensures consistent state between size, width, and height properties

4. Comprehensive test coverage improvements:
   - Added tests for builder pattern with all fields
   - Added tests for copy functionality
   - Added tests for all setter methods
   - Added tests for default values
   - Added tests for equals(), hashCode(), and toString() methods
   - Added specific tests for the updated setSize() behavior
   - Fixed test expectations to match actual implementation behavior

These changes improve code consistency, maintainability, and test coverage
while removing deprecated methods that were scheduled for removal.

Signed-off-by: jonghoonpark <dev@jonghoonpark.com>
2025-05-06 01:03:06 -04:00
ndoe
8acf4b99ff GH-2737 Returning logprobs in generation metadata when requested
Signed-off-by: ndoe <ndoe@interactions.com>
2025-05-05 23:34:00 -04:00
Bart Veenstra
3a3439edc4 feat: enhance AzureOpenAiResponseFormat to support JSON schema and builder pattern
Signed-off-by: Bart Veenstra <bart.veenstra@gmail.com>
2025-05-05 21:37:35 -04:00
Ilayaperumal Gopinathan
228ef10bfb Remove deprecated methods from Media
- Remove deprecated constructor method Media(MimeType mimeType, URL url) from Media
 - Remove deprecated builder method data(URL url) from Media builder
 - Update references to use the builder and the data(URI) methods

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-05-05 01:47:45 +01:00
Ilayaperumal Gopinathan
06edee4069 Remove deprecated UserMessage constructors
- Remove deprecated constructor methods
 - Replace them with the builder methods

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-05-05 01:06:21 +01:00
Ilayaperumal Gopinathan
722c77e812 Remove deprecated PromptTemplate constructors
- Remove the deprecated constructors from PromptTemplate and replace the references using the builder methods

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-05-05 00:57:39 +01:00
Ilayaperumal Gopinathan
46be8987d6 Remove deprecations from OllamApi and AnthropicApi
- Remove deprecated constructors from OllamaApi and AnthropicApi
 - Modify AnthropicApi's public constructor to be private so that only the builder method can use it to construct
 - Update OllamApiAutoConfiguration and AnthropicChatAutoconfiguration to use the builder methods to construct the respective
 Apis
 - Fix other constructor usages to builder methods

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-05-05 00:21:34 +01:00
Mark Pollack
9e71b163e3 Remove Waston text generation model 2025-05-03 18:36:02 -04:00
g00glen00b
d5423f26f1 added @JsonIgnore to ResponseFormat.schema to avoid exposing internal properties (#2969)
Signed-off-by: g00glen00b <4865705+g00glen00b@users.noreply.github.com>
2025-05-03 15:56:01 -04:00
Christian Tzolov
78d90cd134 feat(vertex-ai-gemini): enhance jsonToStruct to support JSON arrays
- Improve the jsonToStruct method in VertexAiGeminiChatModel to handle JSON arrays
  in addition to JSON objects. When a JSON array is detected, it's now properly
  converted to a Protobuf Struct with an items field containing the array elements.
- Added test

Resolves #2647 , #2849

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-05-03 15:32:35 -04:00