acreate method fail when using async
Describe the bug


when using async acreate , the API timeout
To Reproduce
async def chat(query, retry_count=0):
response = await openai.ChatCompletion.acreate(
model="gpt-3.5-turbo",
messages=query,
temperature=0.7,
max_tokens=1200,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.0,
)
out = response.choices[0]['message']['content']
@gpt_app.post("/gpt_go") async def gpt_go(request: Request): json_data = await request.form()
role = json_data["role"]
content = json_data["content"]
output = await chat([{"role": "system", "content":"hello"}])
return output
Code snippets
No response
OS
linux
Python version
Python 3.7
Library version
openai 0.27.0
In my server, upgrade aiohttp to 3.8.4 solved this.
https://github.com/nonebot/nonebot2/issues/1784#issuecomment-1462842717
ClientSession(trust_env=True)
https://stackoverflow.com/a/63364551/2142477
Workaround: replace the session object:
async with ClientSession(trust_env=True) as session:
openai.aiosession.set(session)
...
I met the same problem. I'm wondering if the above solutions work for you? I'm not sure how to add ClientSession in the codes
In my case, the issue turned out to be urllib (probably?) failing to locate the CA SSL certificates on the system. The funny thing is that non-async requests worked - apparently because the OpenAI API library uses different HTTP libraries for sync and async.
For me (Python 3.10 installed via MacPorts on macOS), the fix was to add this to .zshrc:
export SSL_CERT_FILE=$(python3 -m certifi)
This should be fixed in the upcoming v1 beta! Please try it and let us know!