From de0860a5aa0f2bd1d5a6af13ffa2ee7e7ef63e29 Mon Sep 17 00:00:00 2001 From: gaoziman <2942894660@qq.com> Date: Sat, 27 Dec 2025 15:02:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E9=A1=B5=E9=9D=A2):=20=E8=81=8A=E5=A4=A9?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E9=9B=86=E6=88=90=E5=9B=BE=E7=89=87=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 传递 isGeneratingImage 状态到消息气泡 - 传递 generatedImages 数据到消息组件 - 支持历史消息中的生成图片显示 --- src/app/chat/[id]/page.tsx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/app/chat/[id]/page.tsx b/src/app/chat/[id]/page.tsx index 0878c0b..f634e79 100644 --- a/src/app/chat/[id]/page.tsx +++ b/src/app/chat/[id]/page.tsx @@ -112,6 +112,8 @@ export default function ChatPage({ params }: PageProps) { uploadedDocuments: (msg.uploadedDocuments as { name: string; size: number; type: string; content: string }[]) || undefined, // 从数据库加载使用的工具列表 usedTools: (msg.usedTools as string[]) || undefined, + // 从数据库加载 AI 生成的图片(Gemini 等图片生成模型) + generatedImages: (msg.generatedImages as { mimeType: string; data: string; width?: number; height?: number }[]) || undefined, })); setInitialMessages(historyMessages); } @@ -393,12 +395,31 @@ export default function ChatPage({ params }: PageProps) { setLinkPreviewOpen(true); }; + // 判断是否为图片生成模型 + const isImageGenerationModel = (modelId: string): boolean => { + const imageModels = [ + 'gemini-2.0-flash-preview-image-generation', + 'gemini-3-pro-image-preview', + 'imagen-3.0-generate-002', + ]; + return imageModels.some(model => modelId.includes(model)) || + modelId.includes('image-generation') || + modelId.includes('imagen'); + }; + + // 获取模型标签 + const getModelTag = (modelId: string, supportsThinking: boolean): string => { + if (isImageGenerationModel(modelId)) return '图片'; + if (supportsThinking) return 'Thinking'; + return ''; + }; + // 转换模型格式 const modelOptions = models.map((m) => ({ id: m.modelId, name: m.modelId, displayName: m.displayName, - tag: m.supportsThinking ? 'Thinking' : '', + tag: getModelTag(m.modelId, m.supportsThinking), })); const selectedModel = modelOptions.find((m) => m.id === selectedModelId) || modelOptions[0]; @@ -623,6 +644,8 @@ export default function ChatPage({ params }: PageProps) { uploadedDocuments={message.uploadedDocuments} usedTools={message.usedTools} pyodideStatus={message.pyodideStatus} + generatedImages={message.generatedImages} + isGeneratingImage={message.isGeneratingImage} onRegenerate={message.role === 'assistant' && !isStreaming ? handleRegenerate : undefined} onSaveToNote={message.role === 'assistant' && !isStreaming ? handleSaveToNote : undefined} onLinkClick={handleLinkClick}