From aa8b1248408846d6a158f8df1c76fa3015ce3aac Mon Sep 17 00:00:00 2001 From: "A.J. Shulman" Date: Wed, 10 Jul 2024 16:35:11 -0400 Subject: Fixing bugs and attempting to get it to work --- src/client/views/nodes/ChatBox/Agent.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 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 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; + private tools: Record>; 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, { type: 'text', text: '' }]; this.interMessages.push({ role: 'user', content: nextPrompt }); } catch (e) { @@ -97,10 +104,11 @@ export class Agent { private async execute(): Promise { 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 { -- cgit v1.2.3-70-g09d2