| | |
| | | import org.springframework.ai.chat.memory.ChatMemory; |
| | | import org.springframework.ai.chat.model.ChatModel; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.context.annotation.Primary; |
| | |
| | | public class SaaLLMConfig { |
| | | |
| | | /** |
| | | * 创建一个命名的 ChatClient(基于 dashScopeChatModel) |
| | | * 名称为 "dashScopeChatClient" |
| | | * 创建一个默认 ChatClient(基于 Spring AI Alibaba DashScope) |
| | | */ |
| | | //@Primary |
| | | |
| | | @Bean("dashScopeChatClient") |
| | | public ChatClient dashScopeChatClient(@Qualifier("dashScopeChatModel") ChatModel dashScopeChatModel, |
| | | ChatMemory chatMemory) { |
| | | return ChatClient.builder(dashScopeChatModel) |
| | | .defaultAdvisors(MessageChatMemoryAdvisor.builder(chatMemory).build()) |
| | | .defaultAdvisors( |
| | | MessageChatMemoryAdvisor.builder(chatMemory).build(), |
| | | SimpleLoggerAdvisor.builder().build()) |
| | | .build(); |
| | | } |
| | | |
| | | /** |
| | | * 创建一个命名的 ChatClient(基于 dashScopeChatModel) |
| | | * 名称为 "dashScopeChatClient" |
| | | * 本地 Ollama ChatClient,保留为离线或本地模型兜底使用。 |
| | | */ |
| | | @Primary |
| | | @Bean("ollamaChatClient") |