Skip to content

Commit

Permalink
close anthropic client after it's done streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
abi committed Mar 19, 2024
1 parent 212aa22 commit b57f34d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions backend/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b57f34d

Please sign in to comment.