close anthropic client after it's done streaming

This commit is contained in:
Abi Raja 2024-03-19 12:09:25 -04:00
parent 212aa228ab
commit b57f34d73a

View File

@ -113,6 +113,10 @@ async def stream_claude_response(
# Return final message
response = await stream.get_final_message()
# Close the Anthropic client
await client.close()
return response.content[0].text
@ -177,6 +181,9 @@ async def stream_claude_response_native(
f"Token usage: Input Tokens: {response.usage.input_tokens}, Output Tokens: {response.usage.output_tokens}"
)
# Close the Anthropic client
await client.close()
if not response:
raise Exception("No HTML response found in AI response")
else: