From daee6474875bfd58a09f081faa7db14fcd32f211 Mon Sep 17 00:00:00 2001 From: Louis Combaldieu Date: Wed, 23 Apr 2025 09:48:23 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A5=85=20Update=20call=5Fllm.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Handle Anthropic RateLimitError --- utils/call_llm.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/utils/call_llm.py b/utils/call_llm.py index 0d794b4..ef15cad 100644 --- a/utils/call_llm.py +++ b/utils/call_llm.py @@ -85,19 +85,25 @@ def call_llm(prompt: str, use_cache: bool = True) -> str: # # Use Anthropic Claude 3.7 Sonnet Extended Thinking # def call_llm(prompt, use_cache: bool = True): -# from anthropic import Anthropic +# from anthropic import Anthropic, RateLimitError # client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY", "your-api-key")) -# response = client.messages.create( -# model="claude-3-7-sonnet-20250219", -# max_tokens=21000, -# thinking={ -# "type": "enabled", -# "budget_tokens": 20000 -# }, -# messages=[ -# {"role": "user", "content": prompt} -# ] -# ) +# try: +# response = client.messages.create( +# model="claude-3-7-sonnet-20250219", +# max_tokens=21000, +# thinking={ +# "type": "enabled", +# "budget_tokens": 20000 +# }, +# messages=[ +# {"role": "user", "content": prompt} +# ] +# ) +# except RateLimitError: +# for i in range(70): +# print(f"Rate limit exceeded. Waiting {70-i}s before retrying", end='\r', flush=True) +# time.sleep(1) +# return call_llm(prompt) # return response.content[1].text # # Use OpenAI o1 From d32eea7f9ced7fd166f9f6f177b73f9f1175f1cf Mon Sep 17 00:00:00 2001 From: Louis Combaldieu Date: Wed, 23 Apr 2025 09:51:30 +0200 Subject: [PATCH 2/2] :adhesive_bandage: Fixed time dependency --- utils/call_llm.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/call_llm.py b/utils/call_llm.py index ef15cad..eed3933 100644 --- a/utils/call_llm.py +++ b/utils/call_llm.py @@ -86,6 +86,7 @@ def call_llm(prompt: str, use_cache: bool = True) -> str: # # Use Anthropic Claude 3.7 Sonnet Extended Thinking # def call_llm(prompt, use_cache: bool = True): # from anthropic import Anthropic, RateLimitError +# import time # client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY", "your-api-key")) # try: # response = client.messages.create(