Views
No views yet
text-generation-webuihuggingface-hub Python library:pip3 install huggingface-hubhuggingface-cli download LiteLLMs/c4ai-command-r-plus-GGUF Q4_0/Q4_0-00001-of-00009.gguf --local-dir . --local-dir-use-symlinks Falsehuggingface-cli download LiteLLMs/c4ai-command-r-plus-GGUF --local-dir . --local-dir-use-symlinks False --include='*Q4_K*gguf'huggingface-cli, please see: HF -> Hub Python Library -> Download files -> Download from the CLI.hf_transfer:pip3 install huggingface_hub[hf_transfer]HF_HUB_ENABLE_HF_TRANSFER to 1:HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download LiteLLMs/c4ai-command-r-plus-GGUF Q4_0/Q4_0-00001-of-00009.gguf --local-dir . --local-dir-use-symlinks Falseset HF_HUB_ENABLE_HF_TRANSFER=1 before the download command.llama.cpp from commit d0cee0d or later../main -ngl 35 -m Q4_0/Q4_0-00001-of-00009.gguf --color -c 8192 --temp 0.7 --repeat_penalty 1.1 -n -1 -p "<PROMPT>"-ngl 32 to the number of layers to offload to GPU. Remove it if you don't have GPU acceleration.-c 8192 to the desired sequence length. For extended sequence models - eg 8K, 16K, 32K - the necessary RoPE scaling parameters are read from the GGUF file and set by llama.cpp automatically. Note that longer sequence lengths require much more resources, so you may need to reduce this value.-p <PROMPT> argument with -i -instext-generation-webui1# Base ctransformers with no GPU acceleration
2pip install llama-cpp-python
3# With NVidia CUDA acceleration
4CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python
5# Or with OpenBLAS acceleration
6CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" pip install llama-cpp-python
7# Or with CLBLast acceleration
8CMAKE_ARGS="-DLLAMA_CLBLAST=on" pip install llama-cpp-python
9# Or with AMD ROCm GPU acceleration (Linux only)
10CMAKE_ARGS="-DLLAMA_HIPBLAS=on" pip install llama-cpp-python
11# Or with Metal GPU acceleration for macOS systems only
12CMAKE_ARGS="-DLLAMA_METAL=on" pip install llama-cpp-python
13# In windows, to set the variables CMAKE_ARGS in PowerShell, follow this format; eg for NVidia CUDA:
14$env:CMAKE_ARGS = "-DLLAMA_OPENBLAS=on"
15pip install llama-cpp-python1from llama_cpp import Llama
2# Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
3llm = Llama(
4 model_path="./Q4_0/Q4_0-00001-of-00009.gguf", # Download the model file first
5 n_ctx=32768, # The max sequence length to use - note that longer sequence lengths require much more resources
6 n_threads=8, # The number of CPU threads to use, tailor to your system and the resulting performance
7 n_gpu_layers=35 # The number of layers to offload to GPU, if you have GPU acceleration available
8)
9# Simple inference example
10output = llm(
11 "<PROMPT>", # Prompt
12 max_tokens=512, # Generate up to 512 tokens
13 stop=["</s>"], # Example stop token - not necessarily correct for this specific model! Please check before using.
14 echo=True # Whether to echo the prompt
15)
16# Chat Completion API
17llm = Llama(model_path="./Q4_0/Q4_0-00001-of-00009.gguf", chat_format="llama-2") # Set chat_format according to the model you are using
18llm.create_chat_completion(
19 messages = [
20 {"role": "system", "content": "You are a story writing assistant."},
21 {
22 "role": "user",
23 "content": "Write a story about llamas."
24 }
25 ]
26)transformers from the source repository that includes the necessary changes for this model.1# pip install 'git+https://github.com/huggingface/transformers.git'
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_id = "CohereForAI/c4ai-command-r-plus"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(model_id)
7
8# Format message with the command-r-plus chat template
9messages = [{"role": "user", "content": "Hello, how are you?"}]
10input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
11## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
12
13gen_tokens = model.generate(
14 input_ids,
15 max_new_tokens=100,
16 do_sample=True,
17 temperature=0.3,
18 )
19
20gen_text = tokenizer.decode(gen_tokens[0])
21print(gen_text)1# pip install 'git+https://github.com/huggingface/transformers.git' bitsandbytes accelerate
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3
4bnb_config = BitsAndBytesConfig(load_in_8bit=True)
5
6model_id = "CohereForAI/c4ai-command-r-plus"
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config)
9
10# Format message with the command-r-plus chat template
11messages = [{"role": "user", "content": "Hello, how are you?"}]
12input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
13## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
14
15gen_tokens = model.generate(
16 input_ids,
17 max_new_tokens=100,
18 do_sample=True,
19 temperature=0.3,
20 )
21
22gen_text = tokenizer.decode(gen_tokens[0])
23print(gen_text)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.1from transformers import AutoTokenizer
2
3model_id = "CohereForAI/c4ai-command-r-plus"
4tokenizer = AutoTokenizer.from_pretrained(model_id)
5
6# define conversation input:
7conversation = [
8 {"role": "user", "content": "Whats the biggest penguin in the world?"}
9]
10# Define tools available for the model to use:
11tools = [
12 {
13 "name": "internet_search",
14 "description": "Returns a list of relevant document snippets for a textual query retrieved from the internet",
15 "parameter_definitions": {
16 "query": {
17 "description": "Query to search the internet with",
18 "type": 'str',
19 "required": True
20 }
21 }
22 },
23 {
24 'name': "directly_answer",
25 "description": "Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history",
26 'parameter_definitions': {}
27 }
28]
29
30# render the tool use prompt as a string:
31tool_use_prompt = tokenizer.apply_tool_use_template(
32 conversation,
33 tools=tools,
34 tokenize=False,
35 add_generation_prompt=True,
36)
37print(tool_use_prompt)<BOS_TOKEN><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
# System Preamble
## Basic Rules
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.
# User Preamble
## Task and Context
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.
## Style Guide
Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.
## Available Tools
Here is a list of tools that you have available to you:
```python
def internet_search(query: str) -> List[Dict]:
"""Returns a list of relevant document snippets for a textual query retrieved from the internet
Args:
query (str): Query to search the internet with
"""
pass
```
```python
def directly_answer() -> List[Dict]:
"""Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history
"""
pass
```<|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:
```json
[
{
"tool_name": title of the tool in the specification,
"parameters": a dict of parameters to input into the tool as they are defined in the specs, or {} if it takes no parameters
}
]```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
Action: ```json
[
{
"tool_name": "internet_search",
"parameters": {
"query": "biggest penguin in the world"
}
}
]
```accurate grounded generation.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.1from transformers import AutoTokenizer
2
3model_id = "CohereForAI/c4ai-command-r-plus"
4tokenizer = AutoTokenizer.from_pretrained(model_id)
5
6# define conversation input:
7conversation = [
8 {"role": "user", "content": "Whats the biggest penguin in the world?"}
9]
10# define documents to ground on:
11documents = [
12 { "title": "Tall penguins", "text": "Emperor penguins are the tallest growing up to 122 cm in height." },
13 { "title": "Penguin habitats", "text": "Emperor penguins only live in Antarctica."}
14]
15
16# render the tool use prompt as a string:
17grounded_generation_prompt = tokenizer.apply_grounded_generation_template(
18 conversation,
19 documents=documents,
20 citation_mode="accurate", # or "fast"
21 tokenize=False,
22 add_generation_prompt=True,
23)
24print(grounded_generation_prompt)1The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
2
3# System Preamble
4## Basic Rules
5You 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.
6
7# User Preamble
8## Task and Context
9You 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.
10
11## Style Guide
12Unless 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>
13Document: 0
14title: Tall penguins
15text: Emperor penguins are the tallest growing up to 122 cm in height.
16
17Document: 1
18title: Penguin habitats
19text: Emperor penguins only live in Antarctica.
20</results><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.
21Firstly, 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'.
22Secondly, 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'.
23Thirdly, 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.
24Finally, 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|>Relevant Documents: 0,1
Cited Documents: 0,1
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.
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>