-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathmulti_turn.py
More file actions
30 lines (24 loc) · 980 Bytes
/
multi_turn.py
File metadata and controls
30 lines (24 loc) · 980 Bytes
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
"""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 mistralai import Mistral
token = os.environ["GITHUB_TOKEN"]
endpoint = "https://models.github.ai/inference"
# Pick one of the Mistral models from the GitHub Models service
model_name = "mistral-small-2503"
# Create a client
client = Mistral(api_key=token, server_url=endpoint)
# Call the chat completion API
response = client.chat.complete(
model=model_name,
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?"},
],
)
# Print the response
print(response.choices[0].message.content)