Skip to content

stream completions did not work on async api #456

@lsaint

Description

@lsaint

Describe the bug

According to How_to_stream_completions

response = openai.ChatCompletion.create(
    model='gpt-3.5-turbo',
    messages=[
        {'role': 'user', 'content': "What's 1+1? Answer in one word."}
    ],
    temperature=0,
    stream=True  
)

for chunk in response:
    print(chunk)

we can stream a chat completion via ChatCompletion.create
but when I use ChatCompletion.acreate , it failed.

TypeError: 'async_generator' object is not iterable

To Reproduce

response = openai.ChatCompletion.acreate(
    model='gpt-3.5-turbo',
    messages=[
        {'role': 'user', 'content': "What's 1+1? Answer in one word."}
    ],
    temperature=0,
    stream=True  
)

for chunk in response:
    print(chunk)

Code snippets

response = openai.ChatCompletion.acreate(
    model='gpt-3.5-turbo',
    messages=[
        {'role': 'user', 'content': "What's 1+1? Answer in one word."}
    ],
    temperature=0,
    stream=True  
)

for chunk in response:
    print(chunk)


### OS

macOS

### Python version

Python 3.11

### Library version

0.27.2

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