generated from github/codespaces-models
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi_turn.py
31 lines (25 loc) · 1.04 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
"""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.client import MistralClient
from mistralai.models.chat_completion import ChatMessage
token = os.environ["GITHUB_TOKEN"]
endpoint = "https://models.inference.ai.azure.com"
# Pick one of the Mistral models from the GitHub Models service
model_name = "Mistral-small"
# Create a client
client = MistralClient(api_key=token, endpoint=endpoint)
# Call the chat completion API
response = client.chat(
model=model_name,
messages=[
ChatMessage(role="system", content="You are a helpful assistant."),
ChatMessage(role="user", content="What is the capital of France?"),
ChatMessage(role="assistant", content="The capital of France is Paris."),
ChatMessage(role="user", content="What about Spain?"),
],
)
# Print the response
print(response.choices[0].message.content)