@@ -90,7 +90,7 @@ async def upload_file(
9090 logger .debug (f"[Coze] 图片上传成功,file_id: { file_id } " )
9191 return file_id
9292
93- except asyncio . TimeoutError :
93+ except TimeoutError :
9494 logger .error ("文件上传超时" )
9595 raise Exception ("文件上传超时" )
9696 except Exception as e :
@@ -128,7 +128,7 @@ async def chat_messages(
128128 conversation_id : str | None = None ,
129129 auto_save_history : bool = True ,
130130 stream : bool = True ,
131- timeout : float = 120 ,
131+ timeout_seconds : float = 120 ,
132132 ) -> AsyncGenerator [dict [str , Any ], None ]:
133133 """发送聊天消息并返回流式响应
134134
@@ -139,7 +139,7 @@ async def chat_messages(
139139 conversation_id: 会话ID
140140 auto_save_history: 是否自动保存历史
141141 stream: 是否流式响应
142- timeout : 超时时间
142+ timeout_seconds : 超时时间
143143
144144 """
145145 session = await self ._ensure_session ()
@@ -166,7 +166,7 @@ async def chat_messages(
166166 url ,
167167 json = payload ,
168168 params = params ,
169- timeout = aiohttp .ClientTimeout (total = timeout ),
169+ timeout = aiohttp .ClientTimeout (total = timeout_seconds ),
170170 ) as response :
171171 if response .status == 401 :
172172 raise Exception ("Coze API 认证失败,请检查 API Key 是否正确" )
@@ -203,8 +203,8 @@ async def chat_messages(
203203 except json .JSONDecodeError :
204204 event_data = {"content" : data_str }
205205
206- except asyncio . TimeoutError :
207- raise Exception (f"Coze API 流式请求超时 ({ timeout } 秒)" )
206+ except TimeoutError :
207+ raise Exception (f"Coze API 流式请求超时 ({ timeout_seconds } 秒)" )
208208 except Exception as e :
209209 raise Exception (f"Coze API 流式请求失败: { e !s} " )
210210
@@ -236,7 +236,7 @@ async def clear_context(self, conversation_id: str):
236236 except json .JSONDecodeError :
237237 raise Exception ("Coze API 返回非JSON格式" )
238238
239- except asyncio . TimeoutError :
239+ except TimeoutError :
240240 raise Exception ("Coze API 请求超时" )
241241 except aiohttp .ClientError as e :
242242 raise Exception (f"Coze API 请求失败: { e !s} " )
0 commit comments