Skip to content

Instantly share code, notes, and snippets.

@maciejskorski
Created August 9, 2025 14:40
Show Gist options
  • Save maciejskorski/b7865f293842feb6dfa988a497033c15 to your computer and use it in GitHub Desktop.
Save maciejskorski/b7865f293842feb6dfa988a497033c15 to your computer and use it in GitHub Desktop.
async processing with Anthropic
import anthropic
from tqdm.asyncio import tqdm as tqdm_async
async def analyze_with_claude(text: str, temperature=0.7):
client=anthropic.AsyncAnthropic()
output = await client.messages.create(
model="claude-4-sonnet-20250514",
max_tokens=200,
temperature=temperature,
system=prompt,
messages=[{"role": "user", "content": f"Text: {text}"}]
)
return output.content[0].text.strip()
async def process(example):
idx = example['id']
response = await analyze_with_claude(example['text'])
return (idx, response)
async def process_all():
tasks = list(map(process, ds_test_sample))
results = []
for task in tqdm_async.as_completed(tasks):
result = await task
results.append(result)
return results
results = await process_all()
results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment