From c8124d5d32e4ccac30c467ba43689c18c07eeb19 Mon Sep 17 00:00:00 2001 From: yinpeng <2291314224@qq.com> Date: Fri, 20 Dec 2024 10:26:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Gemini=20=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E5=B7=A5=E5=85=B7=E5=92=8C=E6=B5=81=E5=BC=8F=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/chat_service.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/services/chat_service.py b/app/services/chat_service.py index 7f22331..2684568 100644 --- a/app/services/chat_service.py +++ b/app/services/chat_service.py @@ -142,7 +142,7 @@ class ChatService: if tools is None: tools = [] - if settings.TOOLS_CODE_EXECUTION_ENABLED and not model.endswith("-search"): + if settings.TOOLS_CODE_EXECUTION_ENABLED and not (model.endswith("-search") or "-thinking" in model): tools.append({"code_execution": {}}) if model.endswith("-search"): tools.append({"googleSearch": {}}) @@ -198,9 +198,10 @@ class ChatService: timeout = httpx.Timeout(60.0, read=60.0) # 连接超时60秒,读取超时60秒 async with httpx.AsyncClient(timeout=timeout) as client: stream_url = f"https://generativelanguage.googleapis.com/v1beta/models/{gemini_model}:streamGenerateContent?alt=sse&key={current_api_key}" - async with client.stream("POST", stream_url, json=payload) as response: + async with client.stream('POST', stream_url, json=payload) as response: if response.status_code != 200: - error_msg = await response.text() + error_content = await response.read() + error_msg = error_content.decode('utf-8') logger.error(f"API error: {response.status_code}, {error_msg}") if retries < MAX_RETRIES - 1: current_api_key = await self.key_manager.handle_api_failure(current_api_key)