Commit Graph

340 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
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
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
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
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
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
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
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
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
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
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
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
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
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
Christian Tzolov
39be9aeba2 Fix tools test configuration 2025-01-26 07:28:51 +01:00
Mark Pollack
7521cab9db Remove deprecated methods/classes from spring-ai-core 2025-01-24 13:37:14 -05:00
Alexandros Pappas
bb6b8cc20f Refactor OpenAIAudio builder methods
- Refactor the builder methods to remove `with` as the prefix.
- Introduce new methods with updated naming conventions.
- Deprecate the existing `with*` methods to maintain backward compatibility.

Signed-off-by: Alexandros Pappas <alexandros.pappas@yiluhub.com>
2025-01-24 11:47:04 +00:00
dafriz
9d95f0f7c9 Add o1 model to OpenAI ChatModel enum 2025-01-17 16:17:06 +00:00
pir
7e303a06e5 Add additional OpenAI TTS Voice options
- Add OpenAI TTS Voice Unit Test
2025-01-17 13:31:39 +00:00
Alexandros Pappas
7d53ef2056 chore: replace all instances of 'final static' with 'static final' 2025-01-15 15:16:12 +00:00
Ilayaperumal Gopinathan
3c539a37a3 Remove deprecated methods from models 2025-01-06 16:59:33 -05:00
Ilayaperumal Gopinathan
977500f7a1 Remove deprecated classes and methods in spring-ai-core
* Remove use of Document.getContext method from spring-ai-core, use getText
* Remove deprecated ChatOptionsBuilder class
* Remove deprecated FunctionCallingOptionsBuilder class
2025-01-06 16:57:55 -05:00
Ilayaperumal Gopinathan
823766f436 Fix OpenAiChatModelIT#streamingWithTokenUsage
- Modify the streaming vs call usage assertion to match the close to 25% value
   - This change is done because the OpenAI chat response for call and stream invocation results in slight change in usage.
2025-01-02 15:38:18 +00:00
Ilayaperumal Gopinathan
7fe3b389c4 Fix checkstyle errors 2025-01-02 13:43:58 +00:00
Mark Pollack
d7fe07b0f1 Next development version 2024-12-23 14:25:21 -05:00
Mark Pollack
ab022fa956 Release version 1.0.0-M5 2024-12-23 14:24:55 -05:00
Ilayaperumal Gopinathan
1e68862142 Fix SimpleVectorStore' deprecated constructor use
- Use SimpleVectorStoreBuilder for SimpleVectorStore instance creation
2024-12-20 20:29:40 +00:00