Open tyler-suard-parker opened 8 months ago
You mean the code from https://til.simonwillison.net/gpt3/python-chatgpt-streaming-api
Does this work?
import openai
import asyncio
async def generate_cheesecake_names():
async for chunk in await openai.ChatCompletion.acreate(
model="gpt-3.5-turbo",
messages=[{
"role": "user",
"content": "Generate a list of 20 great names for sentient cheesecakes that teach SQL"
}],
stream=True,
):
content = chunk["choices"][0].get("delta", {}).get("content")
if content is not None:
print(content, end='')
asyncio.run(generate_cheesecake_names())
When I run your async code, I get: Error: await can't be used outside of a function. When I enclose the async code within an async function, I get: TypeError: object Stream can't be used in 'await' expression