From e7b7f7000534200d75f3519ffb13d5b22dbc5481 Mon Sep 17 00:00:00 2001 From: "A.J. Shulman" Date: Mon, 22 Jul 2024 12:19:27 -0400 Subject: attempting new RAG prompt and formatting of citations vs grounded text --- src/client/views/nodes/ChatBox/Agent.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/client/views/nodes/ChatBox/Agent.ts') diff --git a/src/client/views/nodes/ChatBox/Agent.ts b/src/client/views/nodes/ChatBox/Agent.ts index d494928f9..ca1b5c60c 100644 --- a/src/client/views/nodes/ChatBox/Agent.ts +++ b/src/client/views/nodes/ChatBox/Agent.ts @@ -43,14 +43,14 @@ 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(); let currentAction: string | undefined; - for (let i = 0; i < maxTurns; i++) { - console.log(`Turn ${i + 1}/${maxTurns}`); + for (let i = 1; i < maxTurns; i++) { + console.log(`Turn ${i}/${maxTurns}`); const result = await this.execute(); console.log(`Bot response: ${result}`); @@ -73,17 +73,20 @@ export class Agent { currentAction = step[key] as string; console.log(`Action: ${currentAction}`); if (this.tools[currentAction]) { + i++; const nextPrompt = [ { type: 'text', - text: builder.build({ action_rules: this.tools[currentAction].getActionRule() }), + text: `` + builder.build({ action_rules: this.tools[currentAction].getActionRule() }) + `<\step>`, }, ]; this.interMessages.push({ role: 'user', content: nextPrompt }); + break; } else { console.log('Error: No valid action'); - this.interMessages.push({ role: 'user', content: 'No valid action, try again.' }); + i++; + this.interMessages.push({ role: 'user', content: `No valid action, try again.` }); break; } } else if (key === 'action_input') { @@ -92,7 +95,12 @@ export class Agent { if (currentAction) { try { const observation = await this.processAction(currentAction, step[key]); - const nextPrompt = [{ type: 'text', text: '' }, ...observation, { type: 'text', text: '' }]; + // const stepElement = parsedResult.documentElement; + // const rootTagName = stepElement.tagName; + // const match = rootTagName.match(/step(\d+)/); + // const currentStep = match ? parseInt(match[1]) + 1 : 1; + i++; + const nextPrompt = [{ type: 'text', text: `` }, ...observation, { type: 'text', text: '' }]; console.log(observation); this.interMessages.push({ role: 'user', content: nextPrompt }); break; -- cgit v1.2.3-70-g09d2