aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/ChatBox/Agent.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/ChatBox/Agent.ts')
-rw-r--r--src/client/views/nodes/ChatBox/Agent.ts63
1 files changed, 36 insertions, 27 deletions
diff --git a/src/client/views/nodes/ChatBox/Agent.ts b/src/client/views/nodes/ChatBox/Agent.ts
index 6f42c08b9..eaa17d283 100644
--- a/src/client/views/nodes/ChatBox/Agent.ts
+++ b/src/client/views/nodes/ChatBox/Agent.ts
@@ -15,6 +15,7 @@ import { on } from 'events';
import { v4 as uuidv4 } from 'uuid';
import { AnswerParser } from './AnswerParser';
import { StreamedAnswerParser } from './StreamedAnswerParser';
+import { CreateCSVTool } from './tools/CreateCSVTool';
dotenv.config();
@@ -33,7 +34,14 @@ export class Agent {
private processingInfo: ProcessingInfo[] = [];
private streamedAnswerParser: StreamedAnswerParser = new StreamedAnswerParser();
- constructor(_vectorstore: Vectorstore, summaries: () => string, history: () => string, csvData: () => { filename: string; id: string; text: string }[], addLinkedUrlDoc: (url: string, id: string) => void) {
+ constructor(
+ _vectorstore: Vectorstore,
+ summaries: () => string,
+ history: () => string,
+ csvData: () => { filename: string; id: string; text: string }[],
+ addLinkedUrlDoc: (url: string, id: string) => void,
+ createCSVInDash: (url: string, title: string, id: string, data: string) => void
+ ) {
this.client = new OpenAI({ apiKey: process.env.OPENAI_KEY, dangerouslyAllowBrowser: true });
this.vectorstore = _vectorstore;
this._history = history;
@@ -45,6 +53,7 @@ export class Agent {
dataAnalysis: new DataAnalysisTool(csvData),
websiteInfoScraper: new WebsiteInfoScraperTool(addLinkedUrlDoc),
searchTool: new SearchTool(addLinkedUrlDoc),
+ createCSV: new CreateCSVTool(createCSVInDash),
no_tool: new NoTool(),
};
}
@@ -114,7 +123,7 @@ export class Agent {
}
} else if (key === 'action_input') {
const actionInput = stage[key];
- console.log(`Action input:`, actionInput);
+ console.log(`Action input:`, actionInput.inputs);
if (currentAction) {
try {
// Parse the inputs
@@ -204,31 +213,31 @@ export class Agent {
const tool = this.tools[action];
const args: Record<string, any> = {};
- for (const paramName in tool.parameters) {
- if (actionInput[paramName] !== undefined) {
- if (Array.isArray(actionInput[paramName])) {
- // If the input is already an array, use it as is
- args[paramName] = actionInput[paramName];
- } else if (typeof actionInput[paramName] === 'object' && actionInput[paramName] !== null) {
- // If the input is an object, check if it has multiple of the same tag
- const values = Object.values(actionInput[paramName]);
- if (values.length > 1) {
- // If there are multiple values, convert to an array
- args[paramName] = values;
- } else {
- // If there's only one value, use it directly
- args[paramName] = values[0];
- }
- } else {
- // For single values, use them as is
- args[paramName] = actionInput[paramName];
- }
- } else if (tool.parameters[paramName].required === 'true') {
- throw new Error(`Missing required parameter '${paramName}' for action '${action}'`);
- }
- }
-
- return await tool.execute(args);
+ // for (const paramName in tool.parameters) {
+ // if (actionInput[paramName] !== undefined) {
+ // if (Array.isArray(actionInput[paramName])) {
+ // // If the input is already an array, use it as is
+ // args[paramName] = actionInput[paramName];
+ // } else if (typeof actionInput[paramName] === 'object' && actionInput[paramName] !== null) {
+ // // If the input is an object, check if it has multiple of the same tag
+ // const values = Object.values(actionInput[paramName]);
+ // if (values.length > 1) {
+ // // If there are multiple values, convert to an array
+ // args[paramName] = values;
+ // } else {
+ // // If there's only one value, use it directly
+ // args[paramName] = values[0];
+ // }
+ // } else {
+ // // For single values, use them as is
+ // args[paramName] = actionInput[paramName];
+ // }
+ // } else if (tool.parameters[paramName].required === 'true') {
+ // throw new Error(`Missing required parameter '${paramName}' for action '${action}'`);
+ // }
+ // }
+
+ return await tool.execute(actionInput);
}
private parseActionInputs(inputs: any): Record<string, string | string[]> {