main
 1import openai
 2
 3# will default to `os.environ['OPENAI_API_KEY']` if not explicitly set
 4openai.api_key = "..."
 5
 6# all client options can be configured just like the `OpenAI` instantiation counterpart
 7openai.base_url = "https://..."
 8openai.default_headers = {"x-foo": "true"}
 9
10# all API calls work in the exact same fashion as well
11stream = openai.chat.completions.create(
12    model="gpt-4",
13    messages=[
14        {
15            "role": "user",
16            "content": "How do I output all files in a directory using Python?",
17        },
18    ],
19    stream=True,
20)
21
22for chunk in stream:
23    print(chunk.choices[0].delta.content or "", end="", flush=True)
24
25print()