aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/ChatBox/Agent.ts
diff options
context:
space:
mode:
authorA.J. Shulman <Shulman.aj@gmail.com>2024-07-16 11:11:53 -0400
committerA.J. Shulman <Shulman.aj@gmail.com>2024-07-16 11:11:53 -0400
commit65179e8b0519aa4ccf28afc4c429262ecf7a62f3 (patch)
tree016f43f1ad9170adecb3ea939abc28c74a451382 /src/client/views/nodes/ChatBox/Agent.ts
parent5a3d5b23c927c5fb05c7eeef1e3bb91479ef896a (diff)
attempting annotations for image chunks
Diffstat (limited to 'src/client/views/nodes/ChatBox/Agent.ts')
-rw-r--r--src/client/views/nodes/ChatBox/Agent.ts32
1 files changed, 8 insertions, 24 deletions
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<string, Tool<any>>;
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 = '<chat_history>\n';
- for (const message of this.messages) {
- if (message.role === 'user') {
- history += `<user>${message.content}</user>\n`;
- } else if (message.role === 'assistant') {
- history += `<assistant>${message.content}</assistant>\n`;
- }
- }
- history += '</chat_history>';
- return history;
- }
-
async askAgent(question: string, maxTurns: number = 8): Promise<string> {
- 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}`);