Skip to content

Commit 7d43bdc

Browse files
committed
chore: add python example
1 parent 9467e7b commit 7d43bdc

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

example/openai-chat-completion.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from openai import OpenAI
2+
3+
client = OpenAI(
4+
api_key="your-key-or-input-something-as-you-like",
5+
base_url="http://127.0.0.1:8080/v1"
6+
)
7+
8+
chat_completion = client.chat.completions.create(
9+
messages=[
10+
{
11+
"role": "user",
12+
"content": "Say this is a test",
13+
}
14+
],
15+
model="gpt-3.5-turbo",
16+
)
17+
18+
print(chat_completion)

example/openai-chat-stream.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from openai import OpenAI
2+
3+
client = OpenAI(
4+
api_key="your-key-or-input-something-as-you-like",
5+
base_url="http://127.0.0.1:8080/v1"
6+
)
7+
8+
stream = client.chat.completions.create(
9+
model="gpt-4",
10+
messages=[{"role": "user", "content": "Write a romantic poem and talk about League of Legends"}],
11+
stream=True,
12+
)
13+
for chunk in stream:
14+
print(chunk.choices[0].delta.content or "", end="")

0 commit comments

Comments
 (0)