Commit Graph

29 Commits

Author SHA1 Message Date
Mark Pollack
84ebaababf remove unused method 2025-05-05 21:08:41 -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
76bee8ceb2 Remove deprecations from 1.0.0-M8
Remove deprecated DocumentCompressor/Ranker/Selector

 - These are replaced by the org.springframework.ai.rag.postretrieval.document.DocumentPostProcessor

Remove deprecated Chatclient/DefaultChatClient methods

In ChatClient:
 - Remove defaultTools and tools as these are replaced by defaultToolCallbacks and defaultToolNames respectively.

In DefaultChatClient:
 - Remove tools method implementation
 - Remove unused DefaultCallPromptResponseSpec and DefaultStreamPromptResponseSpec

Remove deprecated addMessage from Prompt

Remove deprecated isInternalToolExecutionEnabled() from ToolCallingChatOptions

 - This is replaced by getInternalToolExecutionEnabled()

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-05-04 23:54:30 +01:00
Mark Pollack
2cbfb22db6 Polish ChatClientAdvisorTests 2025-05-03 14:26:17 -04:00
Thomas Vitale
90cab219d2 Inner advisor should handle output format instructions
Output format instructions should not be included until the very last advisor runs, otherwise there's a risk of templating failure if more than one advisor tries to render the prompt template. This change guarantees the output format instructions are always included right before calling the chat model, without the risk of previous advisors interfering with it.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-05-01 13:00:53 -04:00
Mark Pollack
c347c6feaf Refactor: Move evaluation, converter, transformer, and util classes
- Move evaluation core classes (Request, Response, Evaluator) to spring-ai-commons.
- Move chat-specific evaluators (FactChecking, Relevancy) to spring-ai-client-chat#evaluation package.
- Move OutputConverter implementations and related classes to spring-ai-model#converter package.
- Move MetadataEnricher transformer classes to spring-ai-model#transformer package.
- Move PromptAssert utility to spring-ai-rag#util package.
- Update relevant pom.xml files and adjust imports in affected classes.
- Document class movements in upgrade-notes.adoc for M8 release.

This refactoring improves module organization and separation of concerns.

Signed-off-by: Mark Pollack <mark.pollack@broadcom.com>
2025-04-30 11:45:06 -04:00
Mark Pollack
aa24a56f9b Add deprecated tools(String...) method for backwards compat on ChatClient 2025-04-30 10:54:44 -04:00
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
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
Miloš Havránek
9e9980707a fix null systemText in PromptChatMemoryAdvisor
Signed-off-by: Miloš Havránek <MilosHavranek@users.noreply.github.com>
2025-04-29 08:02:58 +01:00
Thomas Vitale
faa8778b6a Make ChatClient and Advisor APIs more robust - Part 2
* ChatClient observations now include the full prompt content instead of just the userText and systemText. Furthermore, they include consistent telemetry for the tools passed via the ChatClient and a first-class conversation ID when using memory advisors. Incomplete or unsafe attributes have been deprecated.
* Adopted the new robust Advisor APIs for BaseAdvisor and RetrievalAugmentationAdvisor.
* Improved the prompt augmentation facilities in ChatClientRequest and Prompt for performance and immutability.
* Fixed integration test racing condition.
* Updated the documentation for ChatClient and Observability accordingly.
* Documented changes in upgrade notes.
* Introduced `prompt.augmentUserMessage(String text)` to directly replace the user message content.
* Added `prompt.augmentUserMessage(Function<UserMessage, UserMessage> augmenter)` for more granular updates using the `userMessage.mutate()` pattern, allowing modification of text, media, and metadata.

Relates to gh-2655

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-04-28 17:35:55 -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
Ilayaperumal Gopinathan
4eeeb83d3f Add default ChatOptions to Prompt
- Remove @Nullable on ChatOptions
 - By default, pass the default ChatOptions from the DefaultChatOptionsBuilder

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-28 11:41:31 -04:00
Ilayaperumal Gopinathan
35ed49bf24 Update EvaluationResponse
- Remove deprecation from EvaluationResponse's constructor as it is still being used

Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
2025-04-28 14:20:24 +01:00
Thomas Vitale
25e52b8c94 Fix mutable observation context
The DefaultChatClientObservationConvention is now not removing entries from the observation context, resulting in advisor context entries being removed in the ChatClientRequest.

Fixes gh-2876

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-04-26 22:29:21 -04: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
Thomas Vitale
2bc29dab32 Introduce TemplateRenderer for prompt templating
- Introduce new TemplateRenderer API providing the logic for rendering an input template.
- Update the PromptTemplate API to accept a TemplateRenderer object at construction time.
- Move ST logic to StTemplateRenderer implementation, used by default in PromptTemplate. Additionally, make start and end delimiter character configurable.

Relates to gh-2655

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-04-24 17:17:40 -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
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
Soby Chacko
d9e7ace996 Miscellaneous checkstyle fixes
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-14 09:48:03 +01:00
Soby Chacko
5f1e3ab135 Move AOT runtime hints package and classes from spring-ai-client-chat to spring-ai-model
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-04 12:43:22 -04:00
Ilayaperumal Gopinathan
b4fa31188a Refactoring cleanup
- Update Spring AI BOM with the newly added modules
 - Remove unnecessary dependencies from the modules' POM file
2025-04-04 12:43:22 -04:00
Soby Chacko
d94a3c9f40 Moving LoggingMarkers and ResourceUtils from spring-ai-client-chat to spring-ai-commons
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-04 12:43:22 -04:00
Mark Pollack
72e746db13 Move chat based enrichers to a new package to avoid conflicts with other enrichers in different modules 2025-04-04 12:43:22 -04:00
Mark Pollack
d45ff8e984 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-04 11:44:38 -04:00
Mark Pollack
e3f9b7c16b rename spring-ai-core to spring-ai-client-chat 2025-04-04 11:44:38 -04:00