From 3860634fd21d85b4fe08d41d507833250c97f41a Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Sat, 12 Apr 2025 19:15:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=A4=9A?= =?UTF-8?q?=E6=A8=A1=E6=80=81=E8=BE=93=E5=87=BA=E6=94=AF=E6=8C=81=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E9=97=AE=E9=A2=98=E5=B9=B6=E5=AF=B9=E5=8F=AA=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E5=9B=BE=E7=89=87=E7=9A=84=E6=83=85=E5=86=B5=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E5=A4=84=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/provider/sources/gemini_source.py | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/astrbot/core/provider/sources/gemini_source.py b/astrbot/core/provider/sources/gemini_source.py index a6de908ce..cc026bb0b 100644 --- a/astrbot/core/provider/sources/gemini_source.py +++ b/astrbot/core/provider/sources/gemini_source.py @@ -240,6 +240,13 @@ class ProviderGoogleGenAI(Provider): chain = [] part: types.Part + + # 暂时这样Fallback + if all( + part.inline_data and part.inline_data.mime_type.startswith("image/") + for part in result_parts + ): + chain.append(Comp.Plain("这是图片")) for part in result_parts: if part.text: chain.append(Comp.Plain(part.text)) @@ -300,7 +307,7 @@ class ProviderGoogleGenAI(Provider): logger.warning(f"{self.get_model()} 不支持函数调用,已自动去除") tools = None elif ( - "Multi-modal output is not supported" + "Multi-modal output is not supported" in e.message or "Model does not support the requested response modalities" in e.message ): @@ -358,9 +365,21 @@ class ProviderGoogleGenAI(Provider): if chunk.candidates[0].content.parts and any( part.function_call for part in chunk.candidates[0].content.parts ): - response = LLMResponse("assistant", is_chunk=False) - response.result_chain = self._process_content_parts(chunk, response) - yield response + llm_response = LLMResponse("assistant", is_chunk=False) + llm_response.result_chain = self._process_content_parts( + chunk, llm_response + ) + yield llm_response + break + + if chunk.candidates[0].content.parts and any( + part.inline_data for part in chunk.candidates[0].content.parts + ): + llm_response = LLMResponse("assistant", is_chunk=False) + llm_response.result_chain = self._process_content_parts( + chunk, llm_response + ) + yield llm_response break if chunk.text: