Skip to content

Remove deprecations in ChatClient and Advisors #2993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

ThomasVitale
Copy link
Contributor

  • 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.
  • Remove deprecations in ChatClient and Advisors, and update tests accordingly.

Relates to gh-2655

@ThomasVitale ThomasVitale force-pushed the remove-deprecations-chat-client branch 2 times, most recently from bd1f0d2 to d0d2882 Compare May 5, 2025 17:02
@ThomasVitale ThomasVitale marked this pull request as ready for review May 5, 2025 17:03
public Builder userTextAdvise(String userTextAdvise) {
Assert.hasText(userTextAdvise, "The userTextAdvise must not be empty!");
this.promptTemplate = PromptTemplate.builder().template(userTextAdvise).build();
public Builder protectFromBlocking(boolean protectFromBlocking) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is superseded by the new Scheduler input argument. I kept it for backward compatibility. And I haven't marked it as deprecated since we're trying to avoid that for RC1. But this is a candidate to be eventually removed in future releases.

}

/*
* ==========* OPTIONS * ==========
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure consistency with the implementation of the lower-level APIs, we are now using the same exact merge logic we use in the ChatModel API:

  • ToolCallingChatOptions.mergeToolNames()
  • ToolCallingChatOptions.mergeToolCallbacks()
  • ToolCallingChatOptions.mergeToolContext().

So there shouldn't be any surprise about how the values are merged. We have a consistent behaviour that follows the same rules as Spring Boot:

  • lists are overriden
  • maps are merged

See: https://docs.spring.io/spring-boot/reference/features/external-config.html#features.external-config.typesafe-configuration-properties.merging-complex-types

From a backward compatibility point of view, toolNames and toolCallbacks have the same behaviour as before. Instead, the toolContext was not merged correctly. Now it is.

@ThomasVitale ThomasVitale force-pushed the remove-deprecations-chat-client branch from d0d2882 to 2427377 Compare May 5, 2025 17:12
@@ -87,80 +89,76 @@ public static Builder builder(VectorStore chatMemory) {
}

@Override
public AdvisedResponse aroundCall(AdvisedRequest advisedRequest, CallAroundAdvisorChain chain) {
public ChatClientResponse adviseCall(ChatClientRequest chatClientRequest, CallAdvisorChain callAdvisorChain) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PgVectorStoreWithChatMemoryAdvisorIT now fails with

java.lang.AssertionError: 
Expecting actual:
  UserMessage{content='joke', properties={messageType=USER}, messageType=USER}
to be an instance of:
  org.springframework.ai.chat.messages.SystemMessage
but was instance of:
  org.springframework.ai.chat.messages.UserMessage

Copy link
Member

@markpollack markpollack May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System messages shouldn't be added to the vector store for a similarity search I guess but generally speaking having the system prompt as part of the retrieved conversation is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was some inconsistency in behaviour between the two cases where we try to augment a SystemMessage that doesn't exist and one that does.

I fixed that and also extended the PgVectorStoreWithChatMemoryAdvisorIT to validate both scenarios.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@markpollack
Copy link
Member

Other than the vector store comment above, this can be merged.

@ilayaperumalg can you work with @ThomasVitale tomorrow to get this merged please.

* 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 spring-projectsgh-2655

Signed-off-by: Thomas Vitale <[email protected]>
@ThomasVitale ThomasVitale force-pushed the remove-deprecations-chat-client branch from 2427377 to 1706297 Compare May 6, 2025 05:29
@ThomasVitale
Copy link
Contributor Author

@markpollack good catch! There was some inconsistency in behaviour between the two cases where we try to augment a SystemMessage that doesn't exist and one that does.

I fixed that and also extended the PgVectorStoreWithChatMemoryAdvisorIT to validate both scenarios.

@ilayaperumalg
Copy link
Member

@ThomasVitale Thank you for update. Rebased and merged as 4fe74d8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants