jartine commited on
Commit
b395f74
1 Parent(s): 5017590

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +457 -0
README.md ADDED
@@ -0,0 +1,457 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: CohereForAI/c4ai-command-r-plus
3
+ model_creator: CohereForAI
4
+ quantized_by: jartine
5
+ license: other
6
+ license_link: LICENSE
7
+ library_name: transformers
8
+ pipeline_tag: text-generation
9
+ prompt_template: |
10
+ <BOS_TOKEN>
11
+ <|START_OF_TURN_TOKEN|>
12
+ <|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|>
13
+ <|START_OF_TURN_TOKEN|>
14
+ <|CHATBOT_TOKEN|>
15
+ tags:
16
+ - llamafile
17
+ language:
18
+ - en
19
+ - fr
20
+ - de
21
+ - es
22
+ - it
23
+ - pt
24
+ - ja
25
+ - ko
26
+ - zh
27
+ - ar
28
+ ---
29
+
30
+ # c4ai-command-r-plus - llamafile
31
+
32
+ This repository contains executable weights (which we call
33
+ [llamafiles](https://github.com/Mozilla-Ocho/llamafile)) that run on
34
+ Linux, MacOS, Windows, FreeBSD, OpenBSD, and NetBSD for AMD64 and ARM64.
35
+
36
+ - Model creator: [Microsoft](https://huggingface.co/microsoft)
37
+ - Original model: [microsoft/c4ai-command-r-plus](https://huggingface.co/microsoft/c4ai-command-r-plus)
38
+
39
+ ## Quickstart
40
+
41
+ You can run the following command which download, concatenate, and
42
+ execute the model.
43
+
44
+ ```
45
+ # todo: curl
46
+ chmod +x c4ai-command-r-plus.Q2_K.llamafile
47
+ ./c4ai-command-r-plus.Q2_K.llamafile --help # view manual
48
+ ./c4ai-command-r-plus.Q2_K.llamafile # launch web gui + oai api
49
+ ./c4ai-command-r-plus.Q2_K.llamafile -p ... # cli interface (scriptable)
50
+ ```
51
+
52
+ Alternatively, you may download an official `llamafile` executable from
53
+ Mozilla Ocho on GitHub, in which case you can use the Mixtral llamafiles
54
+ as a simple weights data file.
55
+
56
+ ```
57
+ llamafile -m ./c4ai-command-r-plus.Q2_K.llamafile ...
58
+ ```
59
+
60
+ For further information, please see the [llamafile
61
+ README](https://github.com/mozilla-ocho/llamafile/).
62
+
63
+ Having **trouble?** See the ["Gotchas"
64
+ section](https://github.com/mozilla-ocho/llamafile/?tab=readme-ov-file#gotchas)
65
+ of the README.
66
+
67
+ ## Prompting
68
+
69
+ Prompt template:
70
+
71
+ ```
72
+ <BOS_TOKEN>
73
+ <|START_OF_TURN_TOKEN|>
74
+ <|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|>
75
+ <|START_OF_TURN_TOKEN|>
76
+ <|CHATBOT_TOKEN|>
77
+ ```
78
+
79
+ ## About llamafile
80
+
81
+ llamafile is a new format introduced by Mozilla Ocho on Nov 20th 2023.
82
+ It uses Cosmopolitan Libc to turn LLM weights into runnable llama.cpp
83
+ binaries that run on the stock installs of six OSes for both ARM64 and
84
+ AMD64.
85
+
86
+ In addition to being executables, llamafiles are also zip archives. Each
87
+ llamafile contains a GGUF file, which you can extract using the `unzip`
88
+ command. If you want to change or add files to your llamafiles, then the
89
+ `zipalign` command (distributed on the llamafile github) should be used
90
+ instead of the traditional `zip` command.
91
+
92
+ ## About Quantization Formats (General Advice)
93
+
94
+ Your choice of quantization format depends on three things:
95
+
96
+ 1. Will it fit in RAM or VRAM?
97
+ 2. Is your use case reading (e.g. summarization) or writing (e.g. chatbot)?
98
+ 3. llamafiles bigger than 4.30 GB are hard to run on Windows (see [gotchas](https://github.com/mozilla-ocho/llamafile/?tab=readme-ov-file#gotchas))
99
+
100
+ Good quants for writing (prediction speed) are Q5\_K\_M, and Q4\_0. Text
101
+ generation is bounded by memory speed, so smaller quants help, but they
102
+ cause the LLM to hallucinate more. However that doesn't mean they can't
103
+ think correctly. A highly degraded quant like `Q2_K` may not make a
104
+ great encyclopedia, but it's still capable of logical reasoning and
105
+ the emergent capabilities LLMs exhibit.
106
+
107
+ Good quants for reading (evaluation speed) are BF16, F16, Q8\_0, and
108
+ Q4\_0 (ordered from fastest to slowest). Prompt evaluation is bounded by
109
+ flop count, which means perf can be improved through software
110
+ engineering alone, e.g. BLAS algorithms, in which case quantization
111
+ starts hurting more than it helps, since it competes for CPU resources
112
+ and makes it harder for the compiler to parallelize instructions. You
113
+ want to ideally use the simplest smallest floating point format that's
114
+ natively implemented by your hardware. In most cases, that's BF16 or
115
+ FP16. However, llamafile is able to still offer respectable tinyBLAS
116
+ speedups for llama.cpp's simplest quants: Q8\_0 and Q4\_0.
117
+
118
+ ---
119
+
120
+ # Model Card for C4AI Command R+
121
+
122
+ 🚨 **This model is non-quantized version of C4AI Command R+. You can find the quantized version of C4AI Command R+ using bitsandbytes [here](https://huggingface.co/CohereForAI/c4ai-command-r-plus-4bit)**.
123
+
124
+
125
+ ## Model Summary
126
+
127
+ C4AI Command R+ is an open weights research release of a 104B billion parameter model with highly advanced capabilities, this includes Retrieval Augmented Generation (RAG) and tool use to automate sophisticated tasks. The tool use in this model generation enables multi-step tool use which allows the model to combine multiple tools over multiple steps to accomplish difficult tasks. C4AI Command R+ is a multilingual model evaluated in 10 languages for performance: English, French, Spanish, Italian, German, Brazilian Portuguese, Japanese, Korean, Arabic, and Simplified Chinese. Command R+ is optimized for a variety of use cases including reasoning, summarization, and question answering.
128
+
129
+ C4AI Command R+ is part of a family of open weight releases from Cohere For AI and Cohere. Our smaller companion model is [C4AI Command R](https://huggingface.co/CohereForAI/c4ai-command-r-v01)
130
+
131
+ Developed by: [Cohere](https://cohere.com/) and [Cohere For AI](https://cohere.for.ai)
132
+
133
+ - Point of Contact: Cohere For AI: [cohere.for.ai](https://cohere.for.ai/)
134
+ - License: [CC-BY-NC](https://cohere.com/c4ai-cc-by-nc-license), requires also adhering to [C4AI's Acceptable Use Policy](https://docs.cohere.com/docs/c4ai-acceptable-use-policy)
135
+ - Model: c4ai-command-r-plus
136
+ - Model Size: 104 billion parameters
137
+ - Context length: 128K
138
+
139
+ **Try C4AI Command R+**
140
+
141
+ You can try out C4AI Command R+ before downloading the weights in our hosted [Hugging Face Space](https://huggingface.co/spaces/CohereForAI/c4ai-command-r-plus).
142
+
143
+ **Usage**
144
+
145
+ Please install `transformers` from the source repository that includes the necessary changes for this model.
146
+ ```python
147
+ # pip install 'git+https://github.com/huggingface/transformers.git'
148
+ from transformers import AutoTokenizer, AutoModelForCausalLM
149
+
150
+ model_id = "CohereForAI/c4ai-command-r-plus"
151
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
152
+ model = AutoModelForCausalLM.from_pretrained(model_id)
153
+
154
+ # Format message with the command-r-plus chat template
155
+ messages = [{"role": "user", "content": "Hello, how are you?"}]
156
+ input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
157
+ ## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
158
+
159
+ gen_tokens = model.generate(
160
+ input_ids,
161
+ max_new_tokens=100,
162
+ do_sample=True,
163
+ temperature=0.3,
164
+ )
165
+
166
+ gen_text = tokenizer.decode(gen_tokens[0])
167
+ print(gen_text)
168
+ ```
169
+
170
+ **Quantized model through bitsandbytes, 8-bit precision**
171
+
172
+ ```python
173
+ # pip install 'git+https://github.com/huggingface/transformers.git' bitsandbytes accelerate
174
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
175
+
176
+ bnb_config = BitsAndBytesConfig(load_in_8bit=True)
177
+
178
+ model_id = "CohereForAI/c4ai-command-r-plus"
179
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
180
+ model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config)
181
+
182
+ # Format message with the command-r-plus chat template
183
+ messages = [{"role": "user", "content": "Hello, how are you?"}]
184
+ input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
185
+ ## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
186
+
187
+ gen_tokens = model.generate(
188
+ input_ids,
189
+ max_new_tokens=100,
190
+ do_sample=True,
191
+ temperature=0.3,
192
+ )
193
+
194
+ gen_text = tokenizer.decode(gen_tokens[0])
195
+ print(gen_text)
196
+ ```
197
+
198
+ **Quantized model through bitsandbytes, 4-bit precision**
199
+
200
+ This model is non-quantized version of C4AI Command R+. You can find the quantized version of C4AI Command R+ using bitsandbytes [here](https://huggingface.co/CohereForAI/c4ai-command-r-plus-4bit).
201
+
202
+ ## Model Details
203
+
204
+ **Input**: Models input text only.
205
+
206
+ **Output**: Models generate text only.
207
+
208
+ **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.
209
+
210
+ **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.
211
+
212
+ Pre-training data additionally included the following 13 languages: Russian, Polish, Turkish, Vietnamese, Dutch, Czech, Indonesian, Ukrainian, Romanian, Greek, Hindi, Hebrew, Persian.
213
+
214
+ **Context length**: Command R+ supports a context length of 128K.
215
+
216
+ ## Evaluations
217
+
218
+ Command R+ has been submitted to the [Open LLM leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard). We include the results below, along with a direct comparison to the strongest state-of-art open weights models currently available on Hugging Face. We note that these results are only useful to compare when evaluations are implemented for all models in a [standardized way](https://github.com/EleutherAI/lm-evaluation-harness) using publically available code, and hence shouldn't be used for comparison outside of models submitted to the leaderboard or compared to self-reported numbers which can't be replicated in the same way.
219
+
220
+ | Model | Average | Arc (Challenge) | Hella Swag | MMLU | Truthful QA | Winogrande | GSM8k |
221
+ |:--------------------------------|----------:|------------------:|-------------:|-------:|--------------:|-------------:|--------:|
222
+ | **CohereForAI/c4ai-command-r-plus** | 74.6 | 70.99 | 88.6 | 75.7 | 56.3 | 85.4 | 70.7 |
223
+ | [DBRX Instruct](https://huggingface.co/databricks/dbrx-instruct) | 74.5 | 68.9 | 89 | 73.7 | 66.9 | 81.8 | 66.9 |
224
+ | [Mixtral 8x7B-Instruct](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1) | 72.7 | 70.1 | 87.6 | 71.4 | 65 | 81.1 | 61.1 |
225
+ | [Mixtral 8x7B Chat](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1) | 72.6 | 70.2 | 87.6 | 71.2 | 64.6 | 81.4 | 60.7 |
226
+ | [CohereForAI/c4ai-command-r-v01](https://huggingface.co/CohereForAI/c4ai-command-r-v01) | 68.5 | 65.5 | 87 | 68.2 | 52.3 | 81.5 | 56.6 |
227
+ | [Llama 2 70B](https://huggingface.co/meta-llama/Llama-2-70b-hf) | 67.9 | 67.3 | 87.3 | 69.8 | 44.9 | 83.7 | 54.1 |
228
+ | [Yi-34B-Chat](https://huggingface.co/01-ai/Yi-34B-Chat) | 65.3 | 65.4 | 84.2 | 74.9 | 55.4 | 80.1 | 31.9 |
229
+ | [Gemma-7B](https://huggingface.co/google/gemma-7b) | 63.8 | 61.1 | 82.2 | 64.6 | 44.8 | 79 | 50.9 |
230
+ | [LLama 2 70B Chat](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf) | 62.4 | 64.6 | 85.9 | 63.9 | 52.8 | 80.5 | 26.7 |
231
+ | [Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) | 61 | 60 | 83.3 | 64.2 | 42.2 | 78.4 | 37.8 |
232
+
233
+ We include these metrics here because they are frequently requested, but note that these metrics do not capture RAG, multilingual, tooling performance or the evaluation of open ended generations which we believe Command R+ to be state-of-art at. For evaluations of RAG, multilingual and tooling read more [here](https://txt.cohere.com/command-r-plus-microsoft-azure/). For evaluation of open ended generation, Command R+ is currently being evaluated on the [chatbot arena](https://chat.lmsys.org/).
234
+
235
+ ### Tool use & multihop capabilities:
236
+
237
+ Command R+ has been specifically trained with conversational tool use 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 will likely reduce performance, but we encourage experimentation.
238
+
239
+ Command R+’s 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.
240
+
241
+ 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.
242
+ We recommend including the `directly_answer` tool, but it can be removed or renamed if required.
243
+
244
+ Comprehensive documentation for working with command R+'s tool use prompt template can be found [here](https://docs.cohere.com/docs/prompting-command-r).
245
+
246
+ The code snippet below shows a minimal working example on how to render a prompt.
247
+
248
+ <details>
249
+ <summary><b>Usage: Rendering Tool Use Prompts [CLICK TO EXPAND]</b> </summary>
250
+
251
+ ```python
252
+ from transformers import AutoTokenizer
253
+
254
+ model_id = "CohereForAI/c4ai-command-r-plus"
255
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
256
+
257
+ # define conversation input:
258
+ conversation = [
259
+ {"role": "user", "content": "Whats the biggest penguin in the world?"}
260
+ ]
261
+ # Define tools available for the model to use:
262
+ tools = [
263
+ {
264
+ "name": "internet_search",
265
+ "description": "Returns a list of relevant document snippets for a textual query retrieved from the internet",
266
+ "parameter_definitions": {
267
+ "query": {
268
+ "description": "Query to search the internet with",
269
+ "type": 'str',
270
+ "required": True
271
+ }
272
+ }
273
+ },
274
+ {
275
+ 'name': "directly_answer",
276
+ "description": "Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history",
277
+ 'parameter_definitions': {}
278
+ }
279
+ ]
280
+
281
+ # render the tool use prompt as a string:
282
+ tool_use_prompt = tokenizer.apply_tool_use_template(
283
+ conversation,
284
+ tools=tools,
285
+ tokenize=False,
286
+ add_generation_prompt=True,
287
+ )
288
+ print(tool_use_prompt)
289
+ ```
290
+
291
+ </details>
292
+
293
+ <details>
294
+ <summary><b>Example Rendered Tool Use Prompt [CLICK TO EXPAND]</b></summary>
295
+
296
+ ````
297
+ <BOS_TOKEN><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
298
+ The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
299
+
300
+ # System Preamble
301
+ ## Basic Rules
302
+ 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.
303
+
304
+ # User Preamble
305
+ ## Task and Context
306
+ 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.
307
+
308
+ ## Style Guide
309
+ Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.
310
+
311
+ ## Available Tools
312
+ Here is a list of tools that you have available to you:
313
+
314
+ ```python
315
+ def internet_search(query: str) -> List[Dict]:
316
+ """Returns a list of relevant document snippets for a textual query retrieved from the internet
317
+
318
+ Args:
319
+ query (str): Query to search the internet with
320
+ """
321
+ pass
322
+ ```
323
+
324
+ ```python
325
+ def directly_answer() -> List[Dict]:
326
+ """Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history
327
+ """
328
+ pass
329
+ ```<|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:
330
+ ```json
331
+ [
332
+ {
333
+ "tool_name": title of the tool in the specification,
334
+ "parameters": a dict of parameters to input into the tool as they are defined in the specs, or {} if it takes no parameters
335
+ }
336
+ ]```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
337
+
338
+ ````
339
+
340
+ </details>
341
+
342
+ <details>
343
+ <summary><b>Example Rendered Tool Use Completion [CLICK TO EXPAND]</b></summary>
344
+
345
+ ````
346
+ Action: ```json
347
+ [
348
+ {
349
+ "tool_name": "internet_search",
350
+ "parameters": {
351
+ "query": "biggest penguin in the world"
352
+ }
353
+ }
354
+ ]
355
+ ```
356
+ ````
357
+ </details>
358
+
359
+ ### Grounded Generation and RAG Capabilities:
360
+
361
+ 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. 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. Deviating from this prompt template may reduce performance, but we encourage experimentation.
362
+
363
+ 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. 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.
364
+
365
+ 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. Finally, it will then insert grounding spans into the answer. See below for an example. This is referred to as `accurate` grounded generation.
366
+
367
+ 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.
368
+
369
+ Comprehensive documentation for working with Command R+'s grounded generation prompt template can be found [here](https://docs.cohere.com/docs/prompting-command-r).
370
+
371
+ The code snippet below shows a minimal working example on how to render a prompt.
372
+
373
+ <details>
374
+ <summary> <b>Usage: Rendering Grounded Generation prompts [CLICK TO EXPAND]</b> </summary>
375
+
376
+ ````python
377
+ from transformers import AutoTokenizer
378
+
379
+ model_id = "CohereForAI/c4ai-command-r-plus"
380
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
381
+
382
+ # define conversation input:
383
+ conversation = [
384
+ {"role": "user", "content": "Whats the biggest penguin in the world?"}
385
+ ]
386
+ # define documents to ground on:
387
+ documents = [
388
+ { "title": "Tall penguins", "text": "Emperor penguins are the tallest growing up to 122 cm in height." },
389
+ { "title": "Penguin habitats", "text": "Emperor penguins only live in Antarctica."}
390
+ ]
391
+
392
+ # render the tool use prompt as a string:
393
+ grounded_generation_prompt = tokenizer.apply_grounded_generation_template(
394
+ conversation,
395
+ documents=documents,
396
+ citation_mode="accurate", # or "fast"
397
+ tokenize=False,
398
+ add_generation_prompt=True,
399
+ )
400
+ print(grounded_generation_prompt)
401
+ ````
402
+ </details>
403
+
404
+ <details>
405
+ <summary><b>Example Rendered Grounded Generation Prompt [CLICK TO EXPAND]</b></summary>
406
+
407
+ ````<BOS_TOKEN><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
408
+ The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
409
+
410
+ # System Preamble
411
+ ## Basic Rules
412
+ 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.
413
+
414
+ # User Preamble
415
+ ## Task and Context
416
+ 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.
417
+
418
+ ## Style Guide
419
+ 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>
420
+ Document: 0
421
+ title: Tall penguins
422
+ text: Emperor penguins are the tallest growing up to 122 cm in height.
423
+
424
+ Document: 1
425
+ title: Penguin habitats
426
+ text: Emperor penguins only live in Antarctica.
427
+ </results><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.
428
+ 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'.
429
+ 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'.
430
+ 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.
431
+ 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|>
432
+ ````
433
+
434
+ </details>
435
+
436
+ <details>
437
+ <summary><b>Example Rendered Grounded Generation Completion [CLICK TO EXPAND]</b></summary>
438
+
439
+ ````
440
+ Relevant Documents: 0,1
441
+ Cited Documents: 0,1
442
+ 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.
443
+ 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>
444
+ ````
445
+ </details>
446
+
447
+ ### Code Capabilities:
448
+ 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.
449
+
450
+ ### Model Card Contact
451
+ For errors or additional questions about details in this model card, contact [info@for.ai](mailto:info@for.ai).
452
+
453
+ ### Terms of Use:
454
+ We hope that the release of this model will make community-based research efforts more accessible, by releasing the weights of a highly performant 104 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 [C4AI's Acceptable Use Policy](https://docs.cohere.com/docs/c4ai-acceptable-use-policy).
455
+
456
+ ### Try Chat:
457
+ You can try Command R+ chat in the playground [here](https://dashboard.cohere.com/playground/chat). You can also use it in our dedicated Hugging Face Space [here](https://huggingface.co/spaces/CohereForAI/c4ai-command-r-plus).