Skip to content
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

Encapsulate Advisor Parameters with ChatMemoryAdvisorOptions #2601

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dev-jonghoonpark
Copy link
Contributor

Changes

This PR introduces the ChatMemoryAdvisorOptions class to encapsulate advisor parameters.

Background

Previously, CHAT_MEMORY_CONVERSATION_ID_KEY and CHAT_MEMORY_RETRIEVE_SIZE_KEY had to be referenced directly:

import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY;
import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_RETRIEVE_SIZE_KEY;

// ...

this.chatClient.prompt()
        .user(userMessageContent)
        .advisors(a -> a
                .param(CHAT_MEMORY_CONVERSATION_ID_KEY, chatId)
                .param(CHAT_MEMORY_RETRIEVE_SIZE_KEY, 100))
        .stream().content();

Improvements

By introducing ChatMemoryAdvisorOptions, the code is now more structured:

ChatMemoryAdvisorOptions options = ChatMemoryAdvisorOptions.builder()
        .conversationId(chatId)
        .retrieveSize(100)
        .build();

return this.chatClient.prompt()
        .user(userMessageContent)
        .advisors(options::applyTo)
        .stream().content();

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

Successfully merging this pull request may close these issues.

1 participant