feat: 更新前端多个页面和后端服务
- 前端: 更新AI营养师、计算器、打卡、食物详情等页面 - 前端: 更新食物百科、知识详情、营养知识页面 - 前端: 更新社区首页 - 后端: 更新ToolKieAIServiceImpl服务 - API: 更新models-api.js和user.js
This commit is contained in:
@@ -610,21 +610,24 @@ export default {
|
||||
this.scrollToBottom();
|
||||
},
|
||||
|
||||
/** 从 Gemini 响应 message.content 提取展示文本(支持 string 或 parts 数组) */
|
||||
/** 从 Gemini 响应 data.choices[0].message.content 提取展示文本(支持 string / parts 数组 / { parts } 对象) */
|
||||
extractReplyContent(content) {
|
||||
if (content == null) return '';
|
||||
if (typeof content === 'string') return content;
|
||||
if (Array.isArray(content)) {
|
||||
return content.map(part => (part && part.text) ? part.text : '').filter(Boolean).join('');
|
||||
}
|
||||
if (typeof content === 'object' && Array.isArray(content.parts)) {
|
||||
return content.parts.map(part => (part && part.text) ? part.text : '').filter(Boolean).join('');
|
||||
}
|
||||
return String(content);
|
||||
},
|
||||
|
||||
async sendToAI(content, type) {
|
||||
this.isLoading = true;
|
||||
|
||||
// BUG-005:文本/多模态必须走 KieAI Gemini,回复仅从 data.choices[0].message.content 取,不得使用固定话术
|
||||
// 请求体: { messages: [{ role: 'user', content }], stream: false }
|
||||
// BUG-005:文本/多模态必须走 KieAI Gemini;请求体 { messages: [{ role: 'user', content: 用户输入 }], stream: false }
|
||||
// 回复仅从 data.choices[0].message.content 取,禁止使用 getAIResponse 等固定话术
|
||||
if (type === 'text' || type === 'multimodal') {
|
||||
try {
|
||||
const messages = [{ role: 'user', content: content }];
|
||||
@@ -634,10 +637,10 @@ export default {
|
||||
const data = response.data;
|
||||
const choice = data.choices && data.choices[0];
|
||||
const msgObj = choice && choice.message;
|
||||
const rawContent = msgObj && msgObj.content;
|
||||
const reply = rawContent != null ? this.extractReplyContent(rawContent) : '';
|
||||
// 成功时仅展示模型返回内容
|
||||
this.messageList.push({ role: 'ai', content: reply || '未能获取到有效回复。' });
|
||||
const rawContent = msgObj != null ? msgObj.content : undefined;
|
||||
const reply = rawContent != null && rawContent !== undefined ? this.extractReplyContent(rawContent) : '';
|
||||
// BUG-005: 仅展示接口返回的 data.choices[0].message.content,不使用固定话术
|
||||
this.messageList.push({ role: 'ai', content: reply.trim() || '未能获取到有效回复。' });
|
||||
} else {
|
||||
const msg = (response && response.message) || '发起对话失败';
|
||||
this.messageList.push({ role: 'ai', content: '请求失败:' + msg });
|
||||
|
||||
Reference in New Issue
Block a user