Skip to content

Missing import for asyncio in README example code #1825

@okamiRvS

Description

@okamiRvS

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

Hi there,

I noticed a small typo in the example code provided in the README file. The code snippet uses asyncio.run(main()) but is missing the import statement for asyncio. This could cause confusion for users running the example as it will result in a NameError: name 'asyncio' is not defined.

To Reproduce

Here's the updated code with the necessary import:

from openai import AsyncOpenAI
import asyncio  # Add this import

client = AsyncOpenAI()

async def main():
    stream = await client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": "Say this is a test"}],
        stream=True,
    )
    async for chunk in stream:
        print(chunk.choices[0].delta.content or "", end="")

asyncio.run(main())

Code snippets

No response

OS

Python version

Library version

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions