sanjay920 commited on
Commit
d6cc3be
1 Parent(s): 38efac2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +236 -1
README.md CHANGED
@@ -56,4 +56,239 @@ language:
56
  - en
57
  ---
58
 
59
- # Mistral-7B-Instruct-v0.3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  - en
57
  ---
58
 
59
+ # Mistral-7B-Instruct-v0.3
60
+
61
+ ## Model Description
62
+ Mistral-7B-Instruct-v0.3 is the result of further post-training on the base model [mistralai/Mistral-7B-Instruct-v0.3](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3). This model is designed for high performance in various instruction-following tasks and complex interactions, including function calling and detailed conversations.
63
+
64
+ ## Training Data
65
+ The model underwent additional training on a proprietary dataset encompassing diverse instruction-following, chat, and function calling data. This post-training process enhances the model's ability to integrate tools and manage complex interaction scenarios effectively.
66
+
67
+ ## How to use
68
+
69
+ You can use the model with the Hugging Face `transformers` and the rubra library [rubra-tools](https://github.com/rubra-ai/rubra-tools) as follows:
70
+
71
+ ```
72
+ pip install rubra_tools torch==2.3.0 transformers
73
+ ```
74
+
75
+ You also need Node.js and npm installed. Once you do, install the `jsonrepair` package - it's used to fix some rare hallucinations by the model.
76
+
77
+ ```
78
+ npm install jsonrepair
79
+ ```
80
+
81
+ ### 1. Load the Model
82
+ ```python
83
+ from transformers import AutoTokenizer, AutoModelForCausalLM
84
+ import torch
85
+ from rubra_tools import preprocess_input, postprocess_output
86
+
87
+ model_id = "rubra-ai/Mistral-7B-Instruct-v0.3"
88
+
89
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
90
+ model = AutoModelForCausalLM.from_pretrained(
91
+ model_id,
92
+ torch_dtype=torch.bfloat16,
93
+ device_map="auto",
94
+ )
95
+ ```
96
+
97
+ ### 2. Define Functions
98
+
99
+ Here we use 4 functions for a simple math chaining question:
100
+ ```python
101
+ functions = [
102
+ {
103
+ 'type': 'function',
104
+ 'function': {
105
+ 'name': 'addition',
106
+ 'description': "Adds two numbers together",
107
+ 'parameters': {
108
+ 'type': 'object',
109
+ 'properties': {
110
+ 'a': {
111
+ 'description': 'First number to add',
112
+ 'type': 'string'
113
+ },
114
+ 'b': {
115
+ 'description': 'Second number to add',
116
+ 'type': 'string'
117
+ }
118
+ },
119
+ 'required': []
120
+ }
121
+ }
122
+ },
123
+ {
124
+ 'type': 'function',
125
+ 'function': {
126
+ 'name': 'subtraction',
127
+ 'description': "Subtracts two numbers",
128
+ 'parameters': {
129
+ 'type': 'object',
130
+ 'properties': {
131
+ 'a': {
132
+ 'description': 'First number to be subtracted from',
133
+ 'type': 'string'
134
+ },
135
+ 'b': {
136
+ 'description': 'Number to subtract',
137
+ 'type': 'string'
138
+ }
139
+ },
140
+ 'required': []
141
+ }
142
+ }
143
+ },
144
+ {
145
+ 'type': 'function',
146
+ 'function': {
147
+ 'name': 'multiplication',
148
+ 'description': "Multiply two numbers together",
149
+ 'parameters': {
150
+ 'type': 'object',
151
+ 'properties': {
152
+ 'a': {
153
+ 'description': 'First number to multiply',
154
+ 'type': 'string'
155
+ },
156
+ 'b': {
157
+ 'description': 'Second number to multiply',
158
+ 'type': 'string'
159
+ }
160
+ },
161
+ 'required': []
162
+ }
163
+ }
164
+ },
165
+ {
166
+ 'type': 'function',
167
+ 'function': {
168
+ 'name': 'division',
169
+ 'description': "Divide two numbers",
170
+ 'parameters': {
171
+ 'type': 'object',
172
+ 'properties': {
173
+ 'a': {
174
+ 'description': 'First number to use as the dividend',
175
+ 'type': 'string'
176
+ },
177
+ 'b': {
178
+ 'description': 'Second number to use as the divisor',
179
+ 'type': 'string'
180
+ }
181
+ },
182
+ 'required': []
183
+ }
184
+ }
185
+ },
186
+ ]
187
+ ```
188
+
189
+ ### 3. Start the conversation
190
+ ```python
191
+ messages = [
192
+ {"role": "system", "content": "You are a helpful assistant."},
193
+ {"role": "user", "content": "What is the result of four plus six? Take the result and add 2? Then multiply by 5 and then divide by two"},
194
+ ]
195
+
196
+ def run_model(messages, functions):
197
+ ## Format messages in Rubra's format
198
+ formatted_msgs = preprocess_input(msgs=messages, tools=functions)
199
+
200
+ input_ids = tokenizer.apply_chat_template(
201
+ formatted_msgs,
202
+ add_generation_prompt=True,
203
+ return_tensors="pt"
204
+ ).to(model.device)
205
+
206
+ terminators = [
207
+ tokenizer.eos_token_id,
208
+ tokenizer.convert_tokens_to_ids("")
209
+ ]
210
+
211
+ outputs = model.generate(
212
+ input_ids,
213
+ max_new_tokens=1000,
214
+ eos_token_id=terminators,
215
+ do_sample=True,
216
+ temperature=0.1,
217
+ top_p=0.9,
218
+ )
219
+ response = outputs[0][input_ids.shape[-1]:]
220
+ raw_output = tokenizer.decode(response, skip_special_tokens=True)
221
+ return raw_output
222
+
223
+ raw_output = run_model(messages, functions)
224
+ # Check if there's a function call
225
+ function_call = postprocess_output(raw_output)
226
+ if function_call:
227
+ print(function_call)
228
+ else:
229
+ print(raw_output)
230
+ ```
231
+
232
+ You should see this output, which is a function call made by the AI assistant:
233
+ ```
234
+ [{'id': 'fc65a533', 'function': {'name': 'addition', 'arguments': '{"a": "4", "b": "6"}'}, 'type': 'function'}]
235
+ ```
236
+
237
+ ### 4. Add Executed Tool Result to Message History & Continue the Conversation
238
+
239
+ ```python
240
+ if function_call:
241
+ # append the assistant tool call msg
242
+ messages.append({"role": "assistant", "tool_calls": function_call})
243
+ # append the result of the tool call in openai format, in this case, the value of add 6 to 4 is 10.
244
+ messages.append({'role': 'tool', 'tool_call_id': function_call[0]["id"], 'name': function_call[0]["function"]["name"], 'content': '10'})
245
+ raw_output = run_model(messages, functions)
246
+ # Check if there's a function call
247
+ function_call = postprocess_output(raw_output)
248
+ if function_call:
249
+ print(function_call)
250
+ else:
251
+ print(raw_output)
252
+ ```
253
+
254
+ The LLM will make another call
255
+ ```
256
+ [{'id': '2ffc3de4', 'function': {'name': 'addition', 'arguments': '{"a": "10", "b": "2"}'}, 'type': 'function'}]
257
+ ```
258
+
259
+ ## Framework Versions
260
+
261
+ - Transformers 4.41.2
262
+ - Pytorch 2.3.1+cu121
263
+ - Datasets 2.19.2
264
+ - Tokenizers 0.19.1
265
+
266
+ ## Limitations and Bias
267
+
268
+ While the model performs well on a wide range of tasks, it may still produce biased or incorrect outputs. Users should exercise caution and critical judgment when using the model in sensitive or high-stakes applications. The model's outputs are influenced by the data it was trained on, which may contain inherent biases.
269
+
270
+ ## Ethical Considerations
271
+
272
+ Users should ensure that the deployment of this model adheres to ethical guidelines and consider the potential societal impact of the generated text. Misuse of the model for generating harmful or misleading content is strongly discouraged.
273
+
274
+ ## Acknowledgements
275
+
276
+ We would like to thank Mistral for the model.
277
+
278
+ ## Contact Information
279
+
280
+ For questions or comments about the model, please reach out to [the rubra team](mailto:[email protected]).
281
+
282
+ ## Citation
283
+
284
+ If you use this work, please cite it as:
285
+
286
+ ```
287
+ @misc {rubra_ai_2024,
288
+ author = { Sanjay Nadhavajhala and Yingbei Tong },
289
+ title = { Rubra-Meta-Llama-3-8B-Instruct },
290
+ year = 2024,
291
+ url = { https://huggingface.co/rubra-ai/Meta-Llama-3-8B-Instruct },
292
+ doi = { },
293
+ publisher = { Hugging Face }
294
+ }