Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions examples/async_demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S poetry run python
#!/usr/bin/env -S rye run python

import asyncio

Expand All @@ -9,13 +9,21 @@


async def main() -> None:
stream = await client.completions.create(
model="gpt-3.5-turbo-instruct",
prompt="Say this is a test",
stream = await client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": "Say this is a test",
},
],
stream=True,
)
async for completion in stream:
print(completion.choices[0].text, end="")
async for chunk in stream:
if not chunk.choices:
continue

print(chunk.choices[0].delta.content or "", end="")
print()


Expand Down
8 changes: 4 additions & 4 deletions examples/demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S poetry run python
#!/usr/bin/env -S rye run python

from openai import OpenAI

Expand All @@ -8,7 +8,7 @@
# Non-streaming:
print("----- standard request -----")
completion = client.chat.completions.create(
model="gpt-4",
model="gpt-4o",
messages=[
{
"role": "user",
Expand All @@ -21,7 +21,7 @@
# Streaming:
print("----- streaming request -----")
stream = client.chat.completions.create(
model="gpt-4",
model="gpt-4o",
messages=[
{
"role": "user",
Expand All @@ -40,7 +40,7 @@
# Response headers:
print("----- custom response headers test -----")
response = client.chat.completions.with_raw_response.create(
model="gpt-4",
model="gpt-4o",
messages=[
{
"role": "user",
Expand Down
28 changes: 17 additions & 11 deletions examples/streaming.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S poetry run python
#!/usr/bin/env -S rye run python

import asyncio

Expand All @@ -12,11 +12,14 @@

def sync_main() -> None:
client = OpenAI()
response = client.completions.create(
model="gpt-3.5-turbo-instruct",
prompt="1,2,3,",
max_tokens=5,
temperature=0,
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": "Count from 1 to 5.",
},
],
stream=True,
)

Expand All @@ -32,11 +35,14 @@ def sync_main() -> None:

async def async_main() -> None:
client = AsyncOpenAI()
response = await client.completions.create(
model="gpt-3.5-turbo-instruct",
prompt="1,2,3,",
max_tokens=5,
temperature=0,
response = await client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": "Count from 1 to 5.",
},
],
stream=True,
)

Expand Down
2 changes: 1 addition & 1 deletion examples/video.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S poetry run python
#!/usr/bin/env -S rye run python

import asyncio

Expand Down