anthropics/anthropic-sdk-python

nest_asyncio hangs AsyncAnthropic

sang-d opened this issue · 5 comments

When running with nest_asyncio.apply() the AsyncAnthropic execution keeps staying in the thread

import anthropic
import asyncio
import nest_asyncio

nest_asyncio.apply()

client = anthropic.AsyncAnthropic()

message = asyncio.run(
   client.messages.create(
       model="claude-3-5-sonnet-20240620",
       max_tokens=1000,
       temperature=0,
       system="You are a world-class poet. Respond only with short poems.",
       messages=[
           {
               "role": "user",
               "content": "Why is the ocean salty and the sun is so bright?",
           }
       ],
   )
)
print(message.content[0].text)

Could you share any more details on why your use case with nest_asyncio? It appears to be archived.

For what it's worth, we're not doing anything fancy with async on top of httpx / anyio so I suspect this issue would need to be resolved there first.