aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/ChatBox/Agent.ts
diff options
context:
space:
mode:
authorA.J. Shulman <Shulman.aj@gmail.com>2024-07-10 16:35:11 -0400
committerA.J. Shulman <Shulman.aj@gmail.com>2024-07-10 16:35:11 -0400
commitaa8b1248408846d6a158f8df1c76fa3015ce3aac (patch)
treec0bf0d85b3f09a59e001bdc93963fc413222f942 /src/client/views/nodes/ChatBox/Agent.ts
parentcab0311e2fd9a6379628c000d11ddcd805e01f64 (diff)
Fixing bugs and attempting to get it to work
Diffstat (limited to 'src/client/views/nodes/ChatBox/Agent.ts')
-rw-r--r--src/client/views/nodes/ChatBox/Agent.ts16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/client/views/nodes/ChatBox/Agent.ts b/src/client/views/nodes/ChatBox/Agent.ts
index f20a75a8d..4c2838540 100644
--- a/src/client/views/nodes/ChatBox/Agent.ts
+++ b/src/client/views/nodes/ChatBox/Agent.ts
@@ -2,10 +2,17 @@ import OpenAI from 'openai';
import { Tool, AgentMessage } from './types';
import { getReactPrompt } from './prompts';
import { XMLParser, XMLBuilder } from 'fast-xml-parser';
+import { WikipediaTool } from './tools/WikipediaTool';
+import { CalculateTool } from './tools/CalculateTool';
+import { RAGTool } from './tools/RAGTool';
+import { Vectorstore } from './vectorstore/VectorstoreUpload';
+import { ChatCompletionAssistantMessageParam, ChatCompletionMessageParam } from 'openai/resources';
+import dotenv from 'dotenv';
+dotenv.config();
export class Agent {
private client: OpenAI;
- private tools: Record<string, Tool>;
+ private tools: Record<string, Tool<any>>;
private messages: AgentMessage[] = [];
private interMessages: AgentMessage[] = [];
private summaries: string;
@@ -69,7 +76,7 @@ export class Agent {
const actionInput = new XMLBuilder().build({ action_input: step.action_input });
console.log(`Action input: ${actionInput}`);
try {
- const observation = await this.processAction(action, step.action_input);
+ const observation = await this.processAction(step.action, step.action_input);
const nextPrompt = [{ type: 'text', text: '<observation>' }, ...observation, { type: 'text', text: '</observation>' }];
this.interMessages.push({ role: 'user', content: nextPrompt });
} catch (e) {
@@ -97,10 +104,11 @@ export class Agent {
private async execute(): Promise<string> {
const completion = await this.client.chat.completions.create({
model: 'gpt-4',
- messages: this.interMessages,
+ messages: this.interMessages as ChatCompletionMessageParam[],
temperature: 0,
});
- return completion.choices[0].message.content;
+ if (completion.choices[0].message.content) return completion.choices[0].message.content;
+ else throw new Error('No completion content found');
}
private async processAction(action: string, actionInput: any): Promise<any> {