34 lines
1010 B
Java
34 lines
1010 B
Java
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;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
/**
|
|
* LangChainConfig
|
|
*
|
|
* @author huangge1199
|
|
* @since 2025/7/12 10:32:01
|
|
*/
|
|
@Configuration
|
|
public class LangChainConfig {
|
|
|
|
@Resource
|
|
private ChatModel qwenChatModel;
|
|
|
|
@Bean
|
|
public LangChainService langChainService() {
|
|
ChatMemory chatMemory = MessageWindowChatMemory.withMaxMessages(10);
|
|
return AiServices.builder(LangChainService.class)
|
|
.chatModel(qwenChatModel)
|
|
.chatMemory(chatMemory)
|
|
.chatMemoryProvider(memoryId->MessageWindowChatMemory.withMaxMessages(10))
|
|
.build();
|
|
}
|
|
}
|