openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.28.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

examples/async_demo.py

22lines · modeblame

08b8179aDavid Schnurr2 years ago1#!/usr/bin/env -S poetry run python
2
3import asyncio
4
5from openai import AsyncOpenAI
6
7# gets API Key from environment variable OPENAI_API_KEY
8client = AsyncOpenAI()
9
10
11async def main() -> None:
12stream = await client.completions.create(
a045ef84Stainless Bot2 years ago13model="gpt-3.5-turbo-instruct",
08b8179aDavid Schnurr2 years ago14prompt="Say this is a test",
15stream=True,
16)
17async for completion in stream:
18print(completion.choices[0].text, end="")
19print()
20
21
22asyncio.run(main())