-
Notifications
You must be signed in to change notification settings - Fork 38
/
multi_turn.py
45 lines (39 loc) · 1.11 KB
/
multi_turn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""This sample demonstrates a multi-turn conversation with the chat completion API.
When using the model for a chat application, you'll need to manage the history of that
conversation and send the latest messages to the model.
"""
import os
from openai import OpenAI
token = os.environ["GITHUB_TOKEN"]
endpoint = "https://models.inference.ai.azure.com"
# Pick one of the Azure OpenAI models from the GitHub Models service
model_name = "gpt-4o-mini"
# Create a client
client = OpenAI(
base_url=endpoint,
api_key=token,
)
# Call the chat completion API
response = client.chat.completions.create(
messages=[
{
"role": "system",
"content": "You are a helpful assistant.",
},
{
"role": "user",
"content": "What is the capital of France?",
},
{
"role": "assistant",
"content": "The capital of France is Paris.",
},
{
"role": "user",
"content": "What about Spain?",
},
],
model=model_name,
)
# Print the response
print(response.choices[0].message.content)