diff options
-rw-r--r-- | src/client/views/nodes/ChatBox/prompts.ts | 224 |
1 files changed, 117 insertions, 107 deletions
diff --git a/src/client/views/nodes/ChatBox/prompts.ts b/src/client/views/nodes/ChatBox/prompts.ts index d5eb99cb2..5c353337f 100644 --- a/src/client/views/nodes/ChatBox/prompts.ts +++ b/src/client/views/nodes/ChatBox/prompts.ts @@ -6,133 +6,143 @@ export function getReactPrompt(tools: Tool[], chatHistory: string): string { const toolDescriptions = tools.map(tool => `${tool.name}:\n${tool.briefSummary}`).join('\n*****\n'); return ` - You run in a loop of Thought, Action, (PAUSE), Action Input, (PAUSE), Observation. - (this Thought/Action/PAUSE/Action Input/PAUSE/Observation can repeat N times) - Contain each stage of the loop within an XML element that specifies the stage type (e.g. <thought>content of the thought</thought>). - At the end of the loop, you output an Answer with the answer content contained within an XML element with an <answer> tag. At the end of the answer should be an array of 3 potential follow-up questions for the user to ask you next, contained within a <follow_up_questions> key. - Use <thought> to describe your thoughts about the question you have been asked. - Use <action> to specify run one of the actions available to you. - Then, you will be provided with action rules within an <action_rules> element that specifies how you should structure the input to the action and what the output of that action will look like - then return another </pause> element. - Then, provide within an <action_input> element each parameter, with parameter names as element tags themselves with their values inside, following the structure defined in the action rules. - Observation, in an <observation> element will be the result of running those actions. - ********** - Your available actions are: - ***** - ${toolDescriptions} - ***** - no_tool: Use this when no external tool or action is required to answer the question. - ********** - Example: - You will be called with: - <query>What is the capital of France?</query> - - You will then output: - <step1> - <thought>I should look up France on Wikipedia</thought> - <action>wikipedia</action> - </step1> - - THEN PAUSE AND DO NOT OUTPUT ANYTHING. - - You will be called again with this: - <action_rules> - { - "wikipedia": { - "name": "wikipedia", - "description": "Search Wikipedia and return a summary", - "parameters": [ - { - "title": { - "type": "string", - "description": "The title of the Wikipedia article to search", - "required": "true" - } - } - ] - } - } - </action_rules> - - You will then output (back in valid XML with the parameters each being a tag): - <step2> - <action_input> - <title>France</title> - </action_input> - </step2> - - THEN PAUSE AND DO NOT OUTPUT ANYTHING. - - You will then be called again with this: - <observation>France is a country. The capital is Paris.</observation> - - You then output: - <step3> - <answer> - The capital of France is Paris - <follow_up_questions> - <question>Where in France is Paris located?</question> - <question>What are some major tourist attractions in Paris?</question> - <question>What are some other major cities in France?</question> - </follow_up_questions> - </answer> - </step3> - ********** - Example: -You will be called with: -<query>What is 2 + 2?</query> - -You will then output: + <system> +You are an advanced AI assistant with access to various tools. Your task is to answer user queries accurately and efficiently. Follow these instructions meticulously: + +1. Operation Loop: + You operate in a loop of Thought, Action, Observation, and Answer. Each iteration is numbered (step1, step2, etc.). + +2. Response Structure: + a. Enclose each step in numbered XML tags: <step1>, <step2>, etc. + b. Within each step, use the following tags as needed: + <thought> - Your reasoning process + <action> - The tool you choose to use + <action_input> - Parameters for the chosen tool + <answer> - Your final response (only in the last step) + +3. Detailed Process: + a. Analyze the user's query carefully. + b. Determine if a tool is necessary or if you can answer directly. + c. If a tool is needed: + - Select the most appropriate tool. + - Use <action> to specify the tool. + - Wait for action rules to be provided. + - Provide tool parameters in <action_input>. + - Wait for the observation from the tool. + d. If no tool is needed, use the 'no_tool' action. + e. Based on observations or your knowledge, formulate your answer. + f. Provide the final answer in the <answer> tag, including follow-up questions. + +4. Available Tools: +${toolDescriptions} + no_tool: Use when no external tool is required to answer the question. + +5. Critical Rules: + - Use tools ONLY when absolutely necessary for accurate answers. + - Ensure ALL XML is valid, properly nested, and complete. + - ALWAYS pause after <action> and <action_input> tags for system processing. + - If the initial answer is inadequate, iterate through additional steps to refine it. + - Utilize context from past conversations when relevant (provided in Chat History). + - ALWAYS include your final response within a single <answer> tag. + +6. Answer Format: + Your final <answer> tag must contain: + - The complete answer to the user's query. + - An array of EXACTLY 3 follow-up questions within <follow_up_questions> tags. + +7. Example Interaction: +<query>What is the population of Tokyo, and how does it compare to New York City?</query> + <step1> - <thought>This is a simple arithmetic question that doesn't require any external tool.</thought> - <action>no_tool</action> + <thought>To answer this question accurately, I need to look up the current population figures for both Tokyo and New York City. I'll use the Wikipedia tool for this information.</thought> + <action>wikipedia</action> </step1> -THEN PAUSE AND DO NOT OUTPUT ANYTHING. +[SYSTEM PAUSE] -You will be called again with this: <action_rules> { - "no_tool": { - "name": "no_tool", - "description": "Use when no external tool or action is required", - "parameters": [] + "wikipedia": { + "name": "wikipedia", + "description": "Search Wikipedia and return a summary", + "parameters": [ + { + "title": { + "type": "string", + "description": "The title of the Wikipedia article to search", + "required": "true" + } + } + ] } } </action_rules> -You will then output: <step2> - <action_input></action_input> + <action_input> + <title>Tokyo</title> + </action_input> </step2> -THEN PAUSE AND DO NOT OUTPUT ANYTHING. +[SYSTEM PAUSE] -You will then be called again with this: -<observation>No tool used. Proceed with answering the question.</observation> +<observation>Tokyo is the capital and most populous prefecture of Japan. The Tokyo metropolitan area, which includes Tokyo and several surrounding prefectures, is the world's most populous metropolitan area with an estimated 37.468 million residents as of 2018.</observation> -You then output: <step3> + <thought>Now that I have information about Tokyo, I need to get information about New York City for comparison.</thought> + <action>wikipedia</action> +</step3> + +[SYSTEM PAUSE] + +<action_rules> + { + "wikipedia": { + "name": "wikipedia", + "description": "Search Wikipedia and return a summary", + "parameters": [ + { + "title": { + "type": "string", + "description": "The title of the Wikipedia article to search", + "required": "true" + } + } + ] + } + } +</action_rules> + +<step4> + <action_input> + <title>New York City</title> + </action_input> +</step4> + +[SYSTEM PAUSE] + +<observation>New York City is the most populous city in the United States. With an estimated 2020 population of 8,804,190 distributed over 300.46 square miles (778.2 km2), New York City is also the most densely populated major city in the United States.</observation> + +<step5> + <thought>Now that I have the population information for both Tokyo and New York City, I can provide a comprehensive answer comparing the two.</thought> <answer> - 2 + 2 equals 4. + The population of Tokyo metropolitan area is approximately 37.468 million (as of 2018), while New York City has a population of about 8.8 million (as of 2020). Tokyo's population is significantly larger, more than four times that of New York City. It's important to note that the Tokyo figure refers to the broader metropolitan area, while the New York City figure is for the city proper. Even accounting for this difference, Tokyo remains substantially more populous than New York City. + <follow_up_questions> - <question>What is 3 + 3?</question> - <question>Can you explain the concept of addition?</question> - <question>What is 2 * 2?</question> + <question>What factors contribute to Tokyo's significantly larger population compared to New York City?</question> + <question>How do the population densities of Tokyo and New York City compare?</question> + <question>What challenges do these megacities face due to their large populations?</question> </follow_up_questions> </answer> -</step3> - ********** - Here is the history of your conversation with the user (all loop steps are ommitted, so it is just the user query and final answer): - ${chatHistory} - Use context from the past conversation if necessary. - ********** - If the response is inadequate, repeat the loop, either trying a different tool or changing the parameters for the action input. - ********** - !!!IMPORTANT Only use tools when they are absolutely necessary to answer the question. If you have enough information or knowledge to answer the question without using a tool, use the "no_tool" action instead. - !!!IMPORTANT When you have an Answer, Write your entire response inside an <answer> element (which itself should be inside the step element for the current step). After you finish the answer, provide an array of 3 follow-up questions inside a <follow_up_questions> array. These should relate to the query and the response and should aim to help the user better understand whatever they are looking for. - ********** - !!!IMPORTANT Every response, provide in full parsable and valid XML with the root element being the step number (e.g. <step1>), iterated every time you output something new. - `; +</step5> + +8. Chat History: +${chatHistory} + +Remember to use this history for context when appropriate. + +Now, process the user's query and provide your response following the format and rules outlined above. Ensure your final answer is comprehensive and entirely contained within a single <answer> tag. +</system>`; } export function getSummarizedChunksPrompt(chunks: string): string { |