86 lines
2.0 KiB
Java
86 lines
2.0 KiB
Java
package com.rj.controller;
|
|
|
|
import com.rj.aiservice.CstAIService;
|
|
import com.rj.aiservice.CstAIStreamingService;
|
|
import dev.langchain4j.model.openai.OpenAiChatModel;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import reactor.core.publisher.Flux;
|
|
|
|
/**
|
|
* Author: 李中华 wx: spllzh email(qq): 28668817@qq.com
|
|
* Date: 2025/8/4 10:04
|
|
**/
|
|
@RestController
|
|
public class ChatController
|
|
{
|
|
@Autowired
|
|
private OpenAiChatModel model;
|
|
|
|
@Autowired
|
|
CstAIStreamingService streamingModel;
|
|
|
|
@GetMapping("/chat")
|
|
public String chat(String question)
|
|
{
|
|
String chat = model.chat(question);
|
|
return chat;
|
|
}
|
|
|
|
|
|
|
|
@Autowired
|
|
private CstAIService cstService;
|
|
|
|
@GetMapping("/chatByInterface" )
|
|
public String chatByInterface(String question)
|
|
{
|
|
String chat = cstService.chat(question);
|
|
|
|
return chat;
|
|
}
|
|
|
|
|
|
@GetMapping("/chatByStreaming" )
|
|
public Flux<String> chatByStreaming(String question)
|
|
{
|
|
Flux<String> chat = streamingModel.chat(question);
|
|
|
|
return chat;
|
|
}
|
|
|
|
/**
|
|
* 通过 memoryId ,实现会话隔离
|
|
* @param memoryId
|
|
* @param question
|
|
* @return
|
|
*/
|
|
@GetMapping("/chatByStreamingByMemoryId" )
|
|
public Flux<String> chatByStreamingByMemoryId(String memoryId,String question)
|
|
{
|
|
Flux<String> chat = streamingModel.chatMemoryId(memoryId,question);
|
|
|
|
return chat;
|
|
}
|
|
|
|
|
|
/**
|
|
* 通过 memoryId ,实现会话隔离
|
|
* 会话信息保存在Redis中
|
|
* 加载的本地文档保存在向量数据库
|
|
* 基于向量数据库进行信息检索
|
|
*
|
|
* @param memoryId
|
|
* @param question
|
|
* @return
|
|
*/
|
|
@GetMapping("/chatByStreamingByMemoryIdByRAG" )
|
|
public Flux<String> chatByStreamingByMemoryIdByRAG(String memoryId,String question)
|
|
{
|
|
Flux<String> chat = streamingModel.chatMemoryIdRAG(memoryId,question);
|
|
|
|
return chat;
|
|
}
|
|
}
|