MCPcopy Create free account
hub / github.com/openai/openai-python / sync_main

Function sync_main

examples/streaming.py:13–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11
12
13def 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
33async def async_main() -> None:

Callers 1

streaming.pyFile · 0.70

Calls 3

OpenAIClass · 0.90
to_jsonMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected