anthropics / anthropic-sdk-python

MIT License
1.35k stars 164 forks source link

nest_asyncio hangs AsyncAnthropic #602

Open sang-d opened 2 months ago

sang-d commented 2 months ago

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)
RobertCraigie commented 1 week ago

Could you share any more details on what your use case is 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.

joelpob commented 1 week ago

Also running nest_asyncio.apply(), just updated from 0.28 to 0.34.1 and have hit this problem also.

RobertCraigie commented 1 week ago

@joelpob would you be able to verify if nest_asyncio works with httpx? I suspect this issue lies within the http library we're using / one of it's transitive dependencies