pylint icon indicating copy to clipboard operation
pylint copied to clipboard

not-an-iterable in openai chat completion

Open lutzroeder opened this issue 1 year ago • 0 comments

Bug description

import openai

client = openai.OpenAI()

with open('test.txt', 'r', encoding='utf-8') as handle:
    contents = handle.read()

completion = client.chat.completions.create(
    model="gpt-4-1106-preview",
    messages = [ { "role":"user", "content": "Summarize\n\n" + contents } ],
    stream = True
)

for event in completion: # pylint: disable=not-an-iterable
    content = event.choices[0].delta.content
    print(content, end='', flush=True)

Configuration

[MASTER]
disable=
    C0103, # invalid-name
    C0114, # missing-module-docstring
    C0115, # missing-class-docstring
    C0116, # missing-function-docstring

[TYPECHECK]
generated-members=torch.*

Command used

pyline gpt-4-1106-preview.py

Pylint output

************* Module gpt-4-1106-preview
gpt-4-1106-preview.py:23:13: E1133: Non-iterable value completion is used in an iterating context (not-an-iterable)

Expected behavior

No warning.

Pylint version

ylint 3.0.3
astroid 3.0.1
Python 3.11.6 (main, Oct  2 2023, 13:45:54) [Clang 15.0.0 (clang-1500.0.40.1)]

OS / Environment

macOS 14.2

Additional dependencies

openai==1.5.0

Related issues

microsoft/pyright#6772 openai/openai-python#870

lutzroeder avatar Dec 19 '23 02:12 lutzroeder