From 65179e8b0519aa4ccf28afc4c429262ecf7a62f3 Mon Sep 17 00:00:00 2001 From: "A.J. Shulman" Date: Tue, 16 Jul 2024 11:11:53 -0400 Subject: attempting annotations for image chunks --- src/client/views/nodes/ChatBox/Agent.ts | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 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 fd3c6e5e8..210d3c804 100644 --- a/src/client/views/nodes/ChatBox/Agent.ts +++ b/src/client/views/nodes/ChatBox/Agent.ts @@ -8,6 +8,7 @@ import { RAGTool } from './tools/RAGTool'; import { Vectorstore } from './vectorstore/VectorstoreUpload'; import { ChatCompletionAssistantMessageParam, ChatCompletionMessageParam } from 'openai/resources'; import dotenv from 'dotenv'; +import { ChatBox } from './ChatBox'; dotenv.config(); export class Agent { @@ -15,41 +16,24 @@ export class Agent { private tools: Record>; private messages: AgentMessage[] = []; private interMessages: AgentMessage[] = []; - private summaries: string; + private vectorstore: Vectorstore; + private history: () => string; - constructor(private vectorstore: Vectorstore) { + constructor(_vectorstore: Vectorstore, summaries: () => string, _history: () => string) { this.client = new OpenAI({ apiKey: process.env.OPENAI_KEY, dangerouslyAllowBrowser: true }); - this.summaries = this.vectorstore ? this.vectorstore.getSummaries() : 'No documents available.'; + this.vectorstore = _vectorstore; + this.history = _history; this.tools = { wikipedia: new WikipediaTool(), calculate: new CalculateTool(), - rag: new RAGTool(vectorstore, this.summaries), + rag: new RAGTool(this.vectorstore, summaries), }; } - private refreshSummaries(): void { - this.summaries = this.vectorstore ? this.vectorstore.getSummaries() : 'No documents available.'; - this.tools.rag = new RAGTool(this.vectorstore, this.summaries); - } - - private formatChatHistory(): string { - let history = '\n'; - for (const message of this.messages) { - if (message.role === 'user') { - history += `${message.content}\n`; - } else if (message.role === 'assistant') { - history += `${message.content}\n`; - } - } - history += ''; - return history; - } - async askAgent(question: string, maxTurns: number = 8): Promise { - this.refreshSummaries(); console.log(`Starting query: ${question}`); this.messages.push({ role: 'user', content: question }); - const chatHistory = this.formatChatHistory(); + const chatHistory = this.history(); console.log(`Chat history: ${chatHistory}`); const systemPrompt = getReactPrompt(Object.values(this.tools), chatHistory); console.log(`System prompt: ${systemPrompt}`); -- cgit v1.2.3-70-g09d2