会话记忆

This commit is contained in:
huangge1199 2025-07-12 10:51:11 +08:00
parent 8536e6932e
commit 92c0344365

View File

@ -1,6 +1,8 @@
package com.huangge1199.ai.config;
import com.huangge1199.ai.service.LangChainService;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.service.AiServices;
import jakarta.annotation.Resource;
@ -21,6 +23,10 @@ public class LangChainConfig {
@Bean
public LangChainService langChainService() {
return AiServices.create(LangChainService.class, qwenChatModel);
ChatMemory chatMemory = MessageWindowChatMemory.withMaxMessages(10);
return AiServices.builder(LangChainService.class)
.chatModel(qwenChatModel)
.chatMemory(chatMemory)
.build();
}
}