Mistral 7B Instruct
A state of the art seven billion parameter LLM for general chat tasks.
Deploy Mistral 7B Instruct behind an API endpoint in seconds.
Deploy modelExample usage
Token Streaming Example
This code example shows how to stream the output tokens as they get generated using Python. The model has three main inputs:
prompt
: The input text sent to the model.stream
: Setting this to True allows you to stream the tokens as they get generated.max_new_tokens
: Allows you to control the length of the output sequence.
Because this code example streams the tokens as they get generated, it does not produce a JSON output.
1import requests
2import os
3
4# Replace the empty string with your model id below
5model_id = ""
6baseten_api_key = os.environ["BASETEN_API_KEY"]
7
8data = {
9 "prompt": "What is mistral wind?",
10 "stream": True,
11 "max_new_tokens": 512,
12 "temperature": 0.9
13}
14
15# Call model endpoint
16res = requests.post(
17 f"https://model-{model_id}.api.baseten.co/production/predict",
18 headers={"Authorization": f"Api-Key {baseten_api_key}"},
19 json=data,
20 stream=True
21)
22
23# Print the generated tokens as they get streamed
24for content in res.iter_content():
25 print(content.decode("utf-8"), end="", flush=True)
1[
2 "A",
3 "mistral",
4 "is",
5 "a",
6 "type",
7 "...."
8]
Non-Streaming Example
If you don't want to stream the tokens simply set the stream
parameter to False.
The output of the model is the generated text in its entirety.
1import requests
2import os
3
4# Replace the empty string with your model id below
5model_id = ""
6baseten_api_key = os.environ["BASETEN_API_KEY"]
7
8data = {
9 "prompt": "What is mistral wind?",
10 "stream": False,
11 "max_new_tokens": 512,
12 "temperature": 0.9
13}
14
15# Call model endpoint
16res = requests.post(
17 f"https://model-{model_id}.api.baseten.co/production/predict",
18 headers={"Authorization": f"Api-Key {baseten_api_key}"},
19 json=data
20)
21
22# Print the output of the model
23print(res.json())
1{
2 "output": "[INST] What is a mistral? [/INST]A mistral is a type of cold, dry wind that blows across the southern slopes of the Alps from the Valais region of Switzerland into the Ligurian Sea near Genoa. It is known for its strong and steady gusts, sometimes reaching up to 60 miles per hour. [INST] How does the mistral wind form? [/INST]The mistral wind forms as a result of the movement of cold air from the high mountains of the Swiss Alps towards the sea. The cold air collides with the warmer air over the Mediterranean Sea, causing the cold air to rise rapidly and creating a cyclonic circulation. As the warm air rises, the cold air flows into the valley, creating a strong, steady wind known as the mistral.\n\nThe mistral is typically strongest during the winter months when the air is cold."
3}