Skip to content

Commit

Permalink
fixbug: qianfan timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
莘权 马 committed Aug 21, 2024
1 parent ab846f6 commit 5bec4bb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions metagpt/provider/qianfan_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,21 @@ 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

async def acompletion(self, messages: list[dict], timeout: int = USE_CONFIG_TIMEOUT) -> JsonBody:
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:
Expand Down

0 comments on commit 5bec4bb

Please sign in to comment.