diff --git a/dashboard/src/views/ConversationPage.vue b/dashboard/src/views/ConversationPage.vue index 3f202fd78..2a615b294 100644 --- a/dashboard/src/views/ConversationPage.vue +++ b/dashboard/src/views/ConversationPage.vue @@ -499,21 +499,23 @@ export default { // 将对话历史转换为 MessageList 组件期望的格式 formattedMessages() { return this.conversationHistory.map(msg => { - console.log('处理消息:', msg.role, msg.image_url, msg.audio_url); + console.log('处理消息:', msg.role, msg.content); + + // 将消息内容转换为 MessagePart[] 格式 + const messageParts = this.convertContentToMessageParts(msg.content); + if (msg.role === 'user') { return { content: { type: 'user', - message: this.extractTextFromContent(msg.content), - image_url: this.extractImagesFromContent(msg.content), + message: messageParts } }; } else { return { content: { type: 'bot', - message: this.extractTextFromContent(msg.content), - embedded_images: this.extractImagesFromContent(msg.content), + message: messageParts } }; } @@ -990,7 +992,61 @@ export default { this.showMessage = true; }, - // 从内容中提取文本 + // 将消息内容转换为 MessagePart[] 格式 + convertContentToMessageParts(content) { + const parts = []; + + if (typeof content === 'string') { + // 纯文本内容 + if (content.trim()) { + parts.push({ + type: 'plain', + text: content + }); + } + } else if (Array.isArray(content)) { + // 数组格式(OpenAI 格式) + content.forEach(item => { + if (item.type === 'text' && item.text) { + parts.push({ + type: 'plain', + text: item.text + }); + } else if (item.type === 'image_url' && item.image_url?.url) { + parts.push({ + type: 'image', + embedded_url: item.image_url.url + }); + } + }); + } else if (typeof content === 'object' && content !== null) { + // 对象格式,尝试提取文本和图片 + const textParts = []; + for (const [key, value] of Object.entries(content)) { + if (typeof value === 'string' && value.trim()) { + textParts.push(value); + } + } + if (textParts.length > 0) { + parts.push({ + type: 'plain', + text: textParts.join('\n') + }); + } + } + + // 如果没有提取到任何内容,添加一个空文本 + if (parts.length === 0) { + parts.push({ + type: 'plain', + text: '' + }); + } + + return parts; + }, + + // 从内容中提取文本(保留用于其他用途) extractTextFromContent(content) { if (typeof content === 'string') { return content; @@ -1004,7 +1060,7 @@ export default { return ''; }, - // 从内容中提取图片URL + // 从内容中提取图片URL(保留用于其他用途) extractImagesFromContent(content) { if (Array.isArray(content)) { return content.filter(item => item.type === 'image_url')