From 5bec4bbaa0fdc743b7f8e017c170df386ec763cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Wed, 21 Aug 2024 14:07:10 +0800 Subject: [PATCH] fixbug: qianfan timeout --- metagpt/provider/qianfan_api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/metagpt/provider/qianfan_api.py b/metagpt/provider/qianfan_api.py index 04334f305..3ada7908d 100644 --- a/metagpt/provider/qianfan_api.py +++ b/metagpt/provider/qianfan_api.py @@ -106,13 +106,13 @@ def _update_costs(self, usage: dict): def get_choice_text(self, resp: JsonBody) -> str: return resp.get("result", "") - def completion(self, messages: list[dict]) -> JsonBody: - resp = self.aclient.do(**self._const_kwargs(messages=messages, stream=False)) + def completion(self, messages: list[dict], timeout: int = USE_CONFIG_TIMEOUT) -> JsonBody: + resp = self.aclient.do(**self._const_kwargs(messages=messages, stream=False), request_timeout=timeout) self._update_costs(resp.body.get("usage", {})) return resp.body async def _achat_completion(self, messages: list[dict], timeout: int = USE_CONFIG_TIMEOUT) -> JsonBody: - resp = await self.aclient.ado(**self._const_kwargs(messages=messages, stream=False)) + resp = await self.aclient.ado(**self._const_kwargs(messages=messages, stream=False), request_timeout=timeout) self._update_costs(resp.body.get("usage", {})) return resp.body @@ -120,7 +120,7 @@ async def acompletion(self, messages: list[dict], timeout: int = USE_CONFIG_TIME return await self._achat_completion(messages, timeout=self.get_timeout(timeout)) async def _achat_completion_stream(self, messages: list[dict], timeout: int = USE_CONFIG_TIMEOUT) -> str: - resp = await self.aclient.ado(**self._const_kwargs(messages=messages, stream=True)) + resp = await self.aclient.ado(**self._const_kwargs(messages=messages, stream=True), request_timeout=timeout) collected_content = [] usage = {} async for chunk in resp: