MCPcopy
hub / github.com/openai/openai-python / async_main

Function async_main

examples/streaming.py:33–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31
32
33async 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
54sync_main()

Callers 1

streaming.pyFile · 0.70

Calls 4

AsyncOpenAIClass · 0.90
to_jsonMethod · 0.80
createMethod · 0.45
__anext__Method · 0.45

Tested by

no test coverage detected