From afb5bb72c0f85eda1f41eab0e8b76398fff7ac7f Mon Sep 17 00:00:00 2001 From: "A.J. Shulman" Date: Fri, 16 Aug 2024 13:14:58 -0400 Subject: changed from step tags to stage tags Changed from step1, step2, etc. tags to more straightforward (and not similar to other step tags usage in XML) stage tags with stage number as an attribute. --- src/client/views/nodes/ChatBox/Agent.ts | 35 ++-- src/client/views/nodes/ChatBox/prompts.ts | 262 ++++++++++++++---------------- 2 files changed, 139 insertions(+), 158 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/ChatBox/Agent.ts b/src/client/views/nodes/ChatBox/Agent.ts index 825cd831b..41c91b4c6 100644 --- a/src/client/views/nodes/ChatBox/Agent.ts +++ b/src/client/views/nodes/ChatBox/Agent.ts @@ -54,13 +54,13 @@ export class Agent { console.log(`System prompt: ${systemPrompt}`); this.interMessages = [{ role: 'system', content: systemPrompt }]; - this.interMessages.push({ role: 'user', content: `${question}` }); + this.interMessages.push({ role: 'user', content: `${question}` }); - const parser = new XMLParser(); - const builder = new XMLBuilder(); + const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '@_' }); + const builder = new XMLBuilder({ ignoreAttributes: false, attributeNamePrefix: '@_' }); let currentAction: string | undefined; - for (let i = 3; i < maxTurns; i += 2) { + for (let i = 2; i < maxTurns; i += 2) { console.log(`Turn ${i}/${maxTurns}`); const result = await this.execute(); @@ -75,19 +75,24 @@ export class Agent { return 'Invalid response format.'; } - const step = parsedResult[Object.keys(parsedResult)[0]]; + const stage = parsedResult.stage; - for (const key in step) { + if (!stage) { + console.log('Error: No stage found in response'); + return 'Invalid response format: No stage found.'; + } + + for (const key in stage) { if (key === 'thought') { - console.log(`Thought: ${step[key]}`); + console.log(`Thought: ${stage[key]}`); } else if (key === 'action') { - currentAction = step[key] as string; + currentAction = stage[key] as string; console.log(`Action: ${currentAction}`); if (this.tools[currentAction]) { const nextPrompt = [ { type: 'text', - text: `` + builder.build({ action_rules: this.tools[currentAction].getActionRule() }) + `<\step>`, + text: `` + builder.build({ action_rules: this.tools[currentAction].getActionRule() }) + ``, }, ]; this.interMessages.push({ role: 'user', content: nextPrompt }); @@ -95,20 +100,16 @@ export class Agent { break; } else { console.log('Error: No valid action'); - this.interMessages.push({ role: 'user', content: `No valid action, try again.` }); + this.interMessages.push({ role: 'user', content: `No valid action, try again.` }); break; } } else if (key === 'action_input') { - const actionInput = builder.build({ action_input: step[key] }); + const actionInput = builder.build({ action_input: stage[key] }); console.log(`Action input: ${actionInput}`); if (currentAction) { try { - const observation = await this.processAction(currentAction, step[key]); - // const stepElement = parsedResult.documentElement; - // const rootTagName = stepElement.tagName; - // const match = rootTagName.match(/step(\d+)/); - // const currentStep = match ? parseInt(match[1]) + 1 : 1; - const nextPrompt = [{ type: 'text', text: ` ` }, ...observation, { type: 'text', text: '' }]; + const observation = await this.processAction(currentAction, stage[key]); + const nextPrompt = [{ type: 'text', text: ` ` }, ...observation, { type: 'text', text: '' }]; console.log(observation); this.interMessages.push({ role: 'user', content: nextPrompt }); break; diff --git a/src/client/views/nodes/ChatBox/prompts.ts b/src/client/views/nodes/ChatBox/prompts.ts index 2d04595bc..9c5ac063d 100644 --- a/src/client/views/nodes/ChatBox/prompts.ts +++ b/src/client/views/nodes/ChatBox/prompts.ts @@ -20,13 +20,13 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto - **MOST IMPORTANT**: Always output responses within step number tags, using the step number and the assistant role as the root tag (e.g., , , etc.). This is crucial and should never be overlooked. - **STOP after every step and wait for the system to provide the next input (e.g., action rules or observations). - Only output **ONE step at a time** in your responses. Do not skip steps or provide multiple steps at once. Thus, you should only output even step number root tags. + **MOST IMPORTANT**: Always output responses within stage number tags, using the stage number and the system role as the root tag (e.g., , , etc.). This is crucial and should never be overlooked. + **STOP after every stage and wait for the system to provide the next input (e.g., action rules or observations). + Only output **ONE stage at a time** in your responses. Do not skip stages or provide multiple stages at once. Thus, you should only output even stage number root tags. Always structure your responses using valid, well-formed XML with properly nested tags. If a tool is needed, ALWAYS select the most appropriate tool based on the user's query. - If the query could relate to user documents or require external information (e.g., RAG, search + website scraping, data analysis, Wikipedia), USE the appropriate tool to gather that information. - If there are no user docs or the user docs have not yielded helpful information, either use Wikipedia if a brief summary of a direct topic is all that is needed, or use the search tool to find websites followed by the website scraper tool to get useful infromation from one of those websites. + If the query could relate to user documents or require external information (e.g., RAG, search + website scraping, data analysis), USE the appropriate tool to gather that information. + If there are no user docs or the user docs have not yielded helpful information, use the search tool to find websites followed by the website scraper tool to get useful infromation from one of those websites. You can use the website scraper (or even the search tool), multiple times to find information from multiple websites either from the same search or different searches. @@ -48,7 +48,7 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto - Wrap all information derived from tools (e.g., RAG, Wikipedia, CSV analysis) or chunks in <grounded_text> tags. + Wrap all information derived from tools (e.g., RAG, search + website scraping, data analysis)—which will be provided in chunks—in <grounded_text> tags. DO NOT PUT ANYTHING THAT IS NOT DIRECTLY DERIVED FROM TOOLS OR CHUNKS IN <grounded_text> TAGS. Use a single <grounded_text> tag for sequential and closely related information that references the same citation. If other citations are used sequentially, create new <grounded_text> tags. @@ -72,7 +72,7 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto Specify the correct type: "text", "image", "table", "csv", or "url". For text-based information, include only the relevant subset of the original information that the <grounded_text> is based on. For image, table, csv, or url citation types, leave the citation content empty. - ALL CITATIONS MUST use the chunk_id field to reference the source, whether it’s from RAG, Wikipedia, CSV analysis, or any other tool. + ALL CITATIONS MUST use the chunk_id field to reference the source, whether it’s from RAG, search + website scraping, data analysis, or any other tool. One citation can be used for multiple <grounded_text> tags if they are based on the same tool or chunk information. !!!DO NOT OVERCITE - only include citations for information that is directly relevant to the <grounded_text>. @@ -103,7 +103,7 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto ${toolDescriptions} - If no external tool is required to answer the question, use the 'no_tool' action. However, if the query might relate to user documents or require external information, do not use 'no_tool'—instead, use the appropriate tool (RAG, Wikipedia, etc.), even if unsure. + If no external tool is required to answer the question, use the 'no_tool' action. However, if the query might relate to user documents or require external information, do not use 'no_tool'—instead, use the appropriate tool (RAG, search + website scraping, data analysis), even if unsure. @@ -113,141 +113,121 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto - YOU ONLY OUTPUT THE ASSISTANT STEPS: - - - ***SYSTEM MESSAGE ELIDED*** - - - - Could you provide a detailed overview of the 2010 Vancouver Winter Olympics, including the overall summary of the games, key moments from official statements, and how the medal count compared across countries? - - - - - To answer this query comprehensively, I will start by retrieving an overview of the 2010 Vancouver Winter Olympics from Wikipedia. After that, I'll look for any official press release statements for key moments during the games using the RAG tool. Finally, I'll analyze the medal count using the CSV data to compare how different countries performed. - - wikipedia - - - - ***Action rules elided*** - - - - - 2010 Winter Olympics - - - - - - The 2010 Winter Olympics, officially known as the XXI Olympic Winter Games, took place in Vancouver, British Columbia, Canada, from February 12 to 28, 2010. It featured 86 events in 15 disciplines across 7 sports, with 2,566 athletes from 82 National Olympic Committees participating. This edition of the Winter Olympics was notable for being the first hosted by Canada since the 1988 Winter Olympics in Calgary. - - - - - - Now that I have an overview from Wikipedia, I will use the RAG tool to find relevant information from the user's documents, specifically focusing on key moments and statements from an official press release. - - rag - - - - ***Action rules elided*** - - - - - - The user is asking for key moments and statements from official sources regarding the 2010 Vancouver Winter Olympics. Search the provided documents for any press releases or official statements that highlight significant events, achievements, or noteworthy aspects of the games. - - - - - - - PRESS RELEASE: 2010 VANCOUVER WINTER OLYMPICS - - Vancouver, BC - The 2010 Winter Olympics have been hailed as a monumental success, showcasing the best of Canadian culture and athletic prowess. The Opening Ceremony, held on February 12, 2010, was a spectacular celebration of the nation's history and diversity... - - Key Moments: - - The Canadian men's and women's ice hockey teams both claimed gold medals, an achievement that brought immense pride to the host nation. - - Tragedy struck early in the games with the death of Georgian luger Nodar Kumaritashvili during a training run. This incident led to increased scrutiny of safety measures across all events... - - ***More chunk content elided for brevity*** - - The games concluded on February 28, 2010, with a memorable Closing Ceremony that highlighted the achievements of the athletes and the spirit of unity that defined the 2010 Vancouver Winter Olympics. - - - - - - With information on key moments from the press release, I will now analyze the medal count data to compare how different countries performed during the games. - - dataAnalysis - - - - ***Action rules elided*** - - - - - 2010_Vancouver_Olympics_Medal_Count.csv - - - - - - Country,Gold,Silver,Bronze,Total - USA,9,15,13,37 - Germany,10,13,7,30 - Canada,14,7,5,26 - Norway,9,8,6,23 - - - - - - Now that I have gathered comprehensive information from Wikipedia, the official press release, and the medal count data, I will provide a detailed answer to the user's query. - - - - The 2010 Winter Olympics, officially known as the XXI Olympic Winter Games, took place in Vancouver, British Columbia, Canada, from February 12 to 28, 2010. It featured 86 events in 15 disciplines across 7 sports, with 2,566 athletes from 82 National Olympic Committees participating. - - - The Opening Ceremony was one of the most spectacular in Olympic history, celebrating Canadian culture and heritage. A significant highlight for the host nation was the victory of the Canadian men's and women's ice hockey teams, both securing gold medals, which was a source of immense national pride. - - - In terms of medal performance, the United States led the overall tally with 37 medals, followed by Germany with 30 medals. Canada, while placing third in total medals, achieved a record number of 14 gold medals, the highest of any country in the 2010 games. - - - However, the games were also marked by tragedy with the unfortunate death of Georgian luger Nodar Kumaritashvili during a training run, which deeply affected the Olympic community. - - - - - Vancouver, BC - The 2010 Winter Olympics have been hailed as a monumental success, showcasing the best of Canadian culture and athletic prowess. The Opening Ceremony, held on February 12, 2010, was a spectacular celebration of the nation's history and diversity... + YOU ONLY OUTPUT THE ASSISTANT STAGES: + + + ***SYSTEM MESSAGE ELIDED*** + + + Could you provide a detailed overview of the 2010 Vancouver Winter Olympics's impact, including the overall summary of the games, key moments from official statements, and how the medal count compared across countries? + + + + + Since the user has Olympics related docs, I will use the RAG tool to find relevant information from the user's documents, specifically focusing on key moments and statements from an official press release. + + rag + + + + ***Action rules elided*** + + + + + + The user is asking for key moments and statements from official sources regarding the 2010 Vancouver Winter Olympics. Search the provided documents for any press releases or official statements that highlight significant events, achievements, or noteworthy aspects of the games. + + + + + + + PRESS RELEASE: 2010 VANCOUVER WINTER OLYMPICS + + Vancouver, BC - + + The 2010 Winter Olympics, officially known as the XXI Olympic Winter Games, took place in Vancouver, British Columbia, Canada, from February 12 to 28, 2010. It featured 86 events in 15 disciplines across 7 sports, with 2,566 athletes from 82 National Olympic Committees participating. This edition of the Winter Olympics was notable for being the first hosted by Canada since the 1988 Winter Olympics in Calgary. + + Overall, the 2010 Winter Olympics have been hailed as a monumental success, showcasing the best of Canadian culture and athletic prowess. The Opening Ceremony, held on February 12, 2010, was a spectacular celebration of the nation's history and diversity... Key Moments: - - The Canadian men's and women's ice hockey teams both claimed gold medals, an achievement that brought immense pride to the host nation. - - - - Tragedy struck early in the games with the death of Georgian luger Nodar Kumaritashvili during a training run. - - - - - What were the economic impacts on Vancouver after hosting the 2010 Winter Olympics? - How did the tragic accident of Nodar Kumaritashvili influence safety protocols in luge and other winter sports? - Can you provide more information on other significant performances by athletes during the 2010 Winter Olympics? - - - - - + - The Canadian men's and women's ice hockey teams both claimed gold medals, an achievement that brought immense pride to the host nation. + - Tragedy struck early in the games with the death of Georgian luger Nodar Kumaritashvili during a training run. This incident led to increased scrutiny of safety measures across all events... + + ***More chunk content elided for brevity*** + + The games concluded on February 28, 2010, with a memorable Closing Ceremony that highlighted the achievements of the athletes and the spirit of unity that defined the 2010 Vancouver Winter Olympics. + + + + + + With information on key moments from the press release, I will now analyze the medal count data to compare how different countries performed during the games. + + dataAnalysis + + + + ***Action rules elided*** + + + + + 2010_Vancouver_Olympics_Medal_Count.csv + + + + + + Country,Gold,Silver,Bronze,Total + USA,9,15,13,37 + Germany,10,13,7,30 + Canada,14,7,5,26 + Norway,9,8,6,23 + + + + + + Now that I have gathered comprehensive information from the official press release and the medal count data, I will provide a detailed answer to the user's query. + + + + The 2010 Winter Olympics, officially known as the XXI Olympic Winter Games, took place in Vancouver, British Columbia, Canada, from February 12 to 28, 2010. It featured 86 events in 15 disciplines across 7 sports, with 2,566 athletes from 82 National Olympic Committees participating. + + + The Opening Ceremony was one of the most spectacular in Olympic history, celebrating Canadian culture and heritage. A significant highlight for the host nation was the victory of the Canadian men's and women's ice hockey teams, both securing gold medals, which was a source of immense national pride. + + + In terms of medal performance, the United States led the overall tally with 37 medals, followed by Germany with 30 medals. Canada, while placing third in total medals, achieved a record number of 14 gold medals, the highest of any country in the 2010 games. + + + However, the games were also marked by tragedy with the unfortunate death of Georgian luger Nodar Kumaritashvili during a training run, which deeply affected the Olympic community. + + + + + Vancouver, BC - The 2010 Winter Olympics have been hailed as a monumental success, showcasing the best of Canadian culture and athletic prowess. The Opening Ceremony, held on February 12, 2010, was a spectacular celebration of the nation's history and diversity... + + Key Moments: + - The Canadian men's and women's ice hockey teams both claimed gold medals, an achievement that brought immense pride to the host nation. + + + + Tragedy struck early in the games with the death of Georgian luger Nodar Kumaritashvili during a training run. + + + + + What were the economic impacts on Vancouver after hosting the 2010 Winter Olympics? + How did the tragic accident of Nodar Kumaritashvili influence safety protocols in luge and other winter sports? + Can you provide more information on other significant performances by athletes during the 2010 Winter Olympics? + + + + + -- cgit v1.2.3-70-g09d2