Commit Graph

37 Commits

Author SHA1 Message Date
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
Christian Tzolov
b22a577ebc Add message history ITs for few chat models 2024-09-10 12:08:57 +02:00
Christian Tzolov
99a4fec214 Remove the reactive advisor observability support
-  Add Anthropic WebClient.Builder autoconfiguration to activate the OOTB WebClient obsercabilty support.
2024-08-23 09:57:49 -04:00
Thomas Vitale
3b7522b6c0 Model observability for Anthropic
Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-20 01:13:43 -04:00
Johnny Lim
2d6117b796 Fix typos (#1223) 2024-08-15 10:27:12 -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
kamosama
7c800f35b8 Fix a FunctionCallback inside a container that pollutes the global model's ChatOptions
The autoconfiguration adds the FunctionCallbacks directly to the model's ChatOptions,
 which results in the FunctionCallback being included in the request each time it is called.

 The modification registers the container's FunctionCallback directly to the model's functionCallbackRegister
 using the parent AbstractToolCallSupport constsructor.

 Replace the handleFunctionCallbackConfigurations by simplified runtimeFunctionCallbackConfigurations.

Co-authored-by Christian Tzolov <ctzolov@vmware.com>
2024-07-30 20:11:14 +02:00
Christian Tzolov
1c0c77b4eb Remove a redundant code line 2024-07-27 23:42:00 +02:00
Christian Tzolov
6363352b82 Improve Anthropic function calling
- factor out the common funciton calling logic form AnthropicChatModel to the AbstractToolCallSupport.
 - improve the AbstractToolCallSupport isToolCall to handle OpenAi and Anthropic.
 - fix an issue with the function calling streaming aggreagation leading to lost usage statistics.
 - small code improvements for OpenAiChatModel.
2024-07-25 18:13:26 +02:00
GR
5642521e74 fix: AbstractToolCallSupport wrong method name 2024-07-25 09:22:13 +02:00
Mark Pollack
5aafea872d Improve Message object hierarchy
- SystemMessage no longer has Media
- Add MediaContent interface
- Clear redundant code
2024-07-19 23:05:46 +02:00
Christian Tzolov
5dc9480eea Anthropic: make the beta features header value configurable
- add new spring.ai.anthropic.beta-version property.
  - add ITs.

  Resolves #1068
2024-07-18 20:54:28 +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
40d8671f3e Improve new function calling strategy
- Streamline the Generation constructors

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-07-18 14:18:45 +02:00
Mark Pollack
97f443d615 Update to ResponseMetadata design
* Remove inheritance from HashMap
* No more subclasses per model provider
* Builder class for ChatResponse
* Fix the AbstractResponseMetadata#AI_METADATA_STRING parameter order
* ChatResponseMetadata ignore Null values.
2024-07-18 12:48:28 +02:00
Sinsy
c9a3e66f90 fix: test name error (#1035)
* fix: test name error

* fix: test name error
2024-07-17 11:07:30 +02:00
Christian Tzolov
ee19ee1db9 Add high-level function calling support for Anthropic
- simplify and unify the AbstractToolCallSupport::executeFuncitons. Fix filed typos
 - remove old classes
2024-07-15 13:57:38 +02: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
Christian Tzolov
d8be884cb1 Improve Anthropic Claude streaming handling
- add StreamEven API domain model for reliably parsing stream events.
 - add StreamHelper#mergeToolUseEvents to aggregate partial tool use jsons into a list of ContentBlocks.
 - add StreamHelper#eventToChatCompletionResponse to convert Flux<StreamEvents> into Flux<ChatCompletionResponse>.
 - Rename MediaContent -> ContentBlock, RequestMessage -> AnthropicMessage, ChatCompletion -> ChatCompletionResponse.
 - Improve tests and docs.
2024-07-02 23:36:25 +02:00
Mariusz Bernacki
f5b72242c0 Add Anthropic Claude streaming Function Calling support
Resolves #930
2024-07-02 10:28:31 +02:00
Thomas Vitale
3227311314 Introduce id and model in ChatResponseMetadata
* Extend ChatResponseMetadata for Anthropic (blocking, streaming)
* Add ChatResponseMetadata for Mistral AI (blocking)
* Extend ChatResponseMetadata for OpenAI (blocking)
* Deprecate gpt-4-vision-preview and replace its usage in tests because OpenAI rejects the calls (see: https://platform.openai.com/docs/deprecations)

Fixes gh-936

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-06-24 14:10:19 +02:00
Mariusz Bernacki
b822107586 Fix Anthropic token usage handling in streaming 2024-06-22 20:15:34 +02:00
Christian Tzolov
ae76407f13 Add support for Anthropic Claude 3.5 Sonnet
- add support for the Anthropic API
 - add support for the Bedrok Anthropic API

 Related to #914
2024-06-21 19:14:19 +02:00
Christian Tzolov
dfa3ceb1ab GH-912: Add customizable logger advisor (#913)
* Add customizable logger advisor
* Address review comments
* Use the OutputCaptureExtension to verify the output text

 Resolves #912
2024-06-21 10:26:18 -04:00
luocq3
75d68662ae Change the Prompt's modelOptions() to return ChatOptions instead of ModelOptions. 2024-06-20 15:03:15 +02:00
Mark Pollack
574138a26a Remove chat.service package and related classes
* This functionality is now provided using the advisors feature in ChatClient
2024-05-27 15:36:30 -04:00
Mark Pollack
4a2ad60059 Package refactoring
* Move ChatClient and related classes into the chat.client package
* Move ChatModel and related class into the chat.model package
* Smaller refactorings to remove DSM cycles
* Update README.md
2024-05-23 17:52:27 -04:00
Josh Long
fbfc87e814 Refactoring of ChatClient to add fluent API and introduce Model as dependent object
* Rename the ModelClient class hierarchy into Model:
  - Rename ModelClient into Model. Update all code and doc references.
  - Rename ChatClient to ChatModel. Update all ChatClient suffixes and chatClient fields and variables in code and doc.
  - Rename EmbeddingClient into EmbeddingModel. Update the XxxEmbeddingClient class and variable suffixes and embeddingClient variables and fields in code and docs.
  - Rename ImageClient into ImageModel.
  - Rename SpeechClient into SpeechModel.
  - Rename TranscriptionClient into TranscriptionModel.
  - Update all javadocs and antora pages. Update the related diagrams.

* Create fluent API in ChatClient interface that now includes streaming support
* Add OpenAI FunctionCallbackWrapper2IT auto-config tests.
* Add ChatClientTest mockito testing.
* Add ChatModel#getDefaultOptions(), and remove @FunctionalInterface

* ChatModel enums extend the new ModelDescription interface.
* Implement fromOptions copy method in every ChatOptions implementation.
* Extend ChatClient to use the model default options if not provided explicitly.

* Update readme to provide guidance on how to adapt to breaking changes.

Co-authored-by: Christian Tzolov <ctzolov@vmware.com>
Co-authored-by: Mark Pollack <mpollack@vmware.com>
2024-05-22 16:07:12 -04:00
Mark Pollack
fd9c98661d API refactoring
* Added more natural method names to DocumentReader, Transformer, Writer
* Changed Content getMedia to return Collection, deprecated use of List
* Change constructor for Media to accept URL and Resource, deprecate Object constructor
* Update ETL documentation and a few tests to avoid now deprecated APIs.
2024-05-16 12:53:13 +02:00
Lorenzo Caenazzo
a7eb28ac17 Add real Function Calling Streaming support
- Add Java reflection merge utilities that can access  Azure private constructors and fields.
 - Azure merging, creation of flux windows.
 - Function call grouping for function processing.
 - Do not perform greedy operation on Flux.
 - Use "real" streaming on all client on function response.
 - Gerimi: fix missing method impl.
 - Mistral AI, OpenAI: fix missing stream flag in doCreateToolResponseRequest.
 - Fix code formatting. No wildcard imports.
 - Add Grogdunn to the javadoc authors.
 - Anthropic 3 API does not support streaming funciton calling yet.
2024-05-15 09:43:36 +02:00
Christian Tzolov
a49a2d213f Replace the OutputParser by a StructuredOutputConverter API
- Old OutputParser, BeanOutputParser, ListOutputParser and MapOutputParser classes are depredated
   in favour of the new StructuredOutputConverter, BeanOutputConverter, ListOutputConverter and
   MapOutputConverter implementations.
   Later are drop-in replacements for the former ones, and provide the same functionality.
 - Keep the existing parser package and classes for backward compatibility.
 - Adjust the PromptTemplate for backward compatibility
 - Update all existing tests to use the new Structured Output API.
 - Improve the documentation for structured outputs.
2024-05-08 12:02:24 -04:00
Christian Tzolov
670bf8e259 Adhere to Spring Framework code sytle
- Wildcard imports such as import java.util.* or import static org.assertj.core.api.Assertions.* are forbidden, even in test code.
   https://github.com/spring-projects/spring-framework/wiki/Code-Style#import-statements
2024-05-04 20:32:37 +03:00
Christian Tzolov
f249e64651 Add Function Calling Support for Anthropic Features
- expanded the AnthropicApi to include Tool, facilitating request and response abstractions.
 - extended AnthropicChatClient to inherit AbstractFunctionCallSupport, with
   implementation of all necessary methods and function registration protocols.
 - implemented FunctionCallingOptions interface in AnthropicChatOptions.
 - added tools integration tests for AnthropoicApi and AnthropicChatClient.
 - extended the auto-configuration with functional calling functionality.
 - added ITs for tools auto-config.
 - updated documentation on anthropic function calling and relevant pages for comprehensive coverage.
2024-04-07 22:10:35 -04:00
Christian Tzolov
c66ed36073 Allow Retry on choosen status codes
- Add a new autoconfig property spring.ai.retry.on-http-codes that list status codes (scuh as 429)
   for which the retry should be attemptd.
 - Updated the docs.

 Resolves #433
2024-03-24 15:05:31 +01:00
Christian Tzolov
09fb5743d2 Experimental Function Calling tests for AnthropicApi low-level API 2024-03-22 14:34:37 +01:00
Christian Tzolov
834d2d0487 Add Multi-Modality Support for OpenAI
- Implemented a MediaContent abstraction within the OpenAiApi to handle text and image inputs.
 - Response message content remains a plain String, ensuring backward compatibility.
 - Extended the OpenAiChatClient request creation process to seamlessly map Spring AI Messages with
   Media content to the low-level OpenAiApi MediaContent types.
 - Added integration tests for embedded and URL images, covering both synchronous and streaming calls.
 - Updated the OpenAI class diagram to reflect the new media content types provided by the OpenAI API.
 - Incorporated a chapter on multi-modality within the openai-chat.adoc documentation.
 - Improve the openai multimoality doc
2024-03-21 17:23:49 -04:00
Christian Tzolov
ce2bb131e5 Implement Anthropic Claude3 Message API client support (direct)
This commit introduces support for the Anthropic Claude3 Message API
  (https://api.anthropic.com), enabling direct interaction with its services.
  This is not a Bedrock Anthropic Claude3 implemenation.

  Changes include:

  - Implementation of a low-level client, AnthropicApi, to interact with
    the message API endpoints specified in the Anthropic documentation
    (https://docs.anthropic.com/claude/reference/messages_post), including support for streaming.
  - Addition of AnthropicApi tests to ensure functionality and reliability.
  - Support for multimodal requests within AnthropicApi.
  - Adding the spring-ai-anthropic and boot starter into BOM and parent POM modules for streamlined usage.
  - Add Anthropic Auto-configuration and Boot Starter for seamless integration into existing projects.
  - Implementation of AnthropicChatClient with capabilities for synchronous and streaming communication,
    including support for multimodal messages.
  - Inclusion of both unit and integration tests to validate functionality across various scenarios.
  - Add Antora documentation with comprehensive guidance on using AnthropicApi and AnthropicChatClient.
  - Add of Ahead-of-Time (AOT) hints for AnthropicApi.
  - update anthropic diagram
2024-03-19 00:36:29 -04:00