Commit Graph

55 Commits

Author SHA1 Message Date
Mark Pollack
67a8896422 Next development version 2024-11-20 18:03:30 -05:00
Mark Pollack
33c05c399c Release version 1.0.0-M4 2024-11-20 18:02:47 -05:00
Ilayaperumal Gopinathan
3812d2e6d8 Remove explicit ChatOptions for the models using FunctionCallingOptions
- Since FunctionCallingOptions already extends ChatOptions,
   removing explicit usage of ChatOptions in the Model Options classes
2024-11-19 18:02:54 -05:00
Christian Tzolov
0ca91b2ed9 fix: Resolve various javadoc and checkstyle issues 2024-11-16 11:06:14 +01:00
Christian Tzolov
fb0d99dc37 Revamp function callback builder API
Introduces a simplified, type-safe builder pattern for function callbacks to
improve developer experience and code reliability. The new hierarchical API
separates concerns between direct function invocation and method reflection,
while providing better compile-time safety.

This change deprecates the older FunctionCallbackWrapper in favor of a more
intuitive FunctionCallback.Builder that better handles generic types via
ParameterizedTypeReference. It also adds automatic function description
generation as a fallback when none is provided, though explicit descriptions
are still recommended.

The update standardizes function callback handling across all AI model
implementations (OpenAI, Ollama, Minimax, etc.) and improves response
handling with configurable converters.

Core API Enhancements:

- New Builder Interface: Replaced FunctionCallbackWrapper.builder() with
   FunctionCallback.builder(), introducing a hierarchical approach that improves
   customization and type safety.
- Specialized Builders: Introduced FunctionInvokerBuilder for direct Function/BiFunction
   implementations and MethodInvokerBuilder for reflection-based invocations.
- Generic Type Support: Added ParameterizedTypeReference for better handling of generic parameters.
- Unified Method Definition: Merged method() and argumentTypes() into a single method() call
   for simplicity and type safety.
- Automatic Descriptions: Implemented auto-generation of function descriptions, with warnings
   to encourage explicit descriptions.
- Configurable Response Converters: Enhanced response handling with support for custom
   converters, reducing unnecessary JSON conversions.

Architecture Improvements:

- Established common Builder interface for shared properties
- Separated function object handling from constructor
- Added method-specific configuration (name, arg types, target)
- Added JSON schema generation support for ResolvableType
- Moved to standardized schema types across AI providers
- Set OPEN_API_SCHEMA as default for Vertex AI Gemini

Builder Pattern Standardization:

- Standardized builder method ordering across implementations
- Moved function() call after description() for consistency
- Improved function callback configuration with unified patterns
- Enhanced error handling and validation in DefaultFunctionCallbackBuilder

Deprecations:

- FunctionCallbackWrapper.Builder replaced by DefaultFunctionCallbackBuilder
- Removed CustomizedTypeReference in favor of ParameterizedTypeReference
- Deprecated older ChatClient API methods for function handling

Testing & Documentation:

- Updated all AI model implementations (OpenAI, Ollama, Minimax, Moonshot, ZhiPuAI)
- Added comprehensive integration tests for static/instance methods
- Added integration tests for auto-generated descriptions
- Updated documentation to reflect new builder pattern usage
- Added Kotlin extension for inputType() support

Co-authored-by: Sébastien Deleuze <sebastien.deleuze@broadcom.com>
2024-11-15 15:32:59 -05:00
Ilayaperumal Gopinathan
72c84fe8b8 Remove deprecated code from 1.0 M2 and before
- Remove deprecated types,methods and references
 - Remove usage of "Generation(String text)" and replace with
  "Generation(AssistantMessage)"
 - Remove MiniMaxApi,MootShotApi,OpenAiApi,ZhiPuAiApi
   ChatCompletionFinishReason's FUNCTION_CALL
 - Remove OllamaApi's deprecated types
 - Remove deprecated constructors from PostgresMlEmbeddingModel
 - Remove deprecated constructor from Media
 - Remove tokenNames usage from antlr4 FiltersLexer and FiltersParser
 - Remove deprecated methods from CassandraVectorStoreProperties
 - Remove deprecated constructor and static config class from QdrantVectorStore
 - Minor cleanups on removing deprecated models and versions
 - Remove old name for mixtral models

Resolves #1599
2024-11-15 14:28:21 -05:00
Mark Pollack
2a6f55a8c5 Use shorter retry intervals in tests
The DEFAULT_RETRY_TEMPLATE uses exponential backoff starting at 2s with max 3min
delay between retries, making tests run unnecessarily long. This change
introduces SHORT_RETRY_TEMPLATE with fixed 100ms backoff to speed up test
execution while preserving the same retry behavior and error handling.
2024-11-06 13:29:37 -05:00
Soby Chacko
66f58d2d70 Change default build setting to disable Checkstyle enforcement
- Disable project-wide Checkstyle checks to unblock development
- Add documentation for enabling Checkstyle locally
- Fix remaining checkstyle violations in current codebase

Fixes #1669
2024-11-05 10:43:38 -05:00
Christian Tzolov
d0312ba426 Add @JsonIgnore annotation to jsonSchema field in AI provider APIs
Add @JsonIgnore annotation to the jsonSchema field in Function classes across
multiple AI provider APIs (MiniMax, MistralAI, OpenAI, ZhiPuAI) to exclude
it from JSON serialization.
2024-11-05 12:56:23 +01:00
Christian Tzolov
fd8cac57bb Revert "Revert "Convert API records to POJOs and fix failing autconfig tests""
This reverts commit 3e9a3fd3b0.
2024-11-05 11:52:41 +01:00
Christian Tzolov
3e9a3fd3b0 Revert "Convert API records to POJOs and fix failing autconfig tests"
This reverts commit 4184af5341.
2024-11-05 10:00:57 +01:00
Soby Chacko
4184af5341 Convert API records to POJOs and fix failing autconfig tests
Following removal of Spring Boot's ConstructorBinding, convert record types
to regular POJOs to maintain JSON serialization. Update API classes:

- Convert FunctionTool and Function records to standard Java classes with
 getters/setters
- Update test assertions to use getter methods instead of record accessors
- Fix failing tests in MiniMax, OpenAi and ZhiPu API implementations

This keeps core API models independent of Spring Boot while ensuring proper
serialization through standard Java beans.

- MistralAIApi FunctionTool ConstructorBinding removal changes
2024-11-02 15:04:06 -04:00
Soby Chacko
e72ab6ba25 Addressing more checkstyle violations
- Enable checkstyle on more modules and adressing violations
review
2024-10-31 01:04:41 -04:00
Soby Chacko
94ddefc73f Remove Spring Boot dependencies from core modules
- Remove @NestedConfigurationProperty and @ConstructorBinding annotations from model options classes
- Remove spring-boot dependency from spring-ai-openai module
- Add exclusion for spring-boot-autoconfigure in spring-cloud-function-context dependency
- Move configuration metadata to spring-ai-spring-boot-autoconfigure module

This change decouples the core AI model implementations from Spring Boot,
making the core modules more lightweight and allowing them to be used in
non-Spring Boot applications. Configuration properties are now handled by
the spring-ai-spring-boot-autoconfigure module instead.

Fixes #1540
2024-10-30 11:58:18 -04:00
Soby Chacko
8e758dbd00 Introduce checkstyle plugin
- Based on https://github.com/spring-io/spring-javaformat
- In this iteration, checkstyles are only enabled for spring-ai-core
2024-10-24 16:43:59 -04:00
Christian Tzolov
278a61fde4 Fix doc ref links 2024-10-21 10:24:28 +02:00
Mark Pollack
d0c53392aa Update spring-javaformat to version 0.0.43
- Ran ./mvnw spring-javaformat:apply that made some new formatting changes
2024-10-16 15:50:04 -04:00
Christian Tzolov
2e0a51fac5 Streamline dependencies and improve API consistency
- Remove unnecessary spring-web dependencies
 - Update third-party library versions
 - Refactor API classes to use consistent header handling
 - Remove ApiUtils class and inline its functionality
 - Adjust RestClient and WebClient builder usage in autoconfiguration
 - Replace direct RestClient.Builder injections with ObjectProvider<RestClient.Builder>
   and WebClient.Builder injections with ObjectProvider<WebClient.Builder>
 - Update ChromaVectorStoreAutoConfiguration to use ObjectProvider
 - Rename MongoDbAtlasLocalContainerConnectionDetailsFactoryTest to IT
 - Switch spring-ai-chroma-store dependency from spring-web to spring-webflux
 - Simplify ChromaApi constructor by using method reference for default headers
 - Adjust import order

 Resolves #1066
 Resolves #524
2024-10-16 15:46:03 -04:00
Mark Pollack
4c83fe8302 Guard against NPE in ZhiPu embedding model
- Update retry test to pass - needs investigation
2024-10-08 23:37:00 +02:00
Mark Pollack
4a892b5269 Release version 1.0.0-M3 2024-10-08 23:18:50 +02:00
GR
73df85d5eb MiniMax embedding model autoconfiguration
- Add context isolation in embedding unit test
2024-10-08 20:47:41 +02:00
GR
ee7d2b2556 Add observability to minimax chat model
- add observability to minimax embedding model
- fix chat web search result error
- fix minimax auto configuration
2024-10-08 00:24:22 +02:00
Christian Tzolov
9c10a08bef Add tool context support to chat options and enhance function calling
This commit adds support for tool context in various chat options classes across
  different AI model implementations and enhances function calling capabilities.

  The tool context allows passing additional contextual information to function callbacks.

 - Add toolContext field to chat options classes
 - Update builder classes to support setting toolContext
 - Enhance FunctionCallback interface to support context-aware function calls
 - Update AbstractFunctionCallback to implement BiFunction instead of Function
 - Modify FunctionCallbackWrapper to support both Function and BiFunction and
   to use the new SchemaType location
 - Add support for BiFunction in TypeResolverHelper
 - Update ChatClient interface and DefaultChatClient implementation to support
   new function calling methods with Function, BiFunction and FunctionCallback arguments
 - Refactor AbstractToolCallSupport to pass tool context to function execution
 - Update all affected <Model>ChatOptions with tool context support
 - Simplify OpenAiChatClientMultipleFunctionCallsIT test
 - Add tests for function calling with tool context
 - Add new test cases for function callbacks with context in various integration tests
 - Modify existing tests to incorporate new context-aware function calling capabilities
 - Add docs in in openai function calling

 Resolves #864, #1303, #991
2024-10-04 16:47:42 -04:00
Christian Tzolov
45c6622736 Fix support for FunctionCallingOptions across AI models
Add support for PortableFunctionCallingOptions across AI models

- Modify FunctionCallingOptions interface to extend ChatOptions for better integration
- Refactor option handling in chat models to accommodate both ChatOptions and FunctionCallingOptions
- Implement handling of FunctionCallingOptions in Anthropic, Azure OpenAI,
  MistralAI, Ollama, OpenAI, VertexAI Gemini, and other models
- Update existing function calling tests to use new FunctionCallingOptions.

Resolves #624
2024-10-04 15:50:59 -04:00
Christian Tzolov
a55316c44d Remove name assertion from ToolResponseMessage validation
- Removed the assertion checking for a non-null 'name' in ToolResponseMessage
 - This change affects multiple AI model implementations:
   AzureOpenAiChatModel, MiniMaxChatModel, MistralAiChatModel,
   MoonshotChatModel, OpenAiChatModel, and ZhiPuAiChatModel

 Resolves #1410
2024-09-25 18:49:36 +02:00
Christian Tzolov
501774925c Add proxy tool calls option to chat models
This commit introduces a new proxyToolCalls option for various chat
 models in the Spring AI project. When enabled, it allows the client to
 handle function calls externally instead of being processed internally
 by Spring AI.

 The change affects multiple chat model implementations, including:
  AnthropicChatModel
  AzureOpenAiChatModel
  MiniMaxChatModel
  MistralAiChatModel
  MoonshotChatModel
  OllamaChatModel
  OpenAiChatModel
  VertexAiGeminiChatModel
  ZhiPuAiChatModel

 The proxyToolCalls option is added to the respective chat options
 classes and integrated into the AbstractToolCallSupport class for
 consistent handling across different implementations.

 The proxyToolCalls option can be set either programmatically via
 the <ModelName>ChatOptions.builder().withProxyToolCalls() method
 or the spring.ai.<model-name>.chat.options.proxy-tool-calls
 application property.

 Documentation for the new option is also updated in the relevant
 Antora pages.

 Added ITs for proxy tool calls

 Remove ChatClientPromptRequestSpec and all ChatClient.prompt() overloads can how take advantage of the full fluent API.  Docs updated

 Resolves #1367
2024-09-23 16:22:58 -04:00
Mark Pollack
8bfb25da86 Fix streaming function call for MiniMax chat model
Sometimes, the MiniMax stream mode function calls might get split,
resulting in an empty tool call ID. This indicates that the previous
call is not finished, which is an unusual API design.

The issue occurs when tool calls return in a format like:
[{"id":"1","function":{"name":"a"}},{"id":"","function":{"arguments":"[1]"}}]

These need to be merged into:
[{"id":"1","name":"a","arguments":"[1]"}]

This commit addresses the merging process to handle split function calls.

authored-by: mxsl-gr <mxsl-gr@users.noreply.github.com>
2024-09-17 14:56:23 -04:00
Thomas Vitale
4b123a7516 Use Double instead of Float for portable ChatOptions
This change updates the type of portable chat options from Float to
Double. Affected options include:
- frequencyPenalty
- presencePenalty
- temperature
- topP

The motivation for this change is to simplify coding. In Java, Float
values require an "f" suffix (e.g., 0.5f), while Double values don't
need any suffix. This makes Double easier to type and reduces
potential errors from forgetting the "f" suffix.

APIs, tests, and documentation have been updated to reflect this
change.

Fixes gh-712

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-09-16 15:35:51 -04:00
GR
b38cbe6386 Enhance MiniMax chat model compatibility and add tests
- Add web search mode response in choice.message for enhanced
compatibility
- Implement web search mode for stream mode
- Add comprehensive unit tests for new features

Related to #1292

feat: enhance the compatibility of the minimax model and tests, related issue #1292
2024-09-09 17:56:04 -04:00
Mark Pollack
e1884d1d92 Next development version 2024-08-23 18:47:37 -04:00
Mark Pollack
43ad2bdb97 Release version 1.0.0-M2 2024-08-23 18:46:58 -04:00
GR
4fac212b0d Add web search capability to MiniMax model
Implement web search functionality for the MiniMax model.
Includes unit tests
This enhancement expands the model's ability to access and utilize current information from the internet.

Resolves #1245
2024-08-23 12:17:45 -04:00
GR
0927bd197d Fix MiniMax model function call implementation
Implement function call capability for MiniMax model and add unit tests based on new tool classes.
Address most scenarios, but note limitations in complex English contexts
with multiple function calls. Weather query example: may stop
prematurely when querying multiple locations due to single-location
parameter limit. This behavior stems from model performance constraints.

Streaming function calling is not passing tests, will be address seperately.

Resolves #1077

Implement function call capability for the Moonshot model. Include unit
tests to verify the new functionality. This feature addresses the
requirements outlined in issue #1058.
fix: MiniMax function call

review
2024-08-23 12:03:33 -04:00
GR
a3c0927c9b Add MiniMax chat option to mask sensitive information
This commit introduces a new boolean option 'maskSensitiveInfo' for
the MiniMax API model support in Spring AI. This feature allows users
to control whether sensitive information in the output is masked.

Relevant unit tests have been added to ensure proper functionality.

Resolves: #1216
2024-08-22 11:23:59 -04:00
Johnny Lim
2d6117b796 Fix typos (#1223) 2024-08-15 10:27:12 -04:00
Christian Tzolov
d538e00643 Replace the Embedding format from List<Double> to float[]
- Adjust all affected classes including the Document.
 - Update docs.

Related to #405
2024-08-13 11:53:08 -04:00
Thomas Vitale
bf84d5945e Streamline ChatOptions
* Surface more configuration APIs to ChatOptions
* Use abstraction in Observations directly instead of dedicated implementation
* Simplify metadata config in observations for defined models
* Improve merging of runtime and default options in OpenAI
* Fix missing option in Mistral AI

Relates to gh-1148

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-10 14:48:05 +02:00
Thomas Vitale
08ccc10a16 Streamline EmbeddingOptions
* Add model and dimensions to option abstraction
* Use abstraction in Observations directly instead of dedicated implementation
* Clean-up the merge of runtime and default embedding options in OpenAI

Relates to #gh-1148

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-08 11:35:08 +02:00
Christian Tzolov
018bb2c600 Ensure that ChatClient copies the input chatoptions
- introduce copy() method to the ChatOptions.
 - make sure that the DefaultChatClientRequestSpec takes a copy of the input chat options to prevent multation.
 - add a OpenAiChatClientMultipleFunctionCallsIT to reproduce the problem and verify the solution.

 Resolves #1064
2024-07-18 18:56:28 +02:00
Thomas Vitale
e601f14364 Add model name and token usage to EmbeddingResponseMetadata
- Moves these from free-text key/value pairs to interface
- Enables programmatic use for evaluation and observability

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-07-12 11:18:49 -04:00
Christian Tzolov
c70c20b79d Add VertexAI Embedding Model support
- add new spring-ai-vertex-ai-embedding project.
 - add VertexAiTextEmbeddingModel and VertexAiMultimodalEmbeddingMode with related options configuration classes.
 - add ITs
 - add auto-configuraiton and boot starters.
 - register to BOM.
 - add documentation.
 - add multimodal embedding documentation
 - extend the Embedding metdata so that it can keep references to the source document's data, Id, mediatype

 Resolves #1013
 Related to #1009
2024-07-10 15:36:13 -04:00
GR
f989dfe06e Update ZhiPuAi model support
- Added additional support for ZhiPuAi models including vision model GLM-4V
- Default model changed to GLM_4_Air and update documentation
- Added additional unit and integration tests
- Add documentation for vision model
2024-06-21 15:52:19 -04:00
GR
172c7f1a1a Add more models and tests for MiniMax AI Model 2024-06-21 15:30:57 -04:00
luocq3
75d68662ae Change the Prompt's modelOptions() to return ChatOptions instead of ModelOptions. 2024-06-20 15:03:15 +02:00
Christian Tzolov
b7475ed060 Update Weaviate docker version. remove import wildcard definitions 2024-06-18 09:33:30 +02:00
Piotr Olaszewski
06ff651734 Remove duplicated ApiUtils and polish javadocs 2024-06-17 15:39:32 +02:00
Christian Tzolov
958549ecce Rename all Embedding Client doc and variables occurrences into Embedding Model 2024-06-16 21:24:03 +02:00
Mark Pollack
ac91302eed Next development version 2024-05-28 13:53:04 -04:00
Mark Pollack
0670575f3e Release version 1.0.0-M1 2024-05-28 13:49:11 -04:00
Christian Tzolov
c49a5c84ff Improve model's POM name consistency 2024-05-24 09:16:39 +02:00