From 5e7c6f8d56ed4fc153dfe61a653be1821e2f47c9 Mon Sep 17 00:00:00 2001 From: fern-bot Date: Wed, 21 Aug 2024 07:18:12 -0400 Subject: [PATCH 1/2] hidden page styling --- fern/assets/input.css | 37 ++- fern/fern.config.json | 2 +- .../prompting-command-r.mdx | 298 ++++++++++-------- 3 files changed, 182 insertions(+), 155 deletions(-) diff --git a/fern/assets/input.css b/fern/assets/input.css index e6f3e04bf..44eeecdc5 100644 --- a/fern/assets/input.css +++ b/fern/assets/input.css @@ -541,10 +541,10 @@ button[class^="Sidebar-link-buttonWrapper"] { color: #cc0100 !important; } .bloody-red-text { - color: #a31515; + color: #a31515 !important; } .dark-pink-text { - color: #b80672; + color: #b80672 !important; } .magenta-text { color: #cc669f !important; @@ -566,7 +566,7 @@ button[class^="Sidebar-link-buttonWrapper"] { color: #6aa84f !important; } .grass-green-text { - color: #38761d; + color: #38761d !important; } .dark-green-text { color: #284e13 !important; @@ -608,18 +608,27 @@ button[class^="Sidebar-link-buttonWrapper"] { line-height:100% !important; } .yellow-highlight{ - background-color: yellow; - display: inline-block; - width: 100px; /* Adjust the width as needed */ - /*height: 20px;*/ /* Adjust the height as needed */ + background-color: yellow !important; + display: inline-block !important; + width: 100px !important; /* Adjust the width as needed */ + /*height: 20px !important;*/ /* Adjust the height as needed */ } .code-block { - background-color: rgb(233 230 222); - border-width: 1px; - border-style: solid; - border-color: rgb(228 222 210); + background-color: rgb(233 230 222) !important; + border-width: 1px !important; + border-style: solid !important; + border-color: rgb(228 222 210) !important; display: block !important; - overflow: auto; - padding: 1em; - border-radius:3px; + overflow: auto !important; + padding: 1em !important; + border-radius:3px !important; } + +.extra-yellow { + color: #a31515 !important; + background-color: #ffff00 !important; +} + +.extra-green { + color: #38761d !important; +} \ No newline at end of file diff --git a/fern/fern.config.json b/fern/fern.config.json index b2435708d..f66e5769b 100644 --- a/fern/fern.config.json +++ b/fern/fern.config.json @@ -1,4 +1,4 @@ { "organization": "cohere", - "version": "0.39.4" + "version": "0.39.13" } \ No newline at end of file diff --git a/fern/pages/text-generation/prompt-engineering/prompting-command-r.mdx b/fern/pages/text-generation/prompt-engineering/prompting-command-r.mdx index 3cd698b64..631bd043a 100644 --- a/fern/pages/text-generation/prompt-engineering/prompting-command-r.mdx +++ b/fern/pages/text-generation/prompt-engineering/prompting-command-r.mdx @@ -17,7 +17,7 @@ The easiest way to make sure your prompts will work well with Command R is to us ## Structured Prompts for RAG -Before going into detail on the different components of the prompt and how they fit together, let’s start by looking at a fully rendered prompt. Let’s take an example of using Command R for a simple RAG use case where we are given a user query like: What’s the biggest penguin in the world? +Before going into detail on the different components of the prompt and how they fit together, let’s start by looking at a fully rendered prompt. Let’s take an example of using Command R for a simple RAG use case where we are given a user query like: What’s the biggest penguin in the world? To solve this problem, we will use the model to perform the two steps of RAG: @@ -26,63 +26,70 @@ To solve this problem, we will use the model to perform the two steps of RAG: ### Fully Rendered Default Tool-use Prompt -Let’s start with retrieval, where the model will make calls to an internet_search tool to collect relevant documents needed to answer the user’s question. To enable that, we will create a rendered tool use prompt that will give the model access to two tools: +Let’s start with retrieval, where the model will make calls to an internet_search tool to collect relevant documents needed to answer the user’s question. To enable that, we will create a rendered tool use prompt that will give the model access to two tools: -- def internet_search(query: str) -- def directly_answer() +- def internet_search(query: str) +- def directly_answer() Let's take a look at what this fully rendered prompt would look like using our default settings. -Note that you could get the same result if you were using the HuggingFace Tokenizer’s apply_tool_use_template and setting the conversation and tools parameters. +Note that you could get the same result if you were using the HuggingFace Tokenizer’s apply_tool_use_template and setting the conversation and tools parameters. > tool_use_prompt = > -> """\\<|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. +> """\ \<|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. +> # 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. +> # 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. +> ## 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 PYTHON +> ## Available Tools +> Here is a list of tools that you have available to you: +> +>

+> \`\`\`python 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 PYTHON +>

+> \`\`\`python 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|> What's 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: +> \<|END_OF_TURN_TOKEN|> \<|START_OF_TURN_TOKEN|>\<|USER_TOKEN|> +> What's 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 JSON -> [ -> { +>

+> \`\`\`json 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|>""" +> \<|END_OF_TURN_TOKEN|>""" ### Structured Prompt Templates @@ -90,52 +97,57 @@ The fully rendered prompt above contains a lot of information but it is actually > tool_prompt_template = > -> """\ \<|START_OF_TURN_TOKEN|> -> \<|SYSTEM_TOKEN|> \# Safety Preamble -> \{SAFETY_PREAMBLE} +> """\ \<|START_OF_TURN_TOKEN|> +> \<|SYSTEM_TOKEN|> # Safety Preamble +> \{SAFETY_PREAMBLE} +> +>
+> +> # System Preamble +> +> ## Basic Rules +> \{BASIC_RULES} +> > -> \# System Preamble -> \## Basic Rules -> \{BASIC_RULES} +> # User Preamble > -> \# User Preamble -> \## Task and Context -> \{TASK_CONTEXT} +> ## Task and Context +> \{TASK_CONTEXT} > -> \## Style Guide -> \{STYLE_GUIDE} +> +> ## Style Guide +> \{STYLE_GUIDE} > -> \## Available Tools -> \{TOOLS} -> -> \<|END_OF_TURN_TOKEN|> \{CHAT_HISTORY} \<|START_OF_TURN_TOKEN|> -> \<|SYSTEM_TOKEN|> \{INSTRUCTIONS}\<|END_OF_TURN_TOKEN|>""" +> +> ## Available Tools +> +> \{TOOLS} +> \<|END_OF_TURN_TOKEN|> \{CHAT_HISTORY} \<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|> \{INSTRUCTIONS}\<|END_OF_TURN_TOKEN|>""" -We can see that the prompt is set up in a structured way where we have sections for things like the basic rules we want the model to follow, the task we want it to solve, and the style in which it should write its output in. +We can see that the prompt is set up in a structured way where we have sections for things like the basic rules we want the model to follow, the task we want it to solve, and the style in which it should write its output in. We will take a closer look at these sections later but first lets see how the template changes when we shift from tool use to the second stage of RAG: augmented generation. > augmented_gen_prompt_template = > -> """\ \<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|> \# Safety Preamble -> \{SAFETY_PREAMBLE} +> """\ \<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|> # Safety Preamble +> \{SAFETY_PREAMBLE} > -> \# System Preamble -> \## Basic Rules -> \{BASIC_RULES} +> # System Preamble +> ## Basic Rules +> \{BASIC_RULES} > -> \# User Preamble -> \## Task and Context -> \{TASK_CONTEXT} +> # User Preamble +> ## Task and Context +> \{TASK_CONTEXT} > -> \## Style Guide -> \{STYLE_GUIDE} +> ## Style Guide +> \{STYLE_GUIDE} > ->   > -> \<|END_OF_TURN_TOKEN|> \{CHAT_HISTORY} \<|START_OF_TURN_TOKEN|> \<|SYSTEM_TOKEN|> \{TOOL_OUTPUTS}\<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|> \{INSTRUCTIONS}\<|END_OF_TURN_TOKEN|>""" +> \<|END_OF_TURN_TOKEN|> \{CHAT_HISTORY} \<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|>\{TOOL_OUTPUTS} \<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|> \{INSTRUCTIONS}\<|END_OF_TURN_TOKEN|>""" -Here we can see that the overall structure of the template is very similar between tool use and augmented generation. There are, however, two spots that differ which are highlighted. The first is that we have removed the tool definitions which come after the style guide (you can see that there's no longer an ## Available Tools section), and the second is that we’ve added the TOOL_OUTPUTS retrieved from search after the chat history. +Here we can see that the overall structure of the template is very similar between tool use and augmented generation. There are, however, two spots that differ which are highlighted. The first is that we have removed the tool definitions which come after the style guide (you can see that there's no longer an ## Available Tools section), and the second is that we’ve added the TOOL_OUTPUTS retrieved from search after the chat history. ## Formatting Chat History and Tool Outputs @@ -143,30 +155,31 @@ For our augmented generation call we will need to render both our chat history a ### Chat History -The rendered chat history is quite simple and the only thing to note is that each turn of the conversation should begin with a \<|START_OF_TURN_TOKEN|> followed by one of \<|USER_TOKEN|>, \<|CHATBOT_TOKEN|>, or \<|SYSTEM_TOKEN|> (depending on the role of the speaker), and finally \<|END_OF_TURN_TOKEN|>. +The rendered chat history is quite simple and the only thing to note is that each turn of the conversation should begin with a \<|START_OF_TURN_TOKEN|> followed by one of \<|USER_TOKEN|>, \<|CHATBOT_TOKEN|>, or \<|SYSTEM_TOKEN|> (depending on the role of the speaker), and finally \<|END_OF_TURN_TOKEN|>. -> rendered_chat_history = +> rendered_chat_history = > -> """\<|END_OF_TURN_TOKEN|> \<|START_OF_TURN_TOKEN|>\<|USER_TOKEN|> What's the biggest penguin in the world? \<|END_OF_TURN_TOKEN|>""" +> +> """\<|END_OF_TURN_TOKEN|> \<|START_OF_TURN_TOKEN|>\<|USER_TOKEN|> What's the biggest penguin in the world? \<|END_OF_TURN_TOKEN|>""" ### Tool outputs -The tool outputs should be wrapped in a \<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|>\ \{TOOL_OUTPUTS}\<|END_OF_TURN_TOKEN|> and look something like: +The tool outputs should be wrapped in a \<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|>\ \{TOOL_OUTPUTS}\<|END_OF_TURN_TOKEN|> and look something like: -> rendered_tool_outputs = +> rendered_tool_outputs = > -> """\<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|> -> \ -> Document: 0 -> Tall penguins -> Emperor penguins are the tallest growing up to 122 cm in height.\*\* +> """\<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|> +> \ +> Document: 0 +> Tall penguins +> Emperor penguins are the tallest growing up to 122 cm in height.\*\* > -> Document: 1 -> Penguin habitats -> Emperor penguins only live in Antarctica. -> \\<|END_OF_TURN_TOKEN|>""" +> Document: 1 +> Penguin habitats +> Emperor penguins only live in Antarctica. +> \\<|END_OF_TURN_TOKEN|>""" -Each tool output should start with Document: \{n} and should be an ascending list of integers starting at 0. You can put all kinds of different things as a tool output. In our example, the tool outputs are simple key-value string-string pairs. In general keys should be relatively short descriptive strings, but values can have a lot of variety - e.g. markdown tables or json. +Each tool output should start with Document: \{n} and should be an ascending list of integers starting at 0. You can put all kinds of different things as a tool output. In our example, the tool outputs are simple key-value string-string pairs. In general keys should be relatively short descriptive strings, but values can have a lot of variety - e.g. markdown tables or json. ## Changing sections of the Prompt @@ -178,84 +191,84 @@ Next let’s go into a bit more detail about the different components and sectio #### Special Tokens -- ``: This is a special token used by Command R models to signify the beginning of a prompt. When using raw_prompting, you should always start with this token. -- `<|START_OF_TURN_TOKEN|>`: This special token is used at the beginning of something said by either the USER, SYSTEM, or CHATBOT. -- `<|USER_TOKEN|>`: This should immediately follow `` and signifies that the following output is meant to be from the user such as a query. -- `<|SYSTEM_TOKEN|>`: Same as the `USER` token but indicating some system instruction. -- `<|CHATBOT_TOKEN|>`: same as `USER` and `SYSTEM` token but indicating a chatbot output. -- `<|END_OF_TURN_TOKEN|>`: This will immediately follow the content of a `USER`, `CHATBOT`, or `SYSTEM` turn. +- ``: This is a special token used by Command R models to signify the beginning of a prompt. When using raw_prompting, you should always start with this token. +- `<|START_OF_TURN_TOKEN|>`: This special token is used at the beginning of something said by either the USER, SYSTEM, or CHATBOT. +- `<|USER_TOKEN|>`: This should immediately follow `` and signifies that the following output is meant to be from the user such as a query. +- `<|SYSTEM_TOKEN|>`: Same as the `USER` token but indicating some system instruction. +- `<|CHATBOT_TOKEN|>`: same as `USER` and `SYSTEM` token but indicating a chatbot output. +- `<|END_OF_TURN_TOKEN|>`: This will immediately follow the content of a `USER`, `CHATBOT`, or `SYSTEM` turn. #### Preamble Sections -> \# Safety Preamble: This will outline the safety instructions to the model to instruct it not to produce harmful outputs. +> # Safety Preamble: This will outline the safety instructions to the model to instruct it not to produce harmful outputs. > -> \# System Preamble: System specified rules. -> \## Basic Rules: This outlines how the model should behave in general. +> # System Preamble: System specified rules. +> ## Basic Rules: This outlines how the model should behave in general. > -> \# User Preamble: User specified rules. -> \## Task and Context: Here we outline the specific task it is that we want the model to solve and any additional required context. +> # User Preamble: User specified rules. +> ## Task and Context: Here we outline the specific task it is that we want the model to solve and any additional required context. > -> \## Style Guide: Here we tell the model what the output should look like for example ‘respond in full sentences’ or ‘respond like a pirate’. +> ## Style Guide: Here we tell the model what the output should look like for example ‘respond in full sentences’ or ‘respond like a pirate’. > -> \## Available Tools: If applicable, this will contain definitions of the tools available to the model to use. +> ## Available Tools: If applicable, this will contain definitions of the tools available to the model to use. > -> \{CHAT_HISTORY}: This will contain the current dialogue so far and include user queries plus any responses from the model. +> \{CHAT_HISTORY}: This will contain the current dialogue so far and include user queries plus any responses from the model. > -> \{TOOL_OUTPUTS}: This is where we would add any rendered tool outputs, such as returned documents from a search. +> \{TOOL_OUTPUTS}: This is where we would add any rendered tool outputs, such as returned documents from a search. > -> \{INSTRUCTIONS}: These are the specific instructions that the model should follow when producing its output. For example, we could tell the model that it should produce a tool function call in a particular format, or for augmented generation, we could tell the model to generate an answer along with citations. +> \{INSTRUCTIONS}: These are the specific instructions that the model should follow when producing its output. For example, we could tell the model that it should produce a tool function call in a particular format, or for augmented generation, we could tell the model to generate an answer along with citations. Now that we’ve looked at a high level of the structured prompt and what each of the sections mean, let's see how we can change the content of different sections to get the model to do different things. ### Changing the Output Format: Citation Style -The default instructions for augmented generation (such as in the HuggingFace Tokenizer) uses the following INSTRUCTIONS: +The default instructions for augmented generation (such as in the HuggingFace Tokenizer) uses the following INSTRUCTIONS: -> AUGMENTED_GENERATION_DEFAULT_INSTRUCTIONS = +> AUGMENTED_GENERATION_DEFAULT_INSTRUCTIONS = > -> "Carefully perform the following instructions, in order, starting each with a new line. -> 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'. -> 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'. -> 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. -> Finally, Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbols \ and \ to indicate when a fact comes from a document in the search result, e.g \my fact\ for a fact from document 0." +> "Carefully perform the following instructions, in order, starting each with a new line. +> 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'. +> 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'. +> 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. +> Finally, Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbols \ and \ to indicate when a fact comes from a document in the search result, e.g \my fact\ for a fact from document 0." This default instruction will tell the model to generate four things: 1. A list of docs relevant to the query. 2. A list of docs that will be cited in the answer. 3. A plain text answer to the question -4. A grounded answer which includes citations with the format `my fact`. +4. A grounded answer which includes citations with the format `my fact`. This will lead the model to produce an output like: -> 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 \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.\ +> 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 \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.\ We can easily change the output format of the model by modifying the instruction in our prompt. Let’s get rid of the relevant and cited doc outputs as well as the raw answer. For the remaining grounded answer, let’s change the citation format to be brackets. -> MODIFIED_AUGMENTED_GENERATION_INSTRUCTIONS = +> MODIFIED_AUGMENTED_GENERATION_INSTRUCTIONS = > -> "Carefully perform the following instructions, in order, starting each with a new line. -> Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbol [doc] to indicate when a fact comes from a document in the search result, e.g my fact [0] for a fact from document 0." +> "Carefully perform the following instructions, in order, starting each with a new line. +> Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbol [doc] to indicate when a fact comes from a document in the search result, e.g my fact [0] for a fact from document 0." This will have the model output something like this: -> Grounded answer: The Emperor Penguin[0] is the tallest[0] or biggest penguin in the world. It is a bird that lives only in Antarctica[1] and grows to a height of around 122 centimetres.[0] +> Grounded answer: The Emperor Penguin[0] is the tallest[0] or biggest penguin in the world. It is a bird that lives only in Antarctica[1] and grows to a height of around 122 centimetres.[0] ### Changing the Style -In addition to changing the format of the output, we can also easily change the style by modifying the STYLE_GUIDE. +In addition to changing the format of the output, we can also easily change the style by modifying the STYLE_GUIDE. -> MODIFIED_STYLE_GUIDE = +> MODIFIED_STYLE_GUIDE = > -> """## Style Guide -> Answer in the style of David Attenborough.""" +> “””## Style Guide +> Answer in the style of David Attenborough.””” Which will have the model instead produce this majestic response: -> Grounded answer: And here, emerging from the icy waters, is the majestic emperor penguin, the largest species of its kind. Growing to an impressive height of 122 centimeters[0], these majestic birds rule the Antarctic[1] oceans. Their imposing stature and proud demeanor make them a sight to behold. +> Grounded answer: And here, emerging from the icy waters, is the majestic emperor penguin, the largest species of its kind. Growing to an impressive height of 122 centimeters[0], these majestic birds rule the Antarctic[1] oceans. Their imposing stature and proud demeanor make them a sight to behold. Inspiring. @@ -265,48 +278,53 @@ Grounded summarization is very similar to augmented generation; in both settings In grounded summarization, as the name implies, we instead want to create a summary of those documents. Additionally, unlike a set of search results, the order of the document chunks that the model receives actually matters. -Starting from our augmented generation prompt, we can improve it a bit by changing the TASK_CONTEXT to better fit what we want the model to do. +Starting from our augmented generation prompt, we can improve it a bit by changing the TASK_CONTEXT to better fit what we want the model to do. -> TASK_CONTEXT = +> TASK_CONTEXT = > -> "You will receive a series of text fragments from an article that are presented in chronological order. As the assistant, you must generate responses to user's requests based on the information given in the fragments. Ensure that your responses are accurate and truthful, and that you reference your sources where appropriate to answer the queries, regardless of their complexity." +> "You will receive a series of text fragments from an article that are presented in chronological order. As the assistant, you must generate responses to user's requests based on the information given in the fragments. Ensure that your responses are accurate and truthful, and that you reference your sources where appropriate to answer the queries, regardless of their complexity." > -> CHAT_HISTORY = +> CHAT_HISTORY = > -> "\<|END_OF_TURN_TOKEN|> \<|START_OF_TURN_TOKEN|>\<|USER_TOKEN|> Summarize the documents in 20 words or less. \<|END_OF_TURN_TOKEN|>" +> "\<|END_OF_TURN_TOKEN|> \<|START_OF_TURN_TOKEN|>\<|USER_TOKEN|> Summarize the documents in 20 words or less. \<|END_OF_TURN_TOKEN|>" Let’s switch back to our original `STYLE_GUIDE` and see what the fully rendered prompt looks like: -> \ \<|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. +> \ \<|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. > -> \# 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 > -> \# 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. +> 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. +> ## Style Guide +> 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|> Summarize the documents in 20 words or less.\<|END_OF_TURN_TOKEN|> \<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|> +> \<|END_OF_TURN_TOKEN|> \<|START_OF_TURN_TOKEN|>\<|USER_TOKEN|> Summarize the documents in 20 words or less.\<|END_OF_TURN_TOKEN|> \<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|> > -> \ -> Document: 0 -> Tall penguins -> Emperor penguins are the tallest growing up to 122 cm in height. +> \ +> Document: 0 +> Tall penguins +> Emperor penguins are the tallest growing up to 122 cm in height. > -> Document: 1 -> Penguin habitats -> Emperor penguins only live in Antarctica. -> \\<|END_OF_TURN_TOKEN|>\<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line. -> Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbol [doc] to indicate when a fact comes from a document in the search result, e.g my fact[0] for a fact from document 0.\<|END_OF_TURN_TOKEN|> +> Document: 1 +> Penguin habitats +> Emperor penguins only live in Antarctica. +> \\<|END_OF_TURN_TOKEN|>\<|START_OF_TURN_TOKEN|>\<|SYSTEM_TOKEN|> +> +> Carefully perform the following instructions, in order, starting each with a new line. +> Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbol [doc] to indicate when a fact comes from a document in the search result, e.g my fact[0] for a fact from document 0. +> +> \<|END_OF_TURN_TOKEN|> And this has the model output: -> Grounded answer: Emperor penguins, the tallest species, grow up to 122 cm tall[0] and only live in Antarctica.[1]. +> Grounded answer: Emperor penguins, the tallest species, grow up to 122 cm tall[0] and only live in Antarctica.[1]. ## Appendix @@ -357,4 +375,4 @@ def render_chat_history(_conversation: list[dict]) -> str: rendered_chat_history = render_chat_history(conversation) -``` +``` \ No newline at end of file From 14a29ffd99a6d79f466481e9287f2ac7239e856d Mon Sep 17 00:00:00 2001 From: fern-bot Date: Wed, 21 Aug 2024 07:49:32 -0400 Subject: [PATCH 2/2] add indentation --- .../prompting-command-r.mdx | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fern/pages/text-generation/prompt-engineering/prompting-command-r.mdx b/fern/pages/text-generation/prompt-engineering/prompting-command-r.mdx index 631bd043a..cef0a2ed3 100644 --- a/fern/pages/text-generation/prompt-engineering/prompting-command-r.mdx +++ b/fern/pages/text-generation/prompt-engineering/prompting-command-r.mdx @@ -57,20 +57,20 @@ Note that you could get the same result if you were using the HuggingFace Tokeni >

 > \`\`\`python 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
+>      """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 PYTHON
 > def directly_answer() -> List[Dict]:
->     """Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history
->     """
->     pass
+>      """Calls a standard (un-augmented) AI chatbot to generate a response given the conversation history
+>      """
+>      pass
 > \`\`\`
 > 
> @@ -81,10 +81,10 @@ Note that you could get the same result if you were using the HuggingFace Tokeni >

 > \`\`\`json 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
->     \}
+>      \{
+>           "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
+>      \}
 > \]
 > \`\`\`
 >