|
|
@@ -3,6 +3,7 @@ package cn.qinys.platform.mobile.service.impl;
|
|
|
import cn.qinys.platform.base.security.utils.CurrentUtils;
|
|
|
import cn.qinys.platform.entity.wishing.ChatMessage;
|
|
|
import cn.qinys.platform.mobile.mapper.ChatMessageMapper;
|
|
|
+import cn.qinys.platform.mobile.req.ChatReq;
|
|
|
import cn.qinys.platform.mobile.resp.ChatHistoryResp;
|
|
|
import cn.qinys.platform.mobile.service.ChatService;
|
|
|
import cn.qinys.platform.mobile.tool.DateTimeTools;
|
|
|
@@ -11,6 +12,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.ai.chat.client.ChatClient;
|
|
|
+import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
@@ -27,17 +29,16 @@ public class ChatServiceImpl implements ChatService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public String chat(String message, Integer treeId) {
|
|
|
+ public String chat(ChatReq req) {
|
|
|
String userId = getUserId();
|
|
|
-
|
|
|
// 保存用户消息
|
|
|
- saveMessage(userId, treeId, "user", message);
|
|
|
-
|
|
|
+ saveMessage(userId, req.getTreeId(), "user", req.getMessage());
|
|
|
String reply;
|
|
|
try {
|
|
|
reply = chatClient.prompt()
|
|
|
- .user(message)
|
|
|
- .tools(new DateTimeTools(), new WeatherTools(treeId))
|
|
|
+ .user(req.getMessage())
|
|
|
+ .tools(new DateTimeTools(), new WeatherTools(req.getTreeId()))
|
|
|
+ .advisors(a -> a.param("chat_memory_conversation_id", req.getConversationId()))
|
|
|
.call()
|
|
|
.content();
|
|
|
} catch (Exception e) {
|
|
|
@@ -46,7 +47,7 @@ public class ChatServiceImpl implements ChatService {
|
|
|
}
|
|
|
|
|
|
// 保存 AI 回复
|
|
|
- saveMessage(userId, treeId, "ai", reply);
|
|
|
+ saveMessage(userId, req.getTreeId(), "ai", reply);
|
|
|
|
|
|
return reply;
|
|
|
}
|