feat<chat>: 添加Redis作为对话记忆的持久化存储

This commit is contained in:
2025-10-22 20:06:39 +08:00
parent 86666ff044
commit 2f9923977a
6 changed files with 115 additions and 4 deletions

View File

@@ -1,7 +1,9 @@
package com.hanserwei.snailsai.controller;
import com.hanserwei.snailsai.model.ChatMessageDTO;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
@@ -15,9 +17,10 @@ public class DashScopeController {
private ChatClient dashScopeChatClient;
@PostMapping(value = "/chat",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> chat(@RequestBody String userPrompt) {
public Flux<String> chat(@RequestBody ChatMessageDTO chatMessageDTO) {
return dashScopeChatClient.prompt()
.user(userPrompt)
.user(chatMessageDTO.getMessage())
.advisors(e-> e.param(ChatMemory.CONVERSATION_ID,chatMessageDTO.getConversionId()))
.stream()
.content();
}