From 33067da0978d4159a96d5ac78317b977bf71476f Mon Sep 17 00:00:00 2001 From: Chenyme <118253778+chenyme@users.noreply.github.com> Date: Wed, 4 Feb 2026 23:40:49 +0800 Subject: [PATCH] refactor: merge image attachments into file attachments --- app/services/grok/chat.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/services/grok/chat.py b/app/services/grok/chat.py index e2dda63..919d137 100644 --- a/app/services/grok/chat.py +++ b/app/services/grok/chat.py @@ -215,19 +215,25 @@ class ChatRequestBuilder: mode: 模型模式 think: 是否开启思考 file_attachments: 文件附件 ID 列表 - image_attachments: 图片附件 URL 列表 + image_attachments: 图片附件 ID 列表(合并到 fileAttachments) """ temporary = get_config("grok.temporary", True) if think is None: think = get_config("grok.thinking", False) + merged_attachments: List[str] = [] + if file_attachments: + merged_attachments.extend(file_attachments) + if image_attachments: + merged_attachments.extend(image_attachments) + return { "temporary": temporary, "modelName": model, "modelMode": mode, "message": message, - "fileAttachments": file_attachments or [], - "imageAttachments": image_attachments or [], + "fileAttachments": merged_attachments, + "imageAttachments": [], "disableSearch": False, "enableImageGeneration": True, "returnImageBytes": False, @@ -413,7 +419,6 @@ class GrokChatService: # 处理附件上传 file_ids = [] - image_ids = [] if attachments: upload_service = UploadService() @@ -423,11 +428,9 @@ class GrokChatService: file_id, _ = await upload_service.upload(attach_data, token) if attach_type == "image": - # 图片 imageAttachments - image_ids.append(file_id) + file_ids.append(file_id) logger.debug(f"Image uploaded: {file_id}") else: - # 文件 fileAttachments file_ids.append(file_id) logger.debug(f"File uploaded: {file_id}") finally: @@ -452,7 +455,7 @@ class GrokChatService: think, stream, file_attachments=file_ids, - image_attachments=image_ids, + image_attachments=[], ) return response, stream, request.model