From 8779a5f0b3ea746f2acc93a63156136cde838d8b Mon Sep 17 00:00:00 2001 From: snaily Date: Sun, 16 Mar 2025 23:53:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AF=B9=20image-gen?= =?UTF-8?q?eration=20=E6=A8=A1=E5=9E=8B=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 gemini_chat_service 和 openai_chat_service 中添加对 "-image-generation" 后缀模型的支持 确保 image-generation 模型与 image 模型有相同的处理逻辑 --- app/services/gemini_chat_service.py | 2 +- app/services/openai_chat_service.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/services/gemini_chat_service.py b/app/services/gemini_chat_service.py index 7936249..2cf82c9 100644 --- a/app/services/gemini_chat_service.py +++ b/app/services/gemini_chat_service.py @@ -71,7 +71,7 @@ def _build_payload(model: str, request: GeminiRequest) -> Dict[str, Any]: "systemInstruction": request_dict.get("systemInstruction", "") } - if model.endswith("-image"): + if model.endswith("-image") or model.endswith("-image-generation"): payload.pop("systemInstruction") payload["generationConfig"]["responseModalities"] = ["Text","Image"] return payload diff --git a/app/services/openai_chat_service.py b/app/services/openai_chat_service.py index 10b07fb..f0462a7 100644 --- a/app/services/openai_chat_service.py +++ b/app/services/openai_chat_service.py @@ -35,7 +35,7 @@ def _build_tools( if ( settings.TOOLS_CODE_EXECUTION_ENABLED - and not (model.endswith("-search") or "-thinking" in model or model.endswith("-image")) + and not (model.endswith("-search") or "-thinking" in model or model.endswith("-image") or model.endswith("-image-generation")) and not _has_image_parts(messages) ): tools.append({"code_execution": {}}) @@ -110,7 +110,7 @@ def _build_payload( "tools": _build_tools(request, messages), "safetySettings": _get_safety_settings(request.model), } - if request.model.endswith("-image"): + if request.model.endswith("-image") or request.model.endswith("-image-generation"): payload["generationConfig"]["responseModalities"] = ["Text","Image"] if ( @@ -119,6 +119,7 @@ def _build_payload( and instruction.get("role") == "system" and instruction.get("parts") and not request.model.endswith("-image") + and not request.model.endswith("-image-generation") ): payload["systemInstruction"] = instruction