Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
馃 Update call_llm.py
Handle Anthropic RateLimitError
  • Loading branch information
lcombaldieu authored Apr 23, 2025
commit daee6474875bfd58a09f081faa7db14fcd32f211
30 changes: 18 additions & 12 deletions utils/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down