openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
3f8d8205ae41c389541e125336b0ae0c5e437661

Branches

Tags

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

Clone

HTTPS

Download ZIP

examples/async_demo.py

22lines · modecode

1#!/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:
12 stream = await client.completions.create(
13 model="gpt-3.5-turbo-instruct",
14 prompt="Say this is a test",
15 stream=True,
16 )
17 async for completion in stream:
18 print(completion.choices[0].text, end="")
19 print()
20
21
22asyncio.run(main())
23