Skip to content

Commit

Permalink
Merge pull request #1499 from voidking/main
Browse files Browse the repository at this point in the history
chore: 代码格式化
  • Loading branch information
geekan authored Oct 11, 2024
2 parents 2a23806 + 5afa7f0 commit 4c55a97
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,3 @@ To cite [MetaGPT](https://openreview.net/forum?id=VtmBAGCN7o) or [Data Interpret
primaryClass={cs.AI}
}
```

4 changes: 1 addition & 3 deletions metagpt/provider/general_api_requestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ async def _interpret_async_response(
) -> 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 (
Expand Down
20 changes: 14 additions & 6 deletions metagpt/provider/ollama_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ def _decode_and_load(self, chunk: bytes, encoding: str = "utf-8") -> dict:
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,
Expand All @@ -70,9 +74,13 @@ async def acompletion(self, messages: list[dict], timeout=USE_CONFIG_TIMEOUT) ->
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,
Expand Down

0 comments on commit 4c55a97

Please sign in to comment.