Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,394 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
|
|
|
|
|
7 |
|
8 |
-
|
9 |
|
|
|
10 |
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
##
|
13 |
|
14 |
-
|
15 |
|
16 |
-
|
|
|
|
|
17 |
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
|
28 |
-
|
|
|
29 |
|
30 |
-
|
|
|
31 |
|
32 |
-
|
33 |
-
- **Paper [optional]:** [More Information Needed]
|
34 |
-
- **Demo [optional]:** [More Information Needed]
|
35 |
|
36 |
-
|
37 |
|
38 |
-
|
|
|
|
|
39 |
|
40 |
-
###
|
41 |
|
42 |
-
|
|
|
|
|
43 |
|
44 |
-
|
|
|
|
|
45 |
|
46 |
-
### Downstream Use [optional]
|
47 |
|
48 |
-
|
|
|
49 |
|
50 |
-
[
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
|
|
55 |
|
56 |
-
|
|
|
57 |
|
58 |
-
|
59 |
|
60 |
-
|
|
|
|
|
|
|
61 |
|
62 |
-
|
|
|
|
|
63 |
|
64 |
-
### Recommendations
|
65 |
|
66 |
-
|
|
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
|
71 |
|
72 |
-
|
|
|
73 |
|
74 |
-
|
|
|
75 |
|
76 |
-
##
|
77 |
|
78 |
-
|
79 |
|
80 |
-
|
|
|
81 |
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
### Training Procedure
|
85 |
|
86 |
-
|
87 |
|
88 |
-
|
|
|
|
|
89 |
|
90 |
-
|
|
|
|
|
91 |
|
|
|
|
|
92 |
|
93 |
-
|
|
|
|
|
94 |
|
95 |
-
|
|
|
|
|
|
|
|
|
96 |
|
97 |
-
|
|
|
98 |
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
-
|
|
|
|
|
102 |
|
103 |
-
|
|
|
|
|
104 |
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
-
|
108 |
|
109 |
-
|
110 |
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
-
|
|
|
|
|
|
|
114 |
|
115 |
-
|
116 |
|
117 |
-
|
118 |
|
119 |
-
|
|
|
|
|
120 |
|
121 |
-
|
122 |
|
123 |
-
|
|
|
|
|
124 |
|
125 |
-
|
|
|
126 |
|
127 |
-
|
|
|
128 |
|
129 |
-
|
130 |
|
131 |
-
|
132 |
|
|
|
|
|
|
|
133 |
|
|
|
134 |
|
135 |
-
|
|
|
|
|
136 |
|
137 |
-
|
|
|
|
|
138 |
|
139 |
-
[More Information Needed]
|
140 |
|
141 |
-
|
|
|
142 |
|
143 |
-
|
144 |
|
145 |
-
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
|
153 |
-
|
|
|
154 |
|
155 |
-
###
|
156 |
|
157 |
-
|
|
|
|
|
|
|
158 |
|
159 |
-
|
|
|
|
|
160 |
|
161 |
-
[More Information Needed]
|
162 |
|
163 |
-
|
|
|
164 |
|
165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
-
|
168 |
|
169 |
-
[
|
|
|
170 |
|
171 |
-
|
|
|
172 |
|
173 |
-
|
174 |
|
175 |
-
|
176 |
|
177 |
-
|
|
|
178 |
|
179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
|
181 |
-
[More Information Needed]
|
182 |
|
183 |
-
##
|
184 |
|
185 |
-
|
|
|
|
|
186 |
|
187 |
-
|
|
|
|
|
188 |
|
189 |
-
|
|
|
190 |
|
191 |
-
|
|
|
|
|
192 |
|
193 |
-
|
|
|
|
|
|
|
|
|
194 |
|
195 |
-
[
|
|
|
196 |
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
-
|
|
|
1 |
---
|
2 |
+
license: apache-2.0
|
3 |
+
extra_gated_description: >-
|
4 |
+
If you want to learn more about how we process your personal data, please read
|
5 |
+
our <a href="https://mistral.ai/terms/">Privacy Policy</a>.
|
6 |
+
tags:
|
7 |
+
- gptq
|
8 |
+
- quantized
|
9 |
+
- auto-gptq
|
10 |
+
- 4bit
|
11 |
---
|
12 |
|
13 |
+
## Mistral 7B Instruct v0.3 GPTQ 4bit
|
14 |
+
This is a 4bit GPTQ Quantization of the Mistral 7B Instruct v0.3 model
|
15 |
+
The model has been quantized using auto-gptq with a custom dataset.
|
16 |
|
17 |
+
# Model Card for Mistral-7B-Instruct-v0.3
|
18 |
|
19 |
+
The Mistral-7B-Instruct-v0.3 Large Language Model (LLM) is an instruct fine-tuned version of the Mistral-7B-v0.3.
|
20 |
|
21 |
+
Mistral-7B-v0.3 has the following changes compared to [Mistral-7B-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2/edit/main/README.md)
|
22 |
+
- Extended vocabulary to 32768
|
23 |
+
- Supports v3 Tokenizer
|
24 |
+
- Supports function calling
|
25 |
|
26 |
+
## Installation
|
27 |
|
28 |
+
It is recommended to use `mistralai/Mistral-7B-Instruct-v0.3` with [mistral-inference](https://github.com/mistralai/mistral-inference). For HF transformers code snippets, please keep scrolling.
|
29 |
|
30 |
+
```
|
31 |
+
pip install mistral_inference
|
32 |
+
```
|
33 |
|
34 |
+
## Download
|
35 |
|
36 |
+
```py
|
37 |
+
from huggingface_hub import snapshot_download
|
38 |
+
from pathlib import Path
|
|
|
|
|
|
|
|
|
39 |
|
40 |
+
mistral_models_path = Path.home().joinpath('mistral_models', '7B-Instruct-v0.3')
|
41 |
+
mistral_models_path.mkdir(parents=True, exist_ok=True)
|
42 |
|
43 |
+
snapshot_download(repo_id="mistralai/Mistral-7B-Instruct-v0.3", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)
|
44 |
+
```
|
45 |
|
46 |
+
### Chat
|
|
|
|
|
47 |
|
48 |
+
After installing `mistral_inference`, a `mistral-chat` CLI command should be available in your environment. You can chat with the model using
|
49 |
|
50 |
+
```
|
51 |
+
mistral-chat $HOME/mistral_models/7B-Instruct-v0.3 --instruct --max_tokens 256
|
52 |
+
```
|
53 |
|
54 |
+
### Instruct following
|
55 |
|
56 |
+
```py
|
57 |
+
from mistral_inference.model import Transformer
|
58 |
+
from mistral_inference.generate import generate
|
59 |
|
60 |
+
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
61 |
+
from mistral_common.protocol.instruct.messages import UserMessage
|
62 |
+
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
63 |
|
|
|
64 |
|
65 |
+
tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
|
66 |
+
model = Transformer.from_folder(mistral_models_path)
|
67 |
|
68 |
+
completion_request = ChatCompletionRequest(messages=[UserMessage(content="Explain Machine Learning to me in a nutshell.")])
|
69 |
|
70 |
+
tokens = tokenizer.encode_chat_completion(completion_request).tokens
|
71 |
|
72 |
+
out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
73 |
+
result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
|
74 |
|
75 |
+
print(result)
|
76 |
+
```
|
77 |
|
78 |
+
### Function calling
|
79 |
|
80 |
+
```py
|
81 |
+
from mistral_common.protocol.instruct.tool_calls import Function, Tool
|
82 |
+
from mistral_inference.model import Transformer
|
83 |
+
from mistral_inference.generate import generate
|
84 |
|
85 |
+
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
86 |
+
from mistral_common.protocol.instruct.messages import UserMessage
|
87 |
+
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
88 |
|
|
|
89 |
|
90 |
+
tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
|
91 |
+
model = Transformer.from_folder(mistral_models_path)
|
92 |
|
93 |
+
completion_request = ChatCompletionRequest(
|
94 |
+
tools=[
|
95 |
+
Tool(
|
96 |
+
function=Function(
|
97 |
+
name="get_current_weather",
|
98 |
+
description="Get the current weather",
|
99 |
+
parameters={
|
100 |
+
"type": "object",
|
101 |
+
"properties": {
|
102 |
+
"location": {
|
103 |
+
"type": "string",
|
104 |
+
"description": "The city and state, e.g. San Francisco, CA",
|
105 |
+
},
|
106 |
+
"format": {
|
107 |
+
"type": "string",
|
108 |
+
"enum": ["celsius", "fahrenheit"],
|
109 |
+
"description": "The temperature unit to use. Infer this from the users location.",
|
110 |
+
},
|
111 |
+
},
|
112 |
+
"required": ["location", "format"],
|
113 |
+
},
|
114 |
+
)
|
115 |
+
)
|
116 |
+
],
|
117 |
+
messages=[
|
118 |
+
UserMessage(content="What's the weather like today in Paris?"),
|
119 |
+
],
|
120 |
+
)
|
121 |
|
122 |
+
tokens = tokenizer.encode_chat_completion(completion_request).tokens
|
123 |
|
124 |
+
out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
125 |
+
result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
|
126 |
|
127 |
+
print(result)
|
128 |
+
```
|
129 |
|
130 |
+
## Generate with `transformers`
|
131 |
|
132 |
+
If you want to use Hugging Face `transformers` to generate text, you can do something like this.
|
133 |
|
134 |
+
```py
|
135 |
+
from transformers import pipeline
|
136 |
|
137 |
+
messages = [
|
138 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
139 |
+
{"role": "user", "content": "Who are you?"},
|
140 |
+
]
|
141 |
+
chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.3")
|
142 |
+
chatbot(messages)
|
143 |
+
```
|
144 |
|
|
|
145 |
|
146 |
+
## Function calling with `transformers`
|
147 |
|
148 |
+
To use this example, you'll need `transformers` version 4.42.0 or higher. Please see the
|
149 |
+
[function calling guide](https://huggingface.co/docs/transformers/main/chat_templating#advanced-tool-use--function-calling)
|
150 |
+
in the `transformers` docs for more information.
|
151 |
|
152 |
+
```python
|
153 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
154 |
+
import torch
|
155 |
|
156 |
+
model_id = "mistralai/Mistral-7B-Instruct-v0.3"
|
157 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
158 |
|
159 |
+
def get_current_weather(location: str, format: str):
|
160 |
+
"""
|
161 |
+
Get the current weather
|
162 |
|
163 |
+
Args:
|
164 |
+
location: The city and state, e.g. San Francisco, CA
|
165 |
+
format: The temperature unit to use. Infer this from the users location. (choices: ["celsius", "fahrenheit"])
|
166 |
+
"""
|
167 |
+
pass
|
168 |
|
169 |
+
conversation = [{"role": "user", "content": "What's the weather like in Paris?"}]
|
170 |
+
tools = [get_current_weather]
|
171 |
|
172 |
+
# render the tool use prompt as a string:
|
173 |
+
tool_use_prompt = tokenizer.apply_chat_template(
|
174 |
+
conversation,
|
175 |
+
tools=tools,
|
176 |
+
tokenize=False,
|
177 |
+
add_generation_prompt=True,
|
178 |
+
)
|
179 |
|
180 |
+
inputs = tokenizer(tool_use_prompt, return_tensors="pt")
|
181 |
+
|
182 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
|
183 |
|
184 |
+
outputs = model.generate(**inputs, max_new_tokens=1000)
|
185 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
186 |
+
```
|
187 |
|
188 |
+
Note that, for reasons of space, this example does not show a complete cycle of calling a tool and adding the tool call and tool
|
189 |
+
results to the chat history so that the model can use them in its next generation. For a full tool calling example, please
|
190 |
+
see the [function calling guide](https://huggingface.co/docs/transformers/main/chat_templating#advanced-tool-use--function-calling),
|
191 |
+
and note that Mistral **does** use tool call IDs, so these must be included in your tool calls and tool results. They should be
|
192 |
+
exactly 9 alphanumeric characters.
|
193 |
+
|
194 |
+
|
195 |
+
## Limitations
|
196 |
+
|
197 |
+
The Mistral 7B Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance.
|
198 |
+
It does not have any moderation mechanisms. We're looking forward to engaging with the community on ways to
|
199 |
+
make the model finely respect guardrails, allowing for deployment in environments requiring moderated outputs.
|
200 |
|
201 |
+
## The Mistral AI Team
|
202 |
|
203 |
+
Albert Jiang, Alexandre Sablayrolles, Alexis Tacnet, Antoine Roux, Arthur Mensch, Audrey Herblin-Stoop, Baptiste Bout, Baudouin de Monicault, Blanche Savary, Bam4d, Caroline Feldman, Devendra Singh Chaplot, Diego de las Casas, Eleonore Arcelin, Emma Bou Hanna, Etienne Metzger, Gianna Lengyel, Guillaume Bour, Guillaume Lample, Harizo Rajaona, Jean-Malo Delignon, Jia Li, Justus Murke, Louis Martin, Louis Ternon, Lucile Saulnier, Lélio Renard Lavaud, Margaret Jennings, Marie Pellat, Marie Torelli, Marie-Anne Lachaux, Nicolas Schuhl, Patrick von Platen, Pierre Stock, Sandeep Subramanian, Sophia Yang, Szymon Antoniak, Teven Le Scao, Thibaut Lavril, Timothée Lacroix, Théophile Gervet, Thomas Wang, Valera Nemychnikova, William El Sayed, William Marshall
|
204 |
|
205 |
+
extra_gated_description: If you want to learn more about how we process your personal data, please read our <a href="https://mistral.ai/terms/">Privacy Policy</a>.
|
206 |
+
---
|
207 |
+
|
208 |
+
# Model Card for Mistral-7B-Instruct-v0.3
|
209 |
+
|
210 |
+
The Mistral-7B-Instruct-v0.3 Large Language Model (LLM) is an instruct fine-tuned version of the Mistral-7B-v0.3.
|
211 |
|
212 |
+
Mistral-7B-v0.3 has the following changes compared to [Mistral-7B-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2/edit/main/README.md)
|
213 |
+
- Extended vocabulary to 32768
|
214 |
+
- Supports v3 Tokenizer
|
215 |
+
- Supports function calling
|
216 |
|
217 |
+
## Installation
|
218 |
|
219 |
+
It is recommended to use `mistralai/Mistral-7B-Instruct-v0.3` with [mistral-inference](https://github.com/mistralai/mistral-inference). For HF transformers code snippets, please keep scrolling.
|
220 |
|
221 |
+
```
|
222 |
+
pip install mistral_inference
|
223 |
+
```
|
224 |
|
225 |
+
## Download
|
226 |
|
227 |
+
```py
|
228 |
+
from huggingface_hub import snapshot_download
|
229 |
+
from pathlib import Path
|
230 |
|
231 |
+
mistral_models_path = Path.home().joinpath('mistral_models', '7B-Instruct-v0.3')
|
232 |
+
mistral_models_path.mkdir(parents=True, exist_ok=True)
|
233 |
|
234 |
+
snapshot_download(repo_id="mistralai/Mistral-7B-Instruct-v0.3", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)
|
235 |
+
```
|
236 |
|
237 |
+
### Chat
|
238 |
|
239 |
+
After installing `mistral_inference`, a `mistral-chat` CLI command should be available in your environment. You can chat with the model using
|
240 |
|
241 |
+
```
|
242 |
+
mistral-chat $HOME/mistral_models/7B-Instruct-v0.3 --instruct --max_tokens 256
|
243 |
+
```
|
244 |
|
245 |
+
### Instruct following
|
246 |
|
247 |
+
```py
|
248 |
+
from mistral_inference.model import Transformer
|
249 |
+
from mistral_inference.generate import generate
|
250 |
|
251 |
+
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
252 |
+
from mistral_common.protocol.instruct.messages import UserMessage
|
253 |
+
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
254 |
|
|
|
255 |
|
256 |
+
tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
|
257 |
+
model = Transformer.from_folder(mistral_models_path)
|
258 |
|
259 |
+
completion_request = ChatCompletionRequest(messages=[UserMessage(content="Explain Machine Learning to me in a nutshell.")])
|
260 |
|
261 |
+
tokens = tokenizer.encode_chat_completion(completion_request).tokens
|
262 |
|
263 |
+
out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
264 |
+
result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
|
|
|
|
|
|
|
265 |
|
266 |
+
print(result)
|
267 |
+
```
|
268 |
|
269 |
+
### Function calling
|
270 |
|
271 |
+
```py
|
272 |
+
from mistral_common.protocol.instruct.tool_calls import Function, Tool
|
273 |
+
from mistral_inference.model import Transformer
|
274 |
+
from mistral_inference.generate import generate
|
275 |
|
276 |
+
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
277 |
+
from mistral_common.protocol.instruct.messages import UserMessage
|
278 |
+
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
279 |
|
|
|
280 |
|
281 |
+
tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
|
282 |
+
model = Transformer.from_folder(mistral_models_path)
|
283 |
|
284 |
+
completion_request = ChatCompletionRequest(
|
285 |
+
tools=[
|
286 |
+
Tool(
|
287 |
+
function=Function(
|
288 |
+
name="get_current_weather",
|
289 |
+
description="Get the current weather",
|
290 |
+
parameters={
|
291 |
+
"type": "object",
|
292 |
+
"properties": {
|
293 |
+
"location": {
|
294 |
+
"type": "string",
|
295 |
+
"description": "The city and state, e.g. San Francisco, CA",
|
296 |
+
},
|
297 |
+
"format": {
|
298 |
+
"type": "string",
|
299 |
+
"enum": ["celsius", "fahrenheit"],
|
300 |
+
"description": "The temperature unit to use. Infer this from the users location.",
|
301 |
+
},
|
302 |
+
},
|
303 |
+
"required": ["location", "format"],
|
304 |
+
},
|
305 |
+
)
|
306 |
+
)
|
307 |
+
],
|
308 |
+
messages=[
|
309 |
+
UserMessage(content="What's the weather like today in Paris?"),
|
310 |
+
],
|
311 |
+
)
|
312 |
|
313 |
+
tokens = tokenizer.encode_chat_completion(completion_request).tokens
|
314 |
|
315 |
+
out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
|
316 |
+
result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
|
317 |
|
318 |
+
print(result)
|
319 |
+
```
|
320 |
|
321 |
+
## Generate with `transformers`
|
322 |
|
323 |
+
If you want to use Hugging Face `transformers` to generate text, you can do something like this.
|
324 |
|
325 |
+
```py
|
326 |
+
from transformers import pipeline
|
327 |
|
328 |
+
messages = [
|
329 |
+
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
|
330 |
+
{"role": "user", "content": "Who are you?"},
|
331 |
+
]
|
332 |
+
chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.3")
|
333 |
+
chatbot(messages)
|
334 |
+
```
|
335 |
|
|
|
336 |
|
337 |
+
## Function calling with `transformers`
|
338 |
|
339 |
+
To use this example, you'll need `transformers` version 4.42.0 or higher. Please see the
|
340 |
+
[function calling guide](https://huggingface.co/docs/transformers/main/chat_templating#advanced-tool-use--function-calling)
|
341 |
+
in the `transformers` docs for more information.
|
342 |
|
343 |
+
```python
|
344 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
345 |
+
import torch
|
346 |
|
347 |
+
model_id = "mistralai/Mistral-7B-Instruct-v0.3"
|
348 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
349 |
|
350 |
+
def get_current_weather(location: str, format: str):
|
351 |
+
"""
|
352 |
+
Get the current weather
|
353 |
|
354 |
+
Args:
|
355 |
+
location: The city and state, e.g. San Francisco, CA
|
356 |
+
format: The temperature unit to use. Infer this from the users location. (choices: ["celsius", "fahrenheit"])
|
357 |
+
"""
|
358 |
+
pass
|
359 |
|
360 |
+
conversation = [{"role": "user", "content": "What's the weather like in Paris?"}]
|
361 |
+
tools = [get_current_weather]
|
362 |
|
363 |
+
# render the tool use prompt as a string:
|
364 |
+
tool_use_prompt = tokenizer.apply_chat_template(
|
365 |
+
conversation,
|
366 |
+
tools=tools,
|
367 |
+
tokenize=False,
|
368 |
+
add_generation_prompt=True,
|
369 |
+
)
|
370 |
+
|
371 |
+
inputs = tokenizer(tool_use_prompt, return_tensors="pt")
|
372 |
+
|
373 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
|
374 |
+
|
375 |
+
outputs = model.generate(**inputs, max_new_tokens=1000)
|
376 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
377 |
+
```
|
378 |
+
|
379 |
+
Note that, for reasons of space, this example does not show a complete cycle of calling a tool and adding the tool call and tool
|
380 |
+
results to the chat history so that the model can use them in its next generation. For a full tool calling example, please
|
381 |
+
see the [function calling guide](https://huggingface.co/docs/transformers/main/chat_templating#advanced-tool-use--function-calling),
|
382 |
+
and note that Mistral **does** use tool call IDs, so these must be included in your tool calls and tool results. They should be
|
383 |
+
exactly 9 alphanumeric characters.
|
384 |
+
|
385 |
+
|
386 |
+
## Limitations
|
387 |
+
|
388 |
+
The Mistral 7B Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance.
|
389 |
+
It does not have any moderation mechanisms. We're looking forward to engaging with the community on ways to
|
390 |
+
make the model finely respect guardrails, allowing for deployment in environments requiring moderated outputs.
|
391 |
+
|
392 |
+
## The Mistral AI Team
|
393 |
|
394 |
+
Albert Jiang, Alexandre Sablayrolles, Alexis Tacnet, Antoine Roux, Arthur Mensch, Audrey Herblin-Stoop, Baptiste Bout, Baudouin de Monicault, Blanche Savary, Bam4d, Caroline Feldman, Devendra Singh Chaplot, Diego de las Casas, Eleonore Arcelin, Emma Bou Hanna, Etienne Metzger, Gianna Lengyel, Guillaume Bour, Guillaume Lample, Harizo Rajaona, Jean-Malo Delignon, Jia Li, Justus Murke, Louis Martin, Louis Ternon, Lucile Saulnier, Lélio Renard Lavaud, Margaret Jennings, Marie Pellat, Marie Torelli, Marie-Anne Lachaux, Nicolas Schuhl, Patrick von Platen, Pierre Stock, Sandeep Subramanian, Sophia Yang, Szymon Antoniak, Teven Le Scao, Thibaut Lavril, Timothée Lacroix, Théophile Gervet, Thomas Wang, Valera Nemychnikova, William El Sayed, William Marshall
|