From b57f34d73afaf85b6a95826457de2692cd6e3157 Mon Sep 17 00:00:00 2001 From: Abi Raja Date: Tue, 19 Mar 2024 12:09:25 -0400 Subject: [PATCH] close anthropic client after it's done streaming --- backend/llm.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/llm.py b/backend/llm.py index 2c529e2..e6e628c 100644 --- a/backend/llm.py +++ b/backend/llm.py @@ -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: