From 914922624e81a3a2915c9b999af42a31d0273ab1 Mon Sep 17 00:00:00 2001 From: yinpeng <2291314224@qq.com> Date: Wed, 18 Dec 2024 20:10:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=86=20Gemini=20API=20=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=B8=BA=2060=20=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/chat_service.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/services/chat_service.py b/app/services/chat_service.py index 7fd7b92..8233cda 100644 --- a/app/services/chat_service.py +++ b/app/services/chat_service.py @@ -195,7 +195,7 @@ class ChatService: while retries < MAX_RETRIES: try: - timeout = httpx.Timeout(30.0, read=60.0) # 连接超时30秒,读取超时60秒 + 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: @@ -254,7 +254,7 @@ class ChatService: return generate() else: try: - timeout = httpx.Timeout(60.0, read=60.0) # 连接超时30秒,读取超时60秒 + timeout = httpx.Timeout(60.0, read=60.0) # 连接超时60秒,读取超时60秒 async with httpx.AsyncClient(timeout=timeout) as client: url = f"https://generativelanguage.googleapis.com/v1beta/models/{gemini_model}:generateContent?key={api_key}" response = await client.post(url, json=payload) @@ -290,7 +290,7 @@ class ChatService: """调用Gemini API生成内容""" url = f"{self.base_url}/models/{model_name}:generateContent?key={api_key}" - timeout = httpx.Timeout(30.0, read=60.0) # 连接超时30秒,读取超时60秒 + timeout = httpx.Timeout(60.0, read=60.0) # 连接超时30秒,读取超时60秒 async with httpx.AsyncClient(timeout=timeout) as client: try: response = await client.post(url, json=request.model_dump()) @@ -314,7 +314,7 @@ class ChatService: """调用Gemini API流式生成内容""" url = f"{self.base_url}/models/{model_name}:streamGenerateContent?alt=sse&key={api_key}" - timeout = httpx.Timeout(30.0, read=60.0) # 连接超时30秒,读取超时60秒 + timeout = httpx.Timeout(60.0, read=60.0) # 连接超时60秒,读取超时60秒 async with httpx.AsyncClient(timeout=timeout) as client: try: async with client.stream('POST', url, json=request.model_dump()) as response: