diff options
| author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-07-22 12:19:27 -0400 |
|---|---|---|
| committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-07-22 12:19:27 -0400 |
| commit | e7b7f7000534200d75f3519ffb13d5b22dbc5481 (patch) | |
| tree | c9568e9f79fd6ebb0de09cb8c3cca6011f4d5501 /src/client/views/nodes/ChatBox/Agent.ts | |
| parent | 834ca4e21fead079e681b963e2d533d93a53cb91 (diff) | |
attempting new RAG prompt and formatting of citations vs grounded text
Diffstat (limited to 'src/client/views/nodes/ChatBox/Agent.ts')
| -rw-r--r-- | src/client/views/nodes/ChatBox/Agent.ts | 20 |
1 files changed, 14 insertions, 6 deletions
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: `<query>${question}</query>` }); + this.interMessages.push({ role: 'user', content: `<step0 role="user"><query>${question}</query></step>` }); 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: `<step${i} role="user">` + 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: `<step${i}>No valid action, try again.</step>` }); 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>' }, ...observation, { type: 'text', text: '</observation>' }]; + // 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: `<step${i}<observation>` }, ...observation, { type: 'text', text: '</observation></step>' }]; console.log(observation); this.interMessages.push({ role: 'user', content: nextPrompt }); break; |
