2025-03-02 13:34:44 +00:00
|
|
|
package com.ai.controller;
|
|
|
|
|
2025-03-04 12:09:16 +00:00
|
|
|
import com.ai.service.Assist;
|
2025-03-02 13:34:44 +00:00
|
|
|
import com.ai.service.LangChainService;
|
2025-03-29 14:18:18 +00:00
|
|
|
import dev.langchain4j.community.model.dashscope.QwenChatModel;
|
2025-03-29 15:21:32 +00:00
|
|
|
import dev.langchain4j.community.model.zhipu.ZhipuAiImageModel;
|
|
|
|
import dev.langchain4j.data.image.Image;
|
2025-03-29 14:18:18 +00:00
|
|
|
import dev.langchain4j.memory.ChatMemory;
|
|
|
|
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
|
|
|
|
import dev.langchain4j.model.chat.ChatLanguageModel;
|
2025-03-29 15:21:32 +00:00
|
|
|
import dev.langchain4j.model.output.Response;
|
2025-03-29 14:18:18 +00:00
|
|
|
import dev.langchain4j.service.AiServices;
|
2025-03-02 13:34:44 +00:00
|
|
|
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;
|
|
|
|
|
2025-03-29 15:21:32 +00:00
|
|
|
import java.net.URI;
|
|
|
|
|
2025-03-02 13:34:44 +00:00
|
|
|
@RestController
|
|
|
|
@RequestMapping("/langchain")
|
|
|
|
public class LangChainController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private LangChainService langChainService;
|
|
|
|
|
2025-03-04 12:09:16 +00:00
|
|
|
@Autowired
|
|
|
|
private Assist assist;
|
|
|
|
|
2025-03-29 15:21:32 +00:00
|
|
|
@Autowired
|
|
|
|
private ZhipuAiImageModel zhipuAiImageModel;
|
|
|
|
|
2025-03-02 13:34:44 +00:00
|
|
|
/**
|
|
|
|
* 处理用户输入并调用 LangChainService 获取响应
|
|
|
|
* @param input 用户输入的内容
|
|
|
|
* @return 大语言模型生成的响应
|
|
|
|
*/
|
|
|
|
@GetMapping("/chat")
|
|
|
|
public String chat(@RequestParam("input") String input) {
|
|
|
|
System.out.println("start chat...");
|
|
|
|
return langChainService.getResponse(input);
|
|
|
|
}
|
2025-03-04 12:09:16 +00:00
|
|
|
|
|
|
|
@GetMapping("/high/chat")
|
|
|
|
public String highChat(@RequestParam("input") String input) {
|
|
|
|
System.out.println("start highlevel chat...");
|
|
|
|
return assist.chat(input);
|
|
|
|
}
|
2025-03-29 14:18:18 +00:00
|
|
|
|
|
|
|
@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);
|
|
|
|
}
|
2025-03-29 15:21:32 +00:00
|
|
|
|
|
|
|
@GetMapping("/zhipu/img")
|
2025-03-29 15:46:43 +00:00
|
|
|
public String generateImg( @RequestParam("input") String input) {
|
|
|
|
System.out.println("start generate img...");
|
2025-03-29 15:21:32 +00:00
|
|
|
Response<Image> generate = zhipuAiImageModel.generate(input);
|
|
|
|
URI url = generate.content().url();
|
|
|
|
return "Your remote image is here: " + url;
|
|
|
|
}
|
2025-03-29 15:46:43 +00:00
|
|
|
|
|
|
|
@GetMapping("/high/call")
|
|
|
|
public String functionCall(@RequestParam("input") String input) {
|
|
|
|
System.out.println("start highlevel memory chat...");
|
|
|
|
return assist.chat(input);
|
|
|
|
}
|
2025-03-02 13:34:44 +00:00
|
|
|
}
|