整合体重和饮食指令处理逻辑,优化AI教练服务,支持通过指令解析用户输入。更新系统提示以提供个性化健康建议,并增强饮食图片分析功能。移除冗余的体重识别逻辑,简化代码结构。
This commit is contained in:
@@ -33,39 +33,8 @@ export class AiCoachController {
|
||||
userContent,
|
||||
});
|
||||
|
||||
let weightInfo: { weightKg?: number; systemNotice?: string } = {};
|
||||
|
||||
// 体重识别逻辑优化:
|
||||
// 1. 如果有图片URL,使用原有的图片识别逻辑
|
||||
// 2. 如果没有图片URL,但文本中包含体重信息,使用新的文本识别逻辑
|
||||
try {
|
||||
if (body.imageUrl) {
|
||||
// 原有逻辑:从图片识别体重
|
||||
const imageWeightInfo = await this.aiCoachService.maybeExtractAndUpdateWeight(
|
||||
userId,
|
||||
body.imageUrl,
|
||||
userContent,
|
||||
);
|
||||
if (imageWeightInfo.weightKg) {
|
||||
weightInfo = {
|
||||
weightKg: imageWeightInfo.weightKg,
|
||||
systemNotice: `系统提示:已从图片识别体重为${imageWeightInfo.weightKg}kg,并已为你更新到个人资料。`
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// 新逻辑:从文本识别体重,并获取历史对比信息
|
||||
const textWeightInfo = await this.aiCoachService.processWeightFromText(userId, userContent);
|
||||
if (textWeightInfo.weightKg && textWeightInfo.systemNotice) {
|
||||
weightInfo = {
|
||||
weightKg: textWeightInfo.weightKg,
|
||||
systemNotice: textWeightInfo.systemNotice
|
||||
};
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// 体重识别失败不影响正常对话
|
||||
console.error('体重识别失败:', error);
|
||||
}
|
||||
// 体重和饮食指令处理现在已经集成到 streamChat 方法中
|
||||
// 通过 # 字符开头的指令系统进行统一处理
|
||||
|
||||
if (!stream) {
|
||||
// 非流式:聚合后一次性返回文本
|
||||
@@ -73,14 +42,14 @@ export class AiCoachController {
|
||||
userId,
|
||||
conversationId,
|
||||
userContent,
|
||||
systemNotice: weightInfo.systemNotice,
|
||||
imageUrl: body.imageUrl,
|
||||
});
|
||||
let text = '';
|
||||
for await (const chunk of readable) {
|
||||
text += chunk.toString();
|
||||
}
|
||||
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
||||
res.send({ conversationId, text, weightKg: weightInfo.weightKg });
|
||||
res.send({ conversationId, text });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -93,7 +62,7 @@ export class AiCoachController {
|
||||
userId,
|
||||
conversationId,
|
||||
userContent,
|
||||
systemNotice: weightInfo.systemNotice,
|
||||
imageUrl: body.imageUrl,
|
||||
});
|
||||
|
||||
readable.on('data', (chunk) => {
|
||||
|
||||
Reference in New Issue
Block a user