feat<chat>: 添加Redis作为对话记忆的持久化存储
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user