63 lines
2.2 KiB
Java
63 lines
2.2 KiB
Java
package com.ai.controller;
|
|
|
|
import com.ai.service.Assist;
|
|
import com.ai.service.LangChainService;
|
|
import dev.langchain4j.community.model.dashscope.QwenChatModel;
|
|
import dev.langchain4j.memory.ChatMemory;
|
|
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
|
|
import dev.langchain4j.model.chat.ChatLanguageModel;
|
|
import dev.langchain4j.service.AiServices;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
@RestController
|
|
@RequestMapping("/langchain")
|
|
public class LangChainController {
|
|
|
|
@Autowired
|
|
private LangChainService langChainService;
|
|
|
|
@Autowired
|
|
private Assist assist;
|
|
|
|
/**
|
|
* 处理用户输入并调用 LangChainService 获取响应
|
|
* @param input 用户输入的内容
|
|
* @return 大语言模型生成的响应
|
|
*/
|
|
@GetMapping("/chat")
|
|
public String chat(@RequestParam("input") String input) {
|
|
System.out.println("start chat...");
|
|
return langChainService.getResponse(input);
|
|
}
|
|
|
|
@GetMapping("/high/chat")
|
|
public String highChat(@RequestParam("input") String input) {
|
|
System.out.println("start highlevel chat...");
|
|
return assist.chat(input);
|
|
}
|
|
|
|
// ChatLanguageModel qwenModel = QwenChatModel.builder()
|
|
// .apiKey("sk-2f703a41fff0488e9b6888013d2ee58a")
|
|
// .modelName("deepseek-v3")
|
|
// .build();
|
|
//
|
|
// ChatMemory chatMemory = MessageWindowChatMemory.builder()
|
|
// .maxMessages(10)
|
|
// .build();
|
|
//
|
|
// Assist assist = AiServices.builder(Assist.class)
|
|
// .chatLanguageModel(qwenModel) // the model
|
|
// .chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10)) // memory
|
|
// .build();
|
|
|
|
@GetMapping("/high/memory-chat")
|
|
public String memoryChat(@RequestParam("memoryId") String memoryId, @RequestParam("input") String input) {
|
|
System.out.println("start highlevel memory chat...");
|
|
return assist.memoryChat(memoryId, input);
|
|
}
|
|
}
|