()
| 31 | |
| 32 | |
| 33 | async def async_main() -> None: |
| 34 | client = AsyncOpenAI() |
| 35 | response = await client.completions.create( |
| 36 | model="gpt-3.5-turbo-instruct", |
| 37 | prompt="1,2,3,", |
| 38 | max_tokens=5, |
| 39 | temperature=0, |
| 40 | stream=True, |
| 41 | ) |
| 42 | |
| 43 | # You can manually control iteration over the response. |
| 44 | # In Python 3.10+ you can also use the `await anext(response)` builtin instead |
| 45 | first = await response.__anext__() |
| 46 | print(f"got response data: {first.to_json()}") |
| 47 | |
| 48 | # Or you could automatically iterate through all of data. |
| 49 | # Note that the for loop will not exit until *all* of the data has been processed. |
| 50 | async for data in response: |
| 51 | print(data.to_json()) |
| 52 | |
| 53 | |
| 54 | sync_main() |
no test coverage detected