优化调整
This commit is contained in:
@@ -24,6 +24,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
@@ -34,6 +36,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* AI聊天服务实现类
|
||||
@@ -1017,12 +1020,12 @@ public class AiChatServiceImpl implements AiChatService {
|
||||
String chatHistory = integrateChatHistory(todayMessages);
|
||||
log.info("聊天记录整合完成,总长度: {}", chatHistory.length());
|
||||
|
||||
// 构建情绪分析提示词
|
||||
String emotionPrompt = buildEmotionAnalysisPrompt(chatHistory);
|
||||
// Coze 中已经在工作流设置了提示词,目前不需要构建情绪分析提示词
|
||||
// String emotionPrompt = buildEmotionAnalysisPrompt(chatHistory);
|
||||
|
||||
// 调用Coze API进行情绪分析总结
|
||||
String conversationId = "emotion_summary_" + userId + "_" + today.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||
String emotionSummary = sendSummaryMessage(conversationId, emotionPrompt, userId);
|
||||
String emotionSummary = sendSummaryMessage(conversationId, chatHistory, userId);
|
||||
log.info("情绪分析总结生成完成: {}", emotionSummary);
|
||||
|
||||
// 解析AI返回的情绪分析结果
|
||||
@@ -1049,6 +1052,13 @@ public class AiChatServiceImpl implements AiChatService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("taskExecutor")
|
||||
public CompletableFuture<Map<String, Object>> generateEmotionSummaryAsync(String userId) {
|
||||
Map<String, Object> result = generateEmotionSummary(userId);
|
||||
return CompletableFuture.completedFuture(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 整合聊天记录
|
||||
*/
|
||||
@@ -1106,7 +1116,7 @@ public class AiChatServiceImpl implements AiChatService {
|
||||
return EmotionAnalysis.builder()
|
||||
.primaryEmotion(json.getString("primaryEmotion"))
|
||||
.intensity(BigDecimal.valueOf(json.getDoubleValue("intensity")))
|
||||
.keywords(json.getString("triggers"))
|
||||
.keywords(JSON.toJSONString(Arrays.asList(json.getString("triggers"))))
|
||||
.suggestion(json.getString("suggestions"))
|
||||
.text(summary)
|
||||
.polarity(determinePolarity(json.getString("primaryEmotion")))
|
||||
@@ -1122,7 +1132,7 @@ public class AiChatServiceImpl implements AiChatService {
|
||||
return EmotionAnalysis.builder()
|
||||
.primaryEmotion("平静")
|
||||
.intensity(BigDecimal.valueOf(0.5))
|
||||
.keywords("日常对话")
|
||||
.keywords(JSON.toJSONString(Arrays.asList("日常对话")))
|
||||
.suggestion("保持当前的积极状态")
|
||||
.text(summary)
|
||||
.polarity("neutral")
|
||||
@@ -1192,7 +1202,7 @@ public class AiChatServiceImpl implements AiChatService {
|
||||
.triggers(analysisResult.getKeywords())
|
||||
.description(analysisResult.getText())
|
||||
.notes("基于当天聊天记录自动生成的情绪分析")
|
||||
.tags("AI分析,聊天记录,情绪总结")
|
||||
.tags(JSON.toJSONString(Arrays.asList("AI分析", "聊天记录", "情绪总结")))
|
||||
.build();
|
||||
|
||||
emotionRecordService.save(record);
|
||||
|
||||
Reference in New Issue
Block a user