2025年4月15日15:57:37

master
qmstyle 2025-04-15 15:57:42 +08:00
parent a3453ce343
commit 24b89a98e8
1 changed files with 13 additions and 1 deletions

View File

@ -1,7 +1,10 @@
package com.zhangmeng.deepseek.local.chat.controller;
import com.zhangmeng.deepseek.local.chat.repository.ChatHistoryRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@ -20,14 +23,23 @@ import java.util.List;
@RestController
public class ChatController {
@Autowired
private final ChatClient chatClient;
@Autowired
private final ChatHistoryRepository chatHistoryRepository;
@RequestMapping(value = "/chat", produces = "text/html;charset=utf-8")
public Flux<String> chat(
@RequestParam("prompt") String prompt,
@RequestParam("chatId") String chatId,
@RequestParam(value = "files", required = false) List<MultipartFile> files) {
return chatClient.prompt().user(prompt).stream().content();
// 1.保存会话id
chatHistoryRepository.save("chat", chatId);
// 2.发送消息
return chatClient.prompt().user(prompt)
.advisors(a -> a.param(AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY, chatId))
.stream().content();
}
}