diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/nodes/ChatBox/AnswerParser.ts | 6 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/ChatBox.tsx | 6 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/prompts.ts | 16 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/tools/RAGTool.ts | 5 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/types.ts | 1 |
5 files changed, 27 insertions, 7 deletions
diff --git a/src/client/views/nodes/ChatBox/AnswerParser.ts b/src/client/views/nodes/ChatBox/AnswerParser.ts index 05d26b8de..885114195 100644 --- a/src/client/views/nodes/ChatBox/AnswerParser.ts +++ b/src/client/views/nodes/ChatBox/AnswerParser.ts @@ -10,10 +10,12 @@ export class AnswerParser { const questionRegex = /<question>(.*?)<\/question>/g; const groundedTextRegex = /<grounded_text citation_index="([^"]+)">([\s\S]*?)<\/grounded_text>/g; const normalTextRegex = /<normal_text>([\s\S]*?)<\/normal_text>/g; + const loopSummaryRegex = /<loop_summary>([\s\S]*?)<\/loop_summary>/; const answerMatch = answerRegex.exec(xml); const citationsMatch = citationsRegex.exec(xml); const followUpQuestionsMatch = followUpQuestionsRegex.exec(xml); + const loopSummaryMatch = loopSummaryRegex.exec(xml); if (!answerMatch) { throw new Error('Invalid XML: Missing <answer> tag.'); @@ -31,6 +33,9 @@ export class AnswerParser { if (followUpQuestionsMatch) { rawTextContent = rawTextContent.replace(followUpQuestionsMatch[0], '').trim(); } + if (loopSummaryMatch) { + rawTextContent = rawTextContent.replace(loopSummaryMatch[0], '').trim(); + } // Parse citations let citationMatch; @@ -112,6 +117,7 @@ export class AnswerParser { follow_up_questions: followUpQuestions, citations, processing_info: processingInfo, + loop_summary: loopSummaryMatch ? loopSummaryMatch[1].trim() : undefined, }; return assistantResponse; diff --git a/src/client/views/nodes/ChatBox/ChatBox.tsx b/src/client/views/nodes/ChatBox/ChatBox.tsx index ffede6901..345bfd8d1 100644 --- a/src/client/views/nodes/ChatBox/ChatBox.tsx +++ b/src/client/views/nodes/ChatBox/ChatBox.tsx @@ -445,7 +445,11 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { get formattedHistory(): string { let history = '<chat_history>\n'; for (const message of this.history) { - history += `<${message.role}>${message.content.map(content => content.text).join(' ')}</${message.role}>\n`; + history += `<${message.role}>${message.content.map(content => content.text).join(' ')}`; + if (message.loop_summary) { + history += `<loop_summary>${message.loop_summary}</loop_summary>`; + } + history += `</${message.role}>\n`; } history += '</chat_history>'; return history; diff --git a/src/client/views/nodes/ChatBox/prompts.ts b/src/client/views/nodes/ChatBox/prompts.ts index 71a4f33b4..9ea86dbf4 100644 --- a/src/client/views/nodes/ChatBox/prompts.ts +++ b/src/client/views/nodes/ChatBox/prompts.ts @@ -37,16 +37,17 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto When providing your final response, use the following structure: </instruction> <answer> - <section> - <tag><grounded_text> - Wrap text that is derived from tool-based or chunk-based information within these tags, ensuring proper citation.</tag> - <tag><normal_text> - Wrap text that is not derived from tool-based or chunk-based information within these tags.</tag> - </section> + <tag><grounded_text> - Wrap text that is derived from tool-based or chunk-based information within these tags, ensuring proper citation.</tag> + <tag><normal_text> - Wrap text that is not derived from tool-based or chunk-based information within these tags.</tag> <citations> <tag><citation> - Provide citations for each grounded text, referencing the tool or chunk used.</tag> </citations> <follow_up_questions> <tag><question> - Include exactly three follow-up questions from the user's perspective within these tags.</tag> </follow_up_questions> + <loop_summary> + <tag><loop_summary> - Provide a summary of the actions and tools used by the assistant throughout the interaction within these tags.</tag> + </loop_summary> </answer> </response_structure> @@ -103,6 +104,7 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto <elements> <element>The complete answer to the user's query, with grounded information wrapped in <grounded_text> tags and general information wrapped in <normal_text> tags.</element> <element>Exactly three follow-up questions written from the user's perspective, enclosed within <follow_up_questions> tags.</element> + <element>A concise <loop_summary> that describes the actions and tools used throughout the interaction.</element> </elements> </final_answer_requirements> @@ -267,6 +269,9 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto <question>What specific infrastructure improvements were made in Vancouver as a result of hosting the 2010 Winter Olympics?</question> <question>How did the performance of Canadian athletes in the 2010 Vancouver Winter Olympics compare to their performance in previous Winter Olympics?</question> </follow_up_questions> + <loop_summary> + The assistant used the RAG tool to gather information from the user's documents, focusing on key moments and official statements. It then used the dataAnalysis tool to analyze the medal count and economic impact data, providing a comprehensive overview of the 2010 Vancouver Winter Olympics's impact. + </loop_summary> </answer> </stage> </interaction> @@ -424,6 +429,9 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto <question>Are there any special permits required for hiking certain trails in Yosemite?</question> <question>What wildlife might I encounter while hiking in Yosemite, and how should I prepare for potential encounters?</question> </follow_up_questions> + <loop_summary> + The assistant used the search tool to find relevant websites, then scraped information from those sites using the websiteInfoScraper tool. Additional information about current trail conditions was gathered from the NPS website to provide a comprehensive and safe hiking guide. + </loop_summary> </answer> </stage> </interaction> diff --git a/src/client/views/nodes/ChatBox/tools/RAGTool.ts b/src/client/views/nodes/ChatBox/tools/RAGTool.ts index fcd0ea43f..fe8deae6b 100644 --- a/src/client/views/nodes/ChatBox/tools/RAGTool.ts +++ b/src/client/views/nodes/ChatBox/tools/RAGTool.ts @@ -4,6 +4,7 @@ import { RAGChunk } from '../types'; import * as fs from 'fs'; import { Networking } from '../../../../Network'; import { file } from 'jszip'; +import { ChatCompletion, ChatCompletionContentPart, ChatCompletionMessageParam } from 'openai/resources'; export class RAGTool extends BaseTool<{ hypothetical_document_chunk: string }> { constructor(private vectorstore: Vectorstore) { @@ -118,10 +119,10 @@ export class RAGTool extends BaseTool<{ hypothetical_document_chunk: string }> { return formatted_chunks; } - async getFormattedChunks(relevantChunks: RAGChunk[]): Promise<{ type: string; text?: string; image_url?: { url: string } }[]> { + async getFormattedChunks(relevantChunks: RAGChunk[]): Promise<ChatCompletionContentPart[]> { try { const { formattedChunks } = await Networking.PostToServer('/formatChunks', { relevantChunks }); - console.log('Formatted Chunks:', formattedChunks); + if (!formattedChunks) { throw new Error('Failed to format chunks'); } diff --git a/src/client/views/nodes/ChatBox/types.ts b/src/client/views/nodes/ChatBox/types.ts index 09f14f019..a59ead067 100644 --- a/src/client/views/nodes/ChatBox/types.ts +++ b/src/client/views/nodes/ChatBox/types.ts @@ -64,6 +64,7 @@ export interface AssistantMessage { follow_up_questions?: string[]; citations?: Citation[]; processing_info: ProcessingInfo[]; + loop_summary?: string; } export interface MessageContent { |