// prompts.ts import { Tool } from './types'; 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. content of the thought). At the end of the loop, you output an Answer with the answer content contained within an XML element with an 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 key. Use to describe your thoughts about the question you have been asked. Use to specify run one of the actions available to you. Then, you will be provided with action rules within an 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 element. Then, provide within an 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 element will be the result of running those actions. ********** Your available actions are: ***** ${toolDescriptions} ********** Example: You will be called with: What is the capital of France? You will then output: I should look up France on Wikipedia wikipedia THEN PAUSE AND DO NOT OUTPUT ANYTHING. You will be called again with this: { "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" } } ] } } You will then output (back in valid XML with the parameters each being a tag): France THEN PAUSE AND DO NOT OUTPUT ANYTHING. You will then be called again with this: France is a country. The capital is Paris. You then output: The capital of France is Paris Where in France is Paris located? What are some major tourist attractions in Paris? What are some other major cities in France? ********** 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 When you have an Answer, Write your entire response inside an 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 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. ), iterated every time you output something new. `; } export function getSummarizedChunksPrompt(chunks: string): string { return `Please provide a comprehensive summary of what you think the document from which these chunks originated. Ensure the summary captures the main ideas and key points from all provided chunks. Be concise and brief and only provide the summary in paragraph form. Text chunks: \`\`\` ${chunks} \`\`\``; } export function getSummarizedSystemPrompt(): string { return 'You are an AI assistant tasked with summarizing a document. You are provided with important chunks from the document and provide a summary, as best you can, of what the document will contain overall. Be concise and brief with your response.'; }