()
| 11 | |
| 12 | |
| 13 | def sync_main() -> None: |
| 14 | client = OpenAI() |
| 15 | response = client.completions.create( |
| 16 | model="gpt-3.5-turbo-instruct", |
| 17 | prompt="1,2,3,", |
| 18 | max_tokens=5, |
| 19 | temperature=0, |
| 20 | stream=True, |
| 21 | ) |
| 22 | |
| 23 | # You can manually control iteration over the response |
| 24 | first = next(response) |
| 25 | print(f"got response data: {first.to_json()}") |
| 26 | |
| 27 | # Or you could automatically iterate through all of data. |
| 28 | # Note that the for loop will not exit until *all* of the data has been processed. |
| 29 | for data in response: |
| 30 | print(data.to_json()) |
| 31 | |
| 32 | |
| 33 | async def async_main() -> None: |
no test coverage detected