jukofyork commited on
Commit
9656c30
·
verified ·
1 Parent(s): 3b54487

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +654 -0
README.md ADDED
@@ -0,0 +1,654 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ inference: false
3
+ language:
4
+ - en
5
+ - fr
6
+ - de
7
+ - es
8
+ - it
9
+ - pt
10
+ - ja
11
+ - ko
12
+ - zh
13
+ - ar
14
+ license: cc-by-nc-4.0
15
+ library_name: transformers
16
+ extra_gated_prompt: "By submitting this form, you agree to the [License Agreement](https://cohere.com/c4ai-cc-by-nc-license) and acknowledge that the information you provide will be collected, used, and shared in accordance with Cohere’s [Privacy Policy]( https://cohere.com/privacy). You’ll receive email updates about Cohere Labs and Cohere research, events, products and services. You can unsubscribe at any time."
17
+ extra_gated_fields:
18
+ Name: text
19
+ Affiliation: text
20
+ Country:
21
+ type: select
22
+ options:
23
+ - Aruba
24
+ - Afghanistan
25
+ - Angola
26
+ - Anguilla
27
+ - Åland Islands
28
+ - Albania
29
+ - Andorra
30
+ - United Arab Emirates
31
+ - Argentina
32
+ - Armenia
33
+ - American Samoa
34
+ - Antarctica
35
+ - French Southern Territories
36
+ - Antigua and Barbuda
37
+ - Australia
38
+ - Austria
39
+ - Azerbaijan
40
+ - Burundi
41
+ - Belgium
42
+ - Benin
43
+ - Bonaire Sint Eustatius and Saba
44
+ - Burkina Faso
45
+ - Bangladesh
46
+ - Bulgaria
47
+ - Bahrain
48
+ - Bahamas
49
+ - Bosnia and Herzegovina
50
+ - Saint Barthélemy
51
+ - Belarus
52
+ - Belize
53
+ - Bermuda
54
+ - Plurinational State of Bolivia
55
+ - Brazil
56
+ - Barbados
57
+ - Brunei-Darussalam
58
+ - Bhutan
59
+ - Bouvet-Island
60
+ - Botswana
61
+ - Central African Republic
62
+ - Canada
63
+ - Cocos (Keeling) Islands
64
+ - Switzerland
65
+ - Chile
66
+ - China
67
+ - Côte-dIvoire
68
+ - Cameroon
69
+ - Democratic Republic of the Congo
70
+ - Cook Islands
71
+ - Colombia
72
+ - Comoros
73
+ - Cabo Verde
74
+ - Costa Rica
75
+ - Cuba
76
+ - Curaçao
77
+ - Christmas Island
78
+ - Cayman Islands
79
+ - Cyprus
80
+ - Czechia
81
+ - Germany
82
+ - Djibouti
83
+ - Dominica
84
+ - Denmark
85
+ - Dominican Republic
86
+ - Algeria
87
+ - Ecuador
88
+ - Egypt
89
+ - Eritrea
90
+ - Western Sahara
91
+ - Spain
92
+ - Estonia
93
+ - Ethiopia
94
+ - Finland
95
+ - Fiji
96
+ - Falkland Islands (Malvinas)
97
+ - France
98
+ - Faroe Islands
99
+ - Federated States of Micronesia
100
+ - Gabon
101
+ - United Kingdom
102
+ - Georgia
103
+ - Guernsey
104
+ - Ghana
105
+ - Gibraltar
106
+ - Guinea
107
+ - Guadeloupe
108
+ - Gambia
109
+ - Guinea Bissau
110
+ - Equatorial Guinea
111
+ - Greece
112
+ - Grenada
113
+ - Greenland
114
+ - Guatemala
115
+ - French Guiana
116
+ - Guam
117
+ - Guyana
118
+ - Hong Kong
119
+ - Heard Island and McDonald Islands
120
+ - Honduras
121
+ - Croatia
122
+ - Haiti
123
+ - Hungary
124
+ - Indonesia
125
+ - Isle of Man
126
+ - India
127
+ - British Indian Ocean Territory
128
+ - Ireland
129
+ - Islamic Republic of Iran
130
+ - Iraq
131
+ - Iceland
132
+ - Israel
133
+ - Italy
134
+ - Jamaica
135
+ - Jersey
136
+ - Jordan
137
+ - Japan
138
+ - Kazakhstan
139
+ - Kenya
140
+ - Kyrgyzstan
141
+ - Cambodia
142
+ - Kiribati
143
+ - Saint-Kitts-and-Nevis
144
+ - South Korea
145
+ - Kuwait
146
+ - Lao-Peoples-Democratic-Republic
147
+ - Lebanon
148
+ - Liberia
149
+ - Libya
150
+ - Saint-Lucia
151
+ - Liechtenstein
152
+ - Sri Lanka
153
+ - Lesotho
154
+ - Lithuania
155
+ - Luxembourg
156
+ - Latvia
157
+ - Macao
158
+ - Saint Martin (French-part)
159
+ - Morocco
160
+ - Monaco
161
+ - Republic of Moldova
162
+ - Madagascar
163
+ - Maldives
164
+ - Mexico
165
+ - Marshall Islands
166
+ - North Macedonia
167
+ - Mali
168
+ - Malta
169
+ - Myanmar
170
+ - Montenegro
171
+ - Mongolia
172
+ - Northern Mariana Islands
173
+ - Mozambique
174
+ - Mauritania
175
+ - Montserrat
176
+ - Martinique
177
+ - Mauritius
178
+ - Malawi
179
+ - Malaysia
180
+ - Mayotte
181
+ - Namibia
182
+ - New Caledonia
183
+ - Niger
184
+ - Norfolk Island
185
+ - Nigeria
186
+ - Nicaragua
187
+ - Niue
188
+ - Netherlands
189
+ - Norway
190
+ - Nepal
191
+ - Nauru
192
+ - New Zealand
193
+ - Oman
194
+ - Pakistan
195
+ - Panama
196
+ - Pitcairn
197
+ - Peru
198
+ - Philippines
199
+ - Palau
200
+ - Papua New Guinea
201
+ - Poland
202
+ - Puerto Rico
203
+ - North Korea
204
+ - Portugal
205
+ - Paraguay
206
+ - State of Palestine
207
+ - French Polynesia
208
+ - Qatar
209
+ - Réunion
210
+ - Romania
211
+ - Russia
212
+ - Rwanda
213
+ - Saudi Arabia
214
+ - Sudan
215
+ - Senegal
216
+ - Singapore
217
+ - South Georgia and the South Sandwich Islands
218
+ - Saint Helena Ascension and Tristan da Cunha
219
+ - Svalbard and Jan Mayen
220
+ - Solomon Islands
221
+ - Sierra Leone
222
+ - El Salvador
223
+ - San Marino
224
+ - Somalia
225
+ - Saint Pierre and Miquelon
226
+ - Serbia
227
+ - South Sudan
228
+ - Sao Tome and Principe
229
+ - Suriname
230
+ - Slovakia
231
+ - Slovenia
232
+ - Sweden
233
+ - Eswatini
234
+ - Sint Maarten (Dutch-part)
235
+ - Seychelles
236
+ - Syrian Arab Republic
237
+ - Turks and Caicos Islands
238
+ - Chad
239
+ - Togo
240
+ - Thailand
241
+ - Tajikistan
242
+ - Tokelau
243
+ - Turkmenistan
244
+ - Timor Leste
245
+ - Tonga
246
+ - Trinidad and Tobago
247
+ - Tunisia
248
+ - Turkey
249
+ - Tuvalu
250
+ - Taiwan
251
+ - United Republic of Tanzania
252
+ - Uganda
253
+ - Ukraine
254
+ - United States Minor Outlying Islands
255
+ - Uruguay
256
+ - United-States
257
+ - Uzbekistan
258
+ - Holy See (Vatican City State)
259
+ - Saint Vincent and the Grenadines
260
+ - Bolivarian Republic of Venezuela
261
+ - Virgin Islands British
262
+ - Virgin Islands U.S.
263
+ - VietNam
264
+ - Vanuatu
265
+ - Wallis and Futuna
266
+ - Samoa
267
+ - Yemen
268
+ - South Africa
269
+ - Zambia
270
+ - Zimbabwe
271
+
272
+ I agree to use this model for non-commercial use ONLY: checkbox
273
+ ---
274
+
275
+ # Model Card for Cohere Labs Command-R
276
+
277
+ 🚨 **This model is non-quantized version of Cohere Labs Command-R. You can find the quantized version of Cohere Labs Command-R using bitsandbytes [here](https://huggingface.co/CohereLabs/c4ai-command-r-v01-4bit)**.
278
+
279
+ ## Model Summary
280
+
281
+ Cohere Labs Command-R is a research release of a 35 billion parameter highly performant generative model. Command-R is a large language model with open weights optimized for a variety of use cases including reasoning, summarization, and question answering. Command-R has the capability for multilingual generation evaluated in 10 languages and highly performant RAG capabilities.
282
+
283
+ Developed by: Cohere and [Cohere Labs](https://cohere.com/research)
284
+
285
+ - Point of Contact: [Cohere Labs](https://cohere.com/research)
286
+ - License: [CC-BY-NC](https://cohere.com/c4ai-cc-by-nc-license), requires also adhering to [Cohere Lab's Acceptable Use Policy](https://docs.cohere.com/docs/c4ai-acceptable-use-policy)
287
+ - Model: c4ai-command-r-v01
288
+ - Model Size: 35 billion parameters
289
+ - Context length: 128K
290
+
291
+ **Try Cohere Labs Command R**
292
+
293
+ If you want to try Command R before downloading the weights, the model is hosted in a hugging face space [here](https://huggingface.co/spaces/CohereLabs/c4ai-command?model=command-r).
294
+
295
+ **Usage**
296
+
297
+ Please use `transformers` version 4.39.1 or higher
298
+ ```python
299
+ # pip install 'transformers>=4.39.1'
300
+ from transformers import AutoTokenizer, AutoModelForCausalLM
301
+
302
+ model_id = "CohereLabs/c4ai-command-r-v01"
303
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
304
+ model = AutoModelForCausalLM.from_pretrained(model_id)
305
+
306
+ # Format message with the command-r chat template
307
+ messages = [{"role": "user", "content": "Hello, how are you?"}]
308
+ input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
309
+ ## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
310
+
311
+ gen_tokens = model.generate(
312
+ input_ids,
313
+ max_new_tokens=100,
314
+ do_sample=True,
315
+ temperature=0.3,
316
+ )
317
+
318
+ gen_text = tokenizer.decode(gen_tokens[0])
319
+ print(gen_text)
320
+ ```
321
+
322
+ **Quantized model through bitsandbytes, 8-bit precision**
323
+
324
+ ```python
325
+ # pip install 'transformers>=4.39.1' bitsandbytes accelerate
326
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
327
+
328
+ bnb_config = BitsAndBytesConfig(load_in_8bit=True)
329
+
330
+ model_id = "CohereLabs/c4ai-command-r-v01"
331
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
332
+ model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config)
333
+
334
+ # Format message with the command-r chat template
335
+ messages = [{"role": "user", "content": "Hello, how are you?"}]
336
+ input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
337
+ ## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
338
+
339
+ gen_tokens = model.generate(
340
+ input_ids,
341
+ max_new_tokens=100,
342
+ do_sample=True,
343
+ temperature=0.3,
344
+ )
345
+
346
+ gen_text = tokenizer.decode(gen_tokens[0])
347
+ print(gen_text)
348
+ ```
349
+
350
+ **Quantized model through bitsandbytes, 4-bit precision**
351
+
352
+ You can find a quantized version of this model to 4-bit precision [here](https://huggingface.co/CohereLabs/c4ai-command-r-v01-4bit).
353
+
354
+ ## Model Details
355
+
356
+ **Input**: Models input text only.
357
+
358
+ **Output**: Models generate text only.
359
+
360
+ **Model Architecture**: This is an auto-regressive language model that uses an optimized transformer architecture. After pretraining, this model uses supervised fine-tuning (SFT) and preference training to align model behavior to human preferences for helpfulness and safety.
361
+
362
+ **Languages covered**: The model is optimized to perform well in the following languages: English, French, Spanish, Italian, German, Brazilian Portuguese, Japanese, Korean, Simplified Chinese, and Arabic.
363
+
364
+ Pre-training data additionally included the following 13 languages: Russian, Polish, Turkish, Vietnamese, Dutch, Czech, Indonesian, Ukrainian, Romanian, Greek, Hindi, Hebrew, Persian.
365
+
366
+ **Context length**: Command-R supports a context length of 128K.
367
+
368
+ ### Grounded Generation and RAG Capabilities:
369
+
370
+ Command-R has been specifically trained with grounded generation capabilities. This means that it can generate responses based on a list of supplied document snippets, and it will include grounding spans (citations) in its response indicating the source of the information.
371
+ This can be used to enable behaviors such as grounded summarization and the final step of Retrieval Augmented Generation (RAG).This behavior has been trained into the model via a mixture of supervised fine-tuning and preference fine-tuning, using a specific prompt template.
372
+ Deviating from this prompt template may reduce performance, but we encourage experimentation.
373
+
374
+ Command-R’s grounded generation behavior takes a conversation as input (with an optional user-supplied system preamble, indicating task, context and desired output style), along with a list of retrieved document snippets.
375
+ The document snippets should be chunks, rather than long documents, typically around 100-400 words per chunk. Document snippets consist of key-value pairs. The keys should be short descriptive strings, the values can be text or semi-structured.
376
+
377
+ By default, Command-R will generate grounded responses by first predicting which documents are relevant, then predicting which ones it will cite, then generating an answer.
378
+ Finally, it will then insert grounding spans into the answer. See below for an example. This is referred to as `accurate` grounded generation.
379
+
380
+ The model is trained with a number of other answering modes, which can be selected by prompt changes . A `fast` citation mode is supported in the tokenizer, which will directly generate an answer with grounding spans in it, without first writing the answer out in full. This sacrifices some grounding accuracy in favor of generating fewer tokens.
381
+
382
+ Comprehensive documentation for working with command-R's grounded generation prompt template can be found [here](https://docs.cohere.com/docs/prompting-command-r).
383
+
384
+ The code snippet below shows a minimal working example on how to render a prompt.
385
+
386
+ <details>
387
+ <summary> <b>Usage: Rendering Grounded Generation prompts [CLICK TO EXPAND]</b> </summary>
388
+
389
+ ````python
390
+ from transformers import AutoTokenizer
391
+
392
+ model_id = "CohereLabs/c4ai-command-r-v01"
393
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
394
+
395
+ # define conversation input:
396
+ conversation = [
397
+ {"role": "user", "content": "Whats the biggest penguin in the world?"}
398
+ ]
399
+ # define documents to ground on:
400
+ documents = [
401
+ { "title": "Tall penguins", "text": "Emperor penguins are the tallest growing up to 122 cm in height." },
402
+ { "title": "Penguin habitats", "text": "Emperor penguins only live in Antarctica."}
403
+ ]
404
+
405
+ # render the tool use prompt as a string:
406
+ grounded_generation_prompt = tokenizer.apply_grounded_generation_template(
407
+ conversation,
408
+ documents=documents,
409
+ citation_mode="accurate", # or "fast"
410
+ tokenize=False,
411
+ add_generation_prompt=True,
412
+ )
413
+ print(grounded_generation_prompt)
414
+ ````
415
+ </details>
416
+
417
+ <details>
418
+ <summary><b>Example Rendered Grounded Generation Prompt [CLICK TO EXPAND]</b></summary>
419
+
420
+ ````<BOS_TOKEN><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
421
+ The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
422
+
423
+ # System Preamble
424
+ ## Basic Rules
425
+ You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.
426
+
427
+ # User Preamble
428
+ ## Task and Context
429
+ You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.
430
+
431
+ ## Style Guide
432
+ Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Whats the biggest penguin in the world?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><results>
433
+ Document: 0
434
+ title: Tall penguins
435
+ text: Emperor penguins are the tallest growing up to 122 cm in height.
436
+
437
+ Document: 1
438
+ title: Penguin habitats
439
+ text: Emperor penguins only live in Antarctica.
440
+ </results><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.
441
+ Firstly, Decide which of the retrieved documents are relevant to the user's last input by writing 'Relevant Documents:' followed by comma-separated list of document numbers. If none are relevant, you should instead write 'None'.
442
+ Secondly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user's last input by writing 'Cited Documents:' followed a comma-separated list of document numbers. If you dont want to cite any of them, you should instead write 'None'.
443
+ Thirdly, Write 'Answer:' followed by a response to the user's last input in high quality natural english. Use the retrieved documents to help you. Do not insert any citations or grounding markup.
444
+ Finally, Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbols <co: doc> and </co: doc> to indicate when a fact comes from a document in the search result, e.g <co: 0>my fact</co: 0> for a fact from document 0.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
445
+ ````
446
+
447
+ </details>
448
+
449
+ <details>
450
+ <summary><b>Example Rendered Grounded Generation Completion [CLICK TO EXPAND]</b></summary>
451
+
452
+ ````
453
+ Relevant Documents: 0,1
454
+ Cited Documents: 0,1
455
+ Answer: The Emperor Penguin is the tallest or biggest penguin in the world. It is a bird that lives only in Antarctica and grows to a height of around 122 centimetres.
456
+ Grounded answer: The <co: 0>Emperor Penguin</co: 0> is the <co: 0>tallest</co: 0> or biggest penguin in the world. It is a bird that <co: 1>lives only in Antarctica</co: 1> and <co: 0>grows to a height of around 122 centimetres.</co: 0>
457
+ ````
458
+ </details>
459
+
460
+
461
+ ### Single-Step Tool Use Capabilities ("Function Calling"):
462
+ Single-step tool use (or “Function Calling”) allows Command R to interact with external tools like APIs, databases, or search engines. Single-step tool use is made of two model inferences:
463
+ - Tool Selection: The model decides which tools to call and with what parameters. It’s then up to the developer to execute these tool calls and obtain tool results.
464
+ - Response Generation: The model generates the final response given the tool results.
465
+ You can learn more about single step tool use in our [documentation](https://docs.cohere.com/docs/tool-use).
466
+
467
+ Command R has been specifically trained with single-step tool use (or “Function Calling”) capabilities. These have been trained into the model via a mixture of supervised fine-tuning and preference fine-tuning, using a specific prompt template. Deviating from this prompt template may reduce performance. This is why we recommend using the prompt template described below.
468
+
469
+ Command R’s single-step tool use functionality takes a conversation as input (with an optional user-system preamble), along with a list of available tools. The model will then generate a json-formatted list of actions to execute on a subset of those tools. Command R may use one of its supplied tools more than once.
470
+
471
+ The model has been trained to recognise a special `directly_answer` tool, which it uses to indicate that it doesn’t want to use any of its other tools. The ability to abstain from calling a specific tool can be useful in a range of situations, such as greeting a user, or asking clarifying questions. We recommend including the `directly_answer` tool, but it can be removed or renamed if required.
472
+
473
+ Comprehensive documentation for working with Command R's single-step tool use prompt template can be found [here](https://docs.cohere.com/docs/prompting-command-r#single-step-tool-use-with-command-rr-function-calling) and [here](https://docs.cohere.com/docs/prompting-command-r#single-step-tool-use-with-command-rr-function-calling-1).
474
+
475
+ You can render the single-step tool use prompt template by using the function `apply_tool_use_template()`. The code snippet below shows a minimal working example on how to render this prompt.
476
+
477
+ Command R also supports Hugging Face's [tool use API](https://huggingface.co/docs/transformers/main/en/chat_templating#advanced-tool-use--function-calling) to render the same prompt.
478
+
479
+
480
+ <details>
481
+ <summary><b>Usage: Rendering Single-Step Tool Use Prompts [CLICK TO EXPAND]</b> </summary>
482
+
483
+ ```python
484
+ from transformers import AutoTokenizer
485
+
486
+ model_id = "CohereLabs/c4ai-command-r-v01"
487
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
488
+
489
+ # define conversation input:
490
+ conversation = [
491
+ {"role": "user", "content": "Whats the biggest penguin in the world?"}
492
+ ]
493
+ # Define tools available for the model to use:
494
+ tools = [
495
+ {
496
+ "name": "internet_search",
497
+ "description": "Returns a list of relevant document snippets for a textual query retrieved from the internet",
498
+ "parameter_definitions": {
499
+ "query": {
500
+ "description": "Query to search the internet with",
501
+ "type": 'str',
502
+ "required": True
503
+ }
504
+ }
505
+ },
506
+ {
507
+ 'name': "directly_answer",
508
+ "description": "Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history",
509
+ 'parameter_definitions': {}
510
+ }
511
+ ]
512
+
513
+ # render the tool use prompt as a string:
514
+ tool_use_prompt = tokenizer.apply_tool_use_template(
515
+ conversation,
516
+ tools=tools,
517
+ tokenize=False,
518
+ add_generation_prompt=True,
519
+ )
520
+ print(tool_use_prompt)
521
+ ```
522
+
523
+ </details>
524
+
525
+
526
+ <details>
527
+ <summary><b>Usage: Rendering prompts with the Single-Step Tool Use API [CLICK TO EXPAND]</b> </summary>
528
+
529
+ ```python
530
+ from transformers import AutoTokenizer
531
+
532
+ model_id = "CohereLabs/c4ai-command-r-v01"
533
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
534
+
535
+ # define conversation input:
536
+ conversation = [
537
+ {"role": "user", "content": "Whats the biggest penguin in the world?"}
538
+ ]
539
+
540
+ # Define tools available for the model to use
541
+ # Type hints and docstrings from Python functions are automatically extracted
542
+ def internet_search(query: str):
543
+ """
544
+ Returns a list of relevant document snippets for a textual query retrieved from the internet
545
+
546
+ Args:
547
+ query: Query to search the internet with
548
+ """
549
+ pass
550
+
551
+ def directly_answer():
552
+ """
553
+ Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history
554
+ """
555
+ pass
556
+
557
+ tools = [internet_search, directly_answer]
558
+
559
+ # render the tool use prompt as a string:
560
+ tool_use_prompt = tokenizer.apply_chat_template(
561
+ conversation,
562
+ tools=tools,
563
+ tokenize=False,
564
+ add_generation_prompt=True,
565
+ )
566
+ print(tool_use_prompt)
567
+ ```
568
+
569
+ </details>
570
+
571
+ <details>
572
+ <summary><b>Example Rendered Single-Step Tool Use Prompt [CLICK TO EXPAND]</b></summary>
573
+
574
+ ````
575
+ <BOS_TOKEN><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
576
+ The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
577
+
578
+ # System Preamble
579
+ ## Basic Rules
580
+ You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.
581
+
582
+ # User Preamble
583
+ ## Task and Context
584
+ You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.
585
+
586
+ ## Style Guide
587
+ Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.
588
+
589
+ ## Available Tools
590
+ Here is a list of tools that you have available to you:
591
+
592
+ ```python
593
+ def internet_search(query: str) -> List[Dict]:
594
+ """Returns a list of relevant document snippets for a textual query retrieved from the internet
595
+
596
+ Args:
597
+ query (str): Query to search the internet with
598
+ """
599
+ pass
600
+ ```
601
+
602
+ ```python
603
+ def directly_answer() -> List[Dict]:
604
+ """Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history
605
+ """
606
+ pass
607
+ ```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Whats the biggest penguin in the world?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Write 'Action:' followed by a json-formatted list of actions that you want to perform in order to produce a good response to the user's last input. You can use any of the supplied tools any number of times, but you should aim to execute the minimum number of necessary actions for the input. You should use the `directly-answer` tool if calling the other tools is unnecessary. The list of actions you want to call should be formatted as a list of json objects, for example:
608
+ ```json
609
+ [
610
+ {
611
+ "tool_name": title of the tool in the specification,
612
+ "parameters": a dict of parameters to input into the tool as they are defined in the specs, or {} if it takes no parameters
613
+ }
614
+ ]```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
615
+ ````
616
+
617
+ </details>
618
+
619
+ <details>
620
+ <summary><b>Example Rendered Single-Step Tool Use Completion [CLICK TO EXPAND]</b></summary>
621
+
622
+ ````
623
+ Action: ```json
624
+ [
625
+ {
626
+ "tool_name": "internet_search",
627
+ "parameters": {
628
+ "query": "biggest penguin in the world"
629
+ }
630
+ }
631
+ ]
632
+ ```
633
+ ````
634
+ </details>
635
+
636
+ ### Multi-Step Tool Use Capabilities ("Agents"):
637
+ Multi-step tool use is suited for building agents that can plan and execute a sequence of actions using multiple tools. Unlike single-step tool use, the model can perform several inference cycles, iterating through Action → Observation → Reflection until it decides on a final response. For more details, refer to our [documentation on multi-step tool use](https://docs.cohere.com/docs/multi-step-tool-use).
638
+
639
+ Command R has been specifically trained with multi-step tool use (or “Agents”) capabilities. These have been trained into the model via a mixture of supervised fine-tuning and preference fine-tuning, using a specific prompt template. Deviating from this prompt template may reduce performance. This is why we recommend using the prompt template described below.
640
+
641
+ The prompt template is not yet available in the HuggingFace tokenizer. However, comprehensive documentation for working with Command R's multi-step tool use prompt template can be found [here](https://docs.cohere.com/docs/prompting-command-r#multi-step-tool-use-with-command-rr-agents) and [here](https://docs.cohere.com/docs/prompting-command-r#multihop-tool-use-with-command-rr-agents).
642
+
643
+
644
+ ### Code Capabilities:
645
+ Command-R has been optimized to interact with your code, by requesting code snippets, code explanations, or code rewrites. It might not perform well out-of-the-box for pure code completion. For better performance, we also recommend using a low temperature (and even greedy decoding) for code-generation related instructions.
646
+
647
+ ### Model Card Contact
648
+ For errors or additional questions about details in this model card, contact labs@cohere.com
649
+
650
+ ### Terms of Use:
651
+ We hope that the release of this model will make community-based research efforts more accessible, by releasing the weights of a highly performant 35 billion parameter model to researchers all over the world. This model is governed by a [CC-BY-NC](https://cohere.com/c4ai-cc-by-nc-license) License with an acceptable use addendum, and also requires adhering to [Cohere Lab's Acceptable Use Policy](https://docs.cohere.com/docs/c4ai-acceptable-use-policy).
652
+
653
+ ### Try Chat:
654
+ You can try Command-R chat in the playground [here](https://dashboard.cohere.com/playground/chat).