From 5afa7f045a6cb054d5467b21574102a6f738c109 Mon Sep 17 00:00:00 2001 From: voidking Date: Fri, 11 Oct 2024 17:47:12 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 - metagpt/provider/general_api_requestor.py | 4 +--- metagpt/provider/ollama_api.py | 20 ++++++++++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6881fec25..a151a1f0f 100644 --- a/README.md +++ b/README.md @@ -185,4 +185,3 @@ ## Citation primaryClass={cs.AI} } ``` - diff --git a/metagpt/provider/general_api_requestor.py b/metagpt/provider/general_api_requestor.py index b65ef0de6..501a064e3 100644 --- a/metagpt/provider/general_api_requestor.py +++ b/metagpt/provider/general_api_requestor.py @@ -82,9 +82,7 @@ class GeneralAPIRequestor(APIRequestor): ) -> Tuple[Union[bytes, AsyncGenerator[bytes, None]], bool]: content_type = result.headers.get("Content-Type", "") if stream and ( - "text/event-stream" in content_type or - "application/x-ndjson" in content_type or - content_type == '' + "text/event-stream" in content_type or "application/x-ndjson" in content_type or content_type == "" ): # the `Content-Type` of ollama stream resp is "application/x-ndjson" return ( diff --git a/metagpt/provider/ollama_api.py b/metagpt/provider/ollama_api.py index 047d6950d..454f0e3ee 100644 --- a/metagpt/provider/ollama_api.py +++ b/metagpt/provider/ollama_api.py @@ -51,9 +51,13 @@ class OllamaLLM(BaseLLM): return json.loads(chunk) async def _achat_completion(self, messages: list[dict], timeout: int = USE_CONFIG_TIMEOUT) -> dict: - headers = None if not self.config.api_key or self.config.api_key == "sk-" else { - "Authorization": f"Bearer {self.config.api_key}", - } + headers = ( + None + if not self.config.api_key or self.config.api_key == "sk-" + else { + "Authorization": f"Bearer {self.config.api_key}", + } + ) resp, _, _ = await self.client.arequest( method=self.http_method, url=self.suffix_url, @@ -70,9 +74,13 @@ class OllamaLLM(BaseLLM): 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: - headers = None if not self.config.api_key or self.config.api_key == "sk-" else { - "Authorization": f"Bearer {self.config.api_key}", - } + headers = ( + None + if not self.config.api_key or self.config.api_key == "sk-" + else { + "Authorization": f"Bearer {self.config.api_key}", + } + ) stream_resp, _, _ = await self.client.arequest( method=self.http_method, url=self.suffix_url,