diff --git a/webui/src/App.vue b/webui/src/App.vue index 88d681a..d857a17 100644 --- a/webui/src/App.vue +++ b/webui/src/App.vue @@ -108,6 +108,44 @@ const handleImageChange = async (info) => { } }; +// 解析 Markdown 图片 +const parseMarkdownImages = (content) => { + if (!content) return { text: '', images: [] }; + + const imageRegex = /!\[([^\]]*)\]\(([^)]+)\)/g; + const images = []; + let match; + let lastIndex = 0; + let textParts = []; + + while ((match = imageRegex.exec(content)) !== null) { + // 添加图片之前的文本 + if (match.index > lastIndex) { + textParts.push(content.substring(lastIndex, match.index)); + } + + // 添加图片 + images.push({ + alt: match[1] || '图片', + src: match[2] + }); + + // 不添加占位符,直接跳过图片的 markdown 语法 + + lastIndex = imageRegex.lastIndex; + } + + // 添加剩余文本 + if (lastIndex < content.length) { + textParts.push(content.substring(lastIndex)); + } + + return { + text: textParts.join('').trim(), + images + }; +}; + const testApi = async (type) => { apiTestResults.value[type].status = 'loading'; apiTestResults.value[type].error = null; @@ -196,7 +234,12 @@ const testApi = async (type) => { if (res.ok) { apiTestResults.value[type].status = 'success'; - apiTestResults.value[type].data = data; + // Chat 接口:提取 content + if (type === 'chat' && data.choices?.[0]?.message?.content) { + apiTestResults.value[type].data = { content: data.choices[0].message.content }; + } else { + apiTestResults.value[type].data = data; + } } else { apiTestResults.value[type].status = 'error'; apiTestResults.value[type].error = data.error?.message || `HTTP ${res.status}`; @@ -503,23 +546,45 @@ onMounted(async () => {
{{ chatStreamContent ||
- '等待内容...' }}
+
+ {{
+ parseMarkdownImages(chatStreamContent).text || '等待内容...' }}
+
+ {{
- apiTestResults.chat.data?.content || '' }}
- {{
- JSON.stringify(apiTestResults.chat.data, null, 2) }}
+ style="margin-top: 8px; font-size: 12px; max-height: 400px; overflow-y: auto; background: #fafafa; padding: 8px; border-radius: 4px;">
+
+ {{
+ parseMarkdownImages(apiTestResults.chat.data?.content).text }}
+
+