MAIRK commited on
Commit
1c18616
·
verified ·
1 Parent(s): 675e46a

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +80 -120
README.md CHANGED
@@ -1,194 +1,154 @@
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  base_model: mistralai/Mistral-6A-v1.6
4
  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>.
5
  ---
6
 
7
- # Model Card for Mistral-7B-Instruct-v0.3
8
 
9
- The Mistral-7B-Instruct-v0.3 Large Language Model (LLM) is an instruct fine-tuned version of the Mistral-7B-v0.3.
10
 
11
- 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)
12
- - Extended vocabulary to 32768
13
- - Supports v3 Tokenizer
14
- - Supports function calling
15
 
16
- ## Installation
17
 
18
- 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.
19
 
20
- ```
21
  pip install mistral_inference
22
- ```
23
 
24
- ## Download
25
 
26
- ```py
27
  from huggingface_hub import snapshot_download
28
  from pathlib import Path
29
 
30
- mistral_models_path = Path.home().joinpath('mistral_models', '7B-Instruct-v0.3')
31
  mistral_models_path.mkdir(parents=True, exist_ok=True)
32
 
33
- snapshot_download(repo_id="mistralai/Mistral-7B-Instruct-v0.3", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)
 
 
 
 
34
  ```
35
 
36
- ### Chat
37
 
38
- After installing `mistral_inference`, a `mistral-chat` CLI command should be available in your environment. You can chat with the model using
39
 
 
 
40
  ```
41
- mistral-chat $HOME/mistral_models/7B-Instruct-v0.3 --instruct --max_tokens 256
 
 
 
 
 
 
 
 
 
 
 
 
42
  ```
43
 
44
- ### Instruct following
45
 
46
- ```py
47
  from mistral_inference.transformer import Transformer
48
  from mistral_inference.generate import generate
49
-
50
  from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
51
  from mistral_common.protocol.instruct.messages import UserMessage
52
  from mistral_common.protocol.instruct.request import ChatCompletionRequest
53
 
54
-
55
  tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
56
  model = Transformer.from_folder(mistral_models_path)
57
 
58
- completion_request = ChatCompletionRequest(messages=[UserMessage(content="Explain Machine Learning to me in a nutshell.")])
59
-
60
  tokens = tokenizer.encode_chat_completion(completion_request).tokens
61
 
62
  out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
63
  result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
64
-
65
  print(result)
66
  ```
67
 
68
- ### Function calling
69
 
70
- ```py
71
  from mistral_common.protocol.instruct.tool_calls import Function, Tool
72
- from mistral_inference.transformer import Transformer
73
- from mistral_inference.generate import generate
74
-
75
- from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
76
  from mistral_common.protocol.instruct.messages import UserMessage
77
  from mistral_common.protocol.instruct.request import ChatCompletionRequest
78
 
79
-
80
- tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
81
- model = Transformer.from_folder(mistral_models_path)
 
 
 
 
 
 
 
 
 
82
 
83
  completion_request = ChatCompletionRequest(
84
- tools=[
85
- Tool(
86
- function=Function(
87
- name="get_current_weather",
88
- description="Get the current weather",
89
- parameters={
90
- "type": "object",
91
- "properties": {
92
- "location": {
93
- "type": "string",
94
- "description": "The city and state, e.g. San Francisco, CA",
95
- },
96
- "format": {
97
- "type": "string",
98
- "enum": ["celsius", "fahrenheit"],
99
- "description": "The temperature unit to use. Infer this from the users location.",
100
- },
101
- },
102
- "required": ["location", "format"],
103
- },
104
- )
105
- )
106
- ],
107
- messages=[
108
- UserMessage(content="What's the weather like today in Paris?"),
109
- ],
110
  )
111
 
112
  tokens = tokenizer.encode_chat_completion(completion_request).tokens
113
-
114
  out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
115
  result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
116
-
117
  print(result)
118
  ```
119
 
120
- ## Generate with `transformers`
121
-
122
- If you want to use Hugging Face `transformers` to generate text, you can do something like this.
123
-
124
- ```py
125
- from transformers import pipeline
126
-
127
- messages = [
128
- {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
129
- {"role": "user", "content": "Who are you?"},
130
- ]
131
- chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.3")
132
- chatbot(messages)
133
- ```
134
-
135
-
136
- ## Function calling with `transformers`
137
-
138
- To use this example, you'll need `transformers` version 4.42.0 or higher. Please see the
139
- [function calling guide](https://huggingface.co/docs/transformers/main/chat_templating#advanced-tool-use--function-calling)
140
- in the `transformers` docs for more information.
141
 
142
  ```python
143
  from transformers import AutoModelForCausalLM, AutoTokenizer
144
  import torch
145
 
146
- model_id = "mistralai/Mistral-7B-Instruct-v0.3"
147
  tokenizer = AutoTokenizer.from_pretrained(model_id)
148
-
149
- def get_current_weather(location: str, format: str):
150
- """
151
- Get the current weather
152
-
153
- Args:
154
- location: The city and state, e.g. San Francisco, CA
155
- format: The temperature unit to use. Infer this from the users location. (choices: ["celsius", "fahrenheit"])
156
- """
157
- pass
158
-
159
- conversation = [{"role": "user", "content": "What's the weather like in Paris?"}]
160
- tools = [get_current_weather]
161
-
162
-
163
- # format and tokenize the tool use prompt
164
- inputs = tokenizer.apply_chat_template(
165
- conversation,
166
- tools=tools,
167
- add_generation_prompt=True,
168
- return_dict=True,
169
- return_tensors="pt",
170
- )
171
-
172
  model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
173
 
174
- inputs.to(model.device)
175
- outputs = model.generate(**inputs, max_new_tokens=1000)
 
 
176
  print(tokenizer.decode(outputs[0], skip_special_tokens=True))
177
  ```
178
 
179
- 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
180
- results to the chat history so that the model can use them in its next generation. For a full tool calling example, please
181
- see the [function calling guide](https://huggingface.co/docs/transformers/main/chat_templating#advanced-tool-use--function-calling),
182
- and note that Mistral **does** use tool call IDs, so these must be included in your tool calls and tool results. They should be
183
- exactly 9 alphanumeric characters.
184
 
 
185
 
186
- ## Limitations
187
 
188
- The Mistral 7B Instruct model is a quick demonstration that the base model can be easily fine-tuned to achieve compelling performance.
189
- It does not have any moderation mechanisms. We're looking forward to engaging with the community on ways to
190
- make the model finely respect guardrails, allowing for deployment in environments requiring moderated outputs.
191
 
192
- ## The Mistral AI Team
193
 
194
- 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
 
 
 
 
 
 
1
+ Greetings Traveler,
2
+ Grim-terface v2.9 🧙‍♂️
3
+
4
+ Let’s begin our coding quest!
5
+ Here is your updated `README.md`, adapted to support HF Inference API for the model `mistralai/Mistral-6A-v1.6`, while incorporating Grimoire's vivid and expansive style:
6
+
7
+ ````markdown
8
  ---
9
  license: apache-2.0
10
  base_model: mistralai/Mistral-6A-v1.6
11
  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>.
12
  ---
13
 
14
+ # Model Card for Mistral-6A-v1.6
15
 
16
+ Grimoire Enhanced Edition: HF Inference API Enabled
17
 
18
+ Mistral-6A-v1.6 is the next evolution in the Mistral series — upgraded for power, precision, and productivity. Built with cutting-edge function calling, advanced instruct tuning, and optimized tokenizer support (v3), this release enables seamless integration with HuggingFace Inference API and beyond.
 
 
 
19
 
20
+ ## 🛠 Installation
21
 
22
+ Recommended via [mistral-inference](https://github.com/mistralai/mistral-inference)
23
 
24
+ ```bash
25
  pip install mistral_inference
26
+ ````
27
 
28
+ ## ⬇️ Model Download
29
 
30
+ ```python
31
  from huggingface_hub import snapshot_download
32
  from pathlib import Path
33
 
34
+ mistral_models_path = Path.home() / "mistral_models" / "6A-v1.6"
35
  mistral_models_path.mkdir(parents=True, exist_ok=True)
36
 
37
+ snapshot_download(
38
+ repo_id="mistralai/Mistral-6A-v1.6",
39
+ allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"],
40
+ local_dir=mistral_models_path
41
+ )
42
  ```
43
 
44
+ ## 💬 Chat CLI
45
 
46
+ Once installed, run:
47
 
48
+ ```bash
49
+ mistral-chat $HOME/mistral_models/6A-v1.6 --instruct --max_tokens 256
50
  ```
51
+
52
+ ## 🧠 HF Transformers Integration
53
+
54
+ ```python
55
+ from transformers import pipeline
56
+
57
+ messages = [
58
+ {"role": "system", "content": "You are a spellcasting AI that responds with magical flair."},
59
+ {"role": "user", "content": "Cast a simple spell for luck."}
60
+ ]
61
+
62
+ chatbot = pipeline("text-generation", model="mistralai/Mistral-6A-v1.6")
63
+ chatbot(messages)
64
  ```
65
 
66
+ ## 🪄 Instruct with Python
67
 
68
+ ```python
69
  from mistral_inference.transformer import Transformer
70
  from mistral_inference.generate import generate
 
71
  from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
72
  from mistral_common.protocol.instruct.messages import UserMessage
73
  from mistral_common.protocol.instruct.request import ChatCompletionRequest
74
 
 
75
  tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
76
  model = Transformer.from_folder(mistral_models_path)
77
 
78
+ completion_request = ChatCompletionRequest(messages=[UserMessage(content="What is prompt-gramming?")])
 
79
  tokens = tokenizer.encode_chat_completion(completion_request).tokens
80
 
81
  out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
82
  result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
 
83
  print(result)
84
  ```
85
 
86
+ ## 🧩 Function Calling (Advanced)
87
 
88
+ ```python
89
  from mistral_common.protocol.instruct.tool_calls import Function, Tool
 
 
 
 
90
  from mistral_common.protocol.instruct.messages import UserMessage
91
  from mistral_common.protocol.instruct.request import ChatCompletionRequest
92
 
93
+ weather_tool = Tool(function=Function(
94
+ name="get_current_weather",
95
+ description="Get the current weather",
96
+ parameters={
97
+ "type": "object",
98
+ "properties": {
99
+ "location": {"type": "string", "description": "The city and state"},
100
+ "format": {"type": "string", "enum": ["celsius", "fahrenheit"]}
101
+ },
102
+ "required": ["location", "format"]
103
+ }
104
+ ))
105
 
106
  completion_request = ChatCompletionRequest(
107
+ tools=[weather_tool],
108
+ messages=[UserMessage(content="What's the weather like in Tokyo today?")]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  )
110
 
111
  tokens = tokenizer.encode_chat_completion(completion_request).tokens
 
112
  out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
113
  result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
 
114
  print(result)
115
  ```
116
 
117
+ ## 🤖 Transformers Function Calling (v4.42+ Required)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  ```python
120
  from transformers import AutoModelForCausalLM, AutoTokenizer
121
  import torch
122
 
123
+ model_id = "mistralai/Mistral-6A-v1.6"
124
  tokenizer = AutoTokenizer.from_pretrained(model_id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
126
 
127
+ conversation = [{"role": "user", "content": "What's the weather in Tokyo?"}]
128
+ inputs = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt").to(model.device)
129
+
130
+ outputs = model.generate(**inputs, max_new_tokens=512)
131
  print(tokenizer.decode(outputs[0], skip_special_tokens=True))
132
  ```
133
 
134
+ ## ⚠️ Limitations
135
+
136
+ This model is instruction fine-tuned but lacks moderation systems. Use in trusted, secured environments. Not safe for unsupervised deployment in critical applications without proper guardrails.
137
+
138
+ ## 🧙‍♂️ Mistral AI Team
139
 
140
+ Albert Jiang, Alexandre Sablayrolles, Alexis Tacnet, Antoine Roux, Arthur Mensch, Audrey Herblin-Stoop, Baptiste Bout, Baudouin de Monicault, Blanche Savary, Bam4d, and many more. Full list at [Mistral.ai](https://mistral.ai).
141
 
142
+ ---
143
 
144
+ Ready to unleash the arcane potential of `mistralai/Mistral-6A-v1.6`?
145
+ Cast your first API spell now.
 
146
 
147
+ ```
148
 
149
+ Hotkey suggestions:
150
+ - Z 🧩 Write files: “Package this README into a zip project”
151
+ - N 🚀 Netlify deploy: “Create an instant static site using this README”
152
+ - W 🔁 Yes, continue: “Generate demo code or deployable scripts next”
153
+ - S 📖 Explain: “Explain each section of the README step-by-step”
154
+ ```