aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/ChatBox/prompts.ts
diff options
context:
space:
mode:
authorA.J. Shulman <Shulman.aj@gmail.com>2024-07-10 16:16:26 -0400
committerA.J. Shulman <Shulman.aj@gmail.com>2024-07-10 16:16:26 -0400
commitcab0311e2fd9a6379628c000d11ddcd805e01f64 (patch)
tree60cb3f397426cb3931c13ebe3b8a1e8eb98480dd /src/client/views/nodes/ChatBox/prompts.ts
parentd0e09ff3526e4f6b9aad824fad1020d083a87631 (diff)
first attempt at integrating everything
Diffstat (limited to 'src/client/views/nodes/ChatBox/prompts.ts')
-rw-r--r--src/client/views/nodes/ChatBox/prompts.ts99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/client/views/nodes/ChatBox/prompts.ts b/src/client/views/nodes/ChatBox/prompts.ts
new file mode 100644
index 000000000..8835265e4
--- /dev/null
+++ b/src/client/views/nodes/ChatBox/prompts.ts
@@ -0,0 +1,99 @@
+// 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. <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 return a </pause> element.
+ 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}
+ **********
+ 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>
+ <pause/>
+ </step1>
+
+ 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>
+
+ 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>
+ **********
+ 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 <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.
+ `;
+}
+
+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.';
+}