Merge pull request #3174 from jmandel/fix-claude-streaming

fix: Stream completion responses from anthropic. (Fix #3129)
This commit is contained in:
Krish Dholakia 2024-04-19 15:37:29 -07:00 committed by GitHub
commit dc932ac518
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View file

@ -258,8 +258,9 @@ class AnthropicChatCompletion(BaseLLM):
self.async_handler = AsyncHTTPHandler(
timeout=httpx.Timeout(timeout=600.0, connect=5.0)
)
data["stream"] = True
response = await self.async_handler.post(
api_base, headers=headers, data=json.dumps(data)
api_base, headers=headers, data=json.dumps(data), stream=True
)
if response.status_code != 200:

View file

@ -41,13 +41,16 @@ class AsyncHTTPHandler:
data: Optional[Union[dict, str]] = None, # type: ignore
params: Optional[dict] = None,
headers: Optional[dict] = None,
stream: Optional[bool] = False
):
response = await self.client.post(
req = self.client.build_request(
"POST",
url,
data=data, # type: ignore
params=params,
headers=headers,
headers=headers
)
response = await self.client.send(req, stream=stream)
return response
def __del__(self) -> None: