aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/chatbot/agentsystem/Agent.ts9
-rw-r--r--src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx195
-rw-r--r--src/client/views/nodes/chatbot/tools/BaseTool.ts4
-rw-r--r--src/client/views/nodes/chatbot/tools/CalculateTool.ts2
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateCSVTool.ts2
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts235
-rw-r--r--src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts2
-rw-r--r--src/client/views/nodes/chatbot/tools/GetDocsTool.ts2
-rw-r--r--src/client/views/nodes/chatbot/tools/NoTool.ts2
-rw-r--r--src/client/views/nodes/chatbot/tools/RAGTool.ts2
-rw-r--r--src/client/views/nodes/chatbot/tools/SearchTool.ts5
-rw-r--r--src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts2
-rw-r--r--src/client/views/nodes/chatbot/tools/WikipediaTool.ts4
-rw-r--r--src/client/views/nodes/chatbot/types/tool_types.ts (renamed from src/client/views/nodes/chatbot/tools/ToolTypes.ts)32
-rw-r--r--src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts2
15 files changed, 442 insertions, 58 deletions
diff --git a/src/client/views/nodes/chatbot/agentsystem/Agent.ts b/src/client/views/nodes/chatbot/agentsystem/Agent.ts
index 34e7cf5ea..23e7d4a9d 100644
--- a/src/client/views/nodes/chatbot/agentsystem/Agent.ts
+++ b/src/client/views/nodes/chatbot/agentsystem/Agent.ts
@@ -15,7 +15,9 @@ import { AgentMessage, AssistantMessage, Observation, PROCESSING_TYPE, Processin
import { Vectorstore } from '../vectorstore/Vectorstore';
import { getReactPrompt } from './prompts';
import { BaseTool } from '../tools/BaseTool';
-import { Parameter, ParametersType, Tool } from '../tools/ToolTypes';
+import { Parameter, ParametersType } from '../types/tool_types';
+import { CreateDocTool } from '../tools/CreateDocumentTool';
+import { DocumentOptions } from '../../../../documents/Documents';
dotenv.config();
@@ -54,6 +56,7 @@ export class Agent {
history: () => string,
csvData: () => { filename: string; id: string; text: string }[],
addLinkedUrlDoc: (url: string, id: string) => void,
+ addLinkedDoc: (doc_type: string, data: string, options: DocumentOptions, id: string) => void,
createCSVInDash: (url: string, title: string, id: string, data: string) => void
) {
// Initialize OpenAI client with API key from environment
@@ -71,7 +74,8 @@ export class Agent {
websiteInfoScraper: new WebsiteInfoScraperTool(addLinkedUrlDoc),
searchTool: new SearchTool(addLinkedUrlDoc),
createCSV: new CreateCSVTool(createCSVInDash),
- no_tool: new NoTool(),
+ noTool: new NoTool(),
+ createDoc: new CreateDocTool(addLinkedDoc),
};
}
@@ -164,6 +168,7 @@ export class Agent {
} else if (key === 'action_input') {
// Handle action input stage
const actionInput = stage[key];
+ console.log(`Action input full:`, actionInput);
console.log(`Action input:`, actionInput.inputs);
if (currentAction) {
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
index 44c231c87..4a39ee388 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -20,7 +20,7 @@ import { CsvCast, DocCast, PDFCast, RTFCast, StrCast } from '../../../../../fiel
import { Networking } from '../../../../Network';
import { DocUtils } from '../../../../documents/DocUtils';
import { DocumentType } from '../../../../documents/DocumentTypes';
-import { Docs } from '../../../../documents/Documents';
+import { Docs, DocumentOptions } from '../../../../documents/Documents';
import { DocumentManager } from '../../../../util/DocumentManager';
import { LinkManager } from '../../../../util/LinkManager';
import { ViewBoxAnnotatableComponent } from '../../../DocComponent';
@@ -33,6 +33,7 @@ import { Vectorstore } from '../vectorstore/Vectorstore';
import './ChatBox.scss';
import MessageComponentBox from './MessageComponent';
import { ProgressBar } from './ProgressBar';
+import { RichTextField } from '../../../../../fields/RichTextField';
dotenv.config();
@@ -89,7 +90,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
this.vectorstore_id = StrCast(this.dataDoc.vectorstore_id);
}
this.vectorstore = new Vectorstore(this.vectorstore_id, this.retrieveDocIds);
- this.agent = new Agent(this.vectorstore, this.retrieveSummaries, this.retrieveFormattedHistory, this.retrieveCSVData, this.addLinkedUrlDoc, this.createCSVInDash);
+ this.agent = new Agent(this.vectorstore, this.retrieveSummaries, this.retrieveFormattedHistory, this.retrieveCSVData, this.addLinkedUrlDoc, this.createDocInDash, this.createCSVInDash);
this.messagesRef = React.createRef<HTMLDivElement>();
// Reaction to update dataDoc when chat history changes
@@ -411,6 +412,185 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
};
/**
+ * Creates a text document in the dashboard and adds it for analysis.
+ * @param title The title of the doc.
+ * @param text_content The text of the document.
+ * @param options Other optional document options (e.g. color)
+ * @param id The unique ID for the document.
+ */
+
+ // @action
+ // createDocInDash = async (docs: string[]) => {
+ // console.log('DOCS HERE' + docs);
+ // docs.forEach(doc => {
+ // const parsedDoc = JSON.parse(doc);
+ // this.createIndivDocInDash(parsedDoc.doc_type, parsedDoc.data, parsedDoc.options, '');
+ // });
+ // };
+ @action
+ private createCollectionWithChildren = async (data: any): Promise<Doc[]> => {
+ console.log('Creating collection with nested documents');
+
+ // Create an array of promises for each document
+ const childDocPromises = data.map(async doc => {
+ const parsedDoc = doc;
+ console.log('Parse #3: ' + parsedDoc);
+ if (parsedDoc.doc_type !== 'collection') {
+ // Handle non-collection documents
+ return await this.whichDoc(parsedDoc.doc_type, parsedDoc.data, { backgroundColor: parsedDoc.backgroundColor, _width: parsedDoc.width, _height: parsedDoc.height }, parsedDoc.id);
+ } else {
+ // Recursively process collections
+ const nestedDocs = await this.createCollectionWithChildren(parsedDoc.data);
+ const collectionOptions: DocumentOptions = {
+ title: parsedDoc.title,
+ backgroundColor: parsedDoc.backgroundColor,
+ _width: parsedDoc.width,
+ _height: parsedDoc.height,
+ _layout_fitWidth: true,
+ _freeform_backgroundGrid: true,
+ };
+ const collectionDoc = DocCast(Docs.Create.FreeformDocument(nestedDocs, collectionOptions));
+ return collectionDoc; // Return th
+ }
+ });
+
+ // Await all child document creations concurrently
+ const nestedResults = await Promise.all(childDocPromises);
+ console.log('n' + nestedResults);
+ // Flatten any nested arrays from recursive collection calls
+ const childDocs = nestedResults.flat() as Doc[];
+ console.log('c' + childDocs);
+ childDocs.forEach(doc => {
+ console.log(DocCast(doc));
+ console.log(DocCast(doc)[DocData].data);
+ console.log(DocCast(doc)[DocData].data);
+ });
+ return childDocs;
+ };
+
+ @action
+ whichDoc = async (doc_type: string, data: string, options: DocumentOptions, id: string): Promise<Doc> => {
+ let doc;
+ switch (doc_type) {
+ case 'text':
+ doc = DocCast(Docs.Create.TextDocument(data, options));
+ break;
+ case 'flashcard':
+ doc = this.createFlashcard(data, options);
+ break;
+ case 'image':
+ doc = DocCast(Docs.Create.ImageDocument(data, options));
+ break;
+ case 'equation':
+ doc = DocCast(Docs.Create.EquationDocument('', options));
+ break;
+ case 'noteboard':
+ doc = DocCast(Docs.Create.NoteTakingDocument([], options));
+ break;
+ case 'simulation':
+ doc = DocCast(Docs.Create.SimulationDocument(options));
+ break;
+ case 'collection': {
+ // const par = JSON.parse(data);
+ // console.log('Parse #2: ' + par);
+ const arr = await this.createCollectionWithChildren(data);
+ options._layout_fitWidth = true;
+ options._freeform_backgroundGrid = true;
+
+ // const opts = { _width: 500, _height: 800, _layout_fitWidth: true, _freeform_backgroundGrid: true };
+ doc = DocCast(Docs.Create.FreeformDocument(arr, options));
+ break;
+ }
+ case 'web':
+ doc = DocCast(Docs.Create.WebDocument(data, options));
+ break;
+ case 'comparison':
+ doc = Docs.Create.ComparisonDocument('', options);
+ break;
+ case 'diagram':
+ doc = Docs.Create.DiagramDocument(options);
+ break;
+ case 'audio':
+ doc = Docs.Create.AudioDocument(data, options);
+ break;
+ case 'map':
+ doc = Docs.Create.MapDocument([], options);
+ break;
+ case 'screengrab':
+ doc = Docs.Create.ScreenshotDocument(options);
+ break;
+ case 'webcam':
+ doc = Docs.Create.WebCamDocument('', options);
+ break;
+ case 'button':
+ doc = Docs.Create.ButtonDocument(options);
+ break;
+ case 'script':
+ doc = Docs.Create.ScriptingDocument(null, options);
+ break;
+ case 'dataviz':
+ doc = Docs.Create.DataVizDocument('/users/rz/Downloads/addresses.csv', options);
+ break;
+ case 'chat':
+ doc = Docs.Create.ChatDocument(options);
+ break;
+ case 'trail':
+ doc = Docs.Create.PresDocument(options);
+ break;
+ case 'tab':
+ doc = Docs.Create.FreeformDocument([], options);
+ break;
+ case 'slide':
+ doc = Docs.Create.TreeDocument([], options);
+ break;
+ default:
+ doc = DocCast(Docs.Create.TextDocument(data, options));
+ }
+ return doc;
+ };
+
+ @action
+ createDocInDash = async (doc_type: string, data: string, options: DocumentOptions, id: string) => {
+ console.log('INDIV DOC' + doc_type);
+
+ const doc = await this.whichDoc(doc_type, data, options, id);
+
+ console.log('DOC' + doc_type);
+ const linkDoc = Docs.Create.LinkDocument(this.Document, doc);
+ LinkManager.Instance.addLink(linkDoc);
+
+ doc && this._props.addDocument?.(doc);
+ await DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {});
+ };
+
+ // TODO: DELEGATE TO DIFFERENT CLASS
+ @action
+ createFlashcard = (data: string, options: DocumentOptions) => {
+ const flashcardDeck: Doc[] = [];
+ const parsedItems: { [key: string]: string } = JSON.parse(data);
+ Object.entries(parsedItems).forEach(([key, val]) => {
+ console.log('key' + key);
+ console.log('key' + val);
+
+ const side1 = Docs.Create.CenteredTextCreator('question', key, options);
+ const side2 = Docs.Create.CenteredTextCreator('answer', val, options);
+ const doc = DocCast(Docs.Create.FlashcardDocument(data, side1, side2, { _width: 300, _height: 300 }));
+ this._props.addDocument?.(doc);
+ flashcardDeck.push(doc);
+ });
+ const col = DocCast(
+ Docs.Create.CarouselDocument(flashcardDeck, {
+ title: options.title,
+ _width: 300,
+ _height: 300,
+ _layout_fitWidth: false,
+ _layout_autoHeight: true,
+ })
+ );
+ return col;
+ };
+
+ /**
* Event handler to manage citations click in the message components.
* @param citation The citation object clicked by the user.
*/
@@ -709,17 +889,10 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
</div>
<div className="chat-messages" ref={this.messagesRef}>
{this.history.map((message, index) => (
- <MessageComponentBox key={index} message={message} index={index} onFollowUpClick={this.handleFollowUpClick} onCitationClick={this.handleCitationClick} updateMessageCitations={this.updateMessageCitations} />
+ <MessageComponentBox key={index} message={message} onFollowUpClick={this.handleFollowUpClick} onCitationClick={this.handleCitationClick} updateMessageCitations={this.updateMessageCitations} />
))}
{this.current_message && (
- <MessageComponentBox
- key={this.history.length}
- message={this.current_message}
- index={this.history.length}
- onFollowUpClick={this.handleFollowUpClick}
- onCitationClick={this.handleCitationClick}
- updateMessageCitations={this.updateMessageCitations}
- />
+ <MessageComponentBox key={this.history.length} message={this.current_message} onFollowUpClick={this.handleFollowUpClick} onCitationClick={this.handleCitationClick} updateMessageCitations={this.updateMessageCitations} />
)}
</div>
<form onSubmit={this.askGPT} className="chat-input">
diff --git a/src/client/views/nodes/chatbot/tools/BaseTool.ts b/src/client/views/nodes/chatbot/tools/BaseTool.ts
index 58cd514d9..05ca83b26 100644
--- a/src/client/views/nodes/chatbot/tools/BaseTool.ts
+++ b/src/client/views/nodes/chatbot/tools/BaseTool.ts
@@ -1,5 +1,5 @@
import { Observation } from '../types/types';
-import { Parameter, Tool, ParametersType } from './ToolTypes';
+import { Parameter, ParametersType } from '../types/tool_types';
/**
* @file BaseTool.ts
@@ -14,7 +14,7 @@ import { Parameter, Tool, ParametersType } from './ToolTypes';
* It is generic over a type parameter `P`, which extends `ReadonlyArray<Parameter>`.
* This means `P` is a readonly array of `Parameter` objects that cannot be modified (immutable).
*/
-export abstract class BaseTool<P extends ReadonlyArray<Parameter>> implements Tool<P> {
+export abstract class BaseTool<P extends ReadonlyArray<Parameter>> {
// The name of the tool (e.g., "calculate", "searchTool")
name: string;
// A description of the tool's functionality
diff --git a/src/client/views/nodes/chatbot/tools/CalculateTool.ts b/src/client/views/nodes/chatbot/tools/CalculateTool.ts
index e96c9a98a..139ede8f0 100644
--- a/src/client/views/nodes/chatbot/tools/CalculateTool.ts
+++ b/src/client/views/nodes/chatbot/tools/CalculateTool.ts
@@ -1,5 +1,5 @@
import { Observation } from '../types/types';
-import { ParametersType } from './ToolTypes';
+import { ParametersType } from '../types/tool_types';
import { BaseTool } from './BaseTool';
const calculateToolParams = [
diff --git a/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts b/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts
index b321d98ba..2cc513d6c 100644
--- a/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts
+++ b/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts
@@ -1,7 +1,7 @@
import { BaseTool } from './BaseTool';
import { Networking } from '../../../../Network';
import { Observation } from '../types/types';
-import { ParametersType } from './ToolTypes';
+import { ParametersType } from '../types/tool_types';
const createCSVToolParams = [
{
diff --git a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
new file mode 100644
index 000000000..0b83ff24f
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
@@ -0,0 +1,235 @@
+import { v4 as uuidv4 } from 'uuid';
+import { BaseTool } from './BaseTool';
+import { Observation } from '../types/types';
+import { ParametersType } from '../types/tool_types';
+import { DocumentOptions } from '../../../../documents/Documents';
+
+const example = [
+ {
+ doc_type: 'collection',
+ title: 'Science Collection',
+ data: [
+ {
+ doc_type: 'flashcard',
+ title: 'Photosynthesis',
+ data: { 'What is photosynthesis?': 'The process by which plants make food.' },
+ backgroundColor: '#00ff00',
+ width: 300,
+ height: 300,
+ },
+ {
+ doc_type: 'text',
+ title: 'Water Cycle',
+ data: 'The continuous movement of water on, above, and below the Earth’s surface.',
+ width: 300,
+ height: 300,
+ },
+ {
+ doc_type: 'collection',
+ title: 'Advanced Biology',
+ data: [
+ {
+ doc_type: 'flashcard',
+ title: 'Respiration',
+ data: { 'What is respiration?': 'Conversion of oxygen and glucose to energy.' },
+ backgroundColor: '#00ff00',
+ width: 300,
+ height: 300,
+ },
+ {
+ doc_type: 'text',
+ title: 'Cell Structure',
+ data: 'Cells are the basic building blocks of all living organisms.',
+ width: 300,
+ height: 300,
+ },
+ ],
+ width: 600,
+ height: 600,
+ },
+ ],
+ width: 600,
+ height: 600,
+ },
+];
+
+// Stringify the entire structure for transmission if needed
+const finalJsonString = JSON.stringify(example);
+
+const docInstructions = {
+ collection: {
+ description:
+ 'A recursive collection of documents as a stringified array. Each document can be a "text", "flashcard", "image", "web", "image", "comparison", "equation", "noteboard", "simulation", "diagram", "map", "screengrab", "webcam", "button", or another "collection".',
+ example: finalJsonString,
+ // example: [
+ // {
+ // doc_type: 'collection',
+ // title: 'Science Collection',
+ // data: [
+ // {
+ // doc_type: 'flashcard',
+ // title: 'Photosynthesis',
+ // data: { 'What is photosynthesis?': 'The process by which plants make food.' },
+ // width: 300,
+ // height: 300,
+ // backgroundColor: '#0000FF',
+ // },
+ // {
+ // doc_type: 'text',
+ // title: 'Water Cycle',
+ // data: 'The continuous movement of water on, above, and below the Earth’s surface.',
+ // width: 300,
+ // height: 300,
+ // },
+ // {
+ // doc_type: 'collection',
+ // title: 'Advanced Biology',
+ // data: [
+ // {
+ // doc_type: 'flashcard',
+ // title: 'Respiration',
+ // data: { 'What is respiration?': 'Conversion of oxygen and glucose to energy.' },
+ // width: 300,
+ // height: 300,
+ // },
+ // {
+ // doc_type: 'text',
+ // title: 'Cell Structure',
+ // data: 'Cells are the basic building blocks of all living organisms.',
+ // width: 300,
+ // height: 300,
+ // },
+ // ],
+ // width: 600,
+ // height: 600,
+ // },
+ // ],
+ // width: 600,
+ // height: 600,
+ // },
+ // ],
+ },
+ text: 'Provide text content as a plain string. Example: "This is a standalone text document."',
+ flashcard: 'A dictionary mapping the front to the back of the flashcard. Example: {"Question":"Answer"}',
+ flashcardDeck: 'A collection of flashcards under a common theme.',
+ image: 'A URL to an image. Example: "https://example.com/image.jpg"',
+ web: 'A URL to a webpage. Example: "https://example.com"',
+ equation: 'Create a equation document.',
+ noteboard: 'Create a noteboard document',
+ comparison: 'Create a comparison document',
+ simulation: 'Create a simulation document',
+} as const;
+
+const createDocToolParams = [
+ {
+ name: 'data',
+ type: 'string', // Accepts either string or array, supporting individual and nested data
+ description: docInstructions,
+ required: true,
+ },
+ {
+ name: 'doc_type',
+ type: 'string',
+ description: 'The type of the document. Options: "collection", "text", "flashcard", "image", "web".',
+ required: true,
+ },
+ {
+ name: 'title',
+ type: 'string',
+ description: 'The title of the document.',
+ required: true,
+ },
+ {
+ name: 'background_color',
+ type: 'string',
+ description: 'The background color of the document as a hex string.',
+ required: false,
+ },
+ {
+ name: 'font_color',
+ type: 'string',
+ description: 'The font color of the document as a hex string.',
+ required: false,
+ },
+ {
+ name: 'width',
+ type: 'number',
+ description: 'The width of the document in pixels.',
+ required: true,
+ },
+ {
+ name: 'height',
+ type: 'number',
+ description: 'The height of the document in pixels.',
+ required: true,
+ },
+] as const;
+
+const createListDocToolParams = [
+ {
+ name: 'docs',
+ type: 'string', // Array of stringified JSON objects
+ description:
+ 'Array of documents in stringified JSON format. Each item in the array should be an individual stringified JSON object. Each document can be of type "text", "flashcard", "image", "web", or "collection" (for nested documents). ' +
+ 'Use this structure for nesting collections within collections. Each document should follow the structure in ' +
+ createDocToolParams +
+ '. Example: ' +
+ finalJsonString,
+ //["{"doc_type":"collection","title":"Science Topics","data":"[\\"{\\\\"doc_type\\\\":\\\\"text\\\\",\\\\"title\\\\":\\\\"Photosynthesis\\\\",\\\\"background_color\\\\":\\\\""#0000FF"\\\\",\\\\"data\\\\":\\\\"Photosynthesis is the process by which plants make food.\\\\",\\\\"width\\\\":300,\\\\"height\\\\":300}\\",\\"{\\\\"doc_type\\\\":\\\\"collection\\\\",\\\\"title\\\\":\\\\"Advanced Biology\\\\",\\\\"data\\\\":\\\\"[\\\\"{\\\\"doc_type\\\\":\\\\"flashcard\\\\",\\\\"title\\\\":\\\\"Respiration\\\\",\\\\"data\\\\":{\\\\"What is respiration?\\\\":\\\\"Conversion of oxygen and glucose to energy.\\\\"},\\\\"width\\\\":300,\\\\"height\\\\":300}\\",\\\\"{\\\\"doc_type\\\\":\\\\"text\\\\",\\\\"title\\\\":\\\\"Cell Structure\\\\",\\\\"data\\\\":\\\\"Cells are the basic building blocks of all living organisms.\\\\",\\\\"width\\\\":300,\\\\"height\\\\":300}\\"]\\\\",\\\\"width\\\\":600,\\\\"height\\\\":600}\\"]","width":600,"height":600}"]',
+
+ //["{"doc_type":"collection","title":"Science Topics","data":["{\\"doc_type\\":\\"text\\",\\"title\\":\\"Photosynthesis\\",\\"data\\":\\"Photosynthesis is the process by which plants make food.\\",\\"width\\":300,\\"height\\":300}","{\\"doc_type\\":\\"collection\\",\\"title\\":\\"Advanced Biology\\",\\"data\\":["{\\"doc_type\\":\\"flashcard\\",\\"title\\":\\"Respiration\\",\\"data\\":{\\"What is respiration?\\":\\"Conversion of oxygen and glucose to energy.\\"},\\"width\\":300,\\"height\\":300}","{\\"doc_type\\":\\"text\\",\\"title\\":\\"Cell Structure\\",\\"data\\":\\"Cells are the basic building blocks of all living organisms.\\",\\"width\\":300,\\"height\\":300}"],\\"width\\":600,\\"height\\":600}"],"width":600,"height":600}"]',
+ required: true,
+ },
+] as const;
+
+type CreateListDocToolParamsType = typeof createListDocToolParams;
+// type CreateDocToolParamsType = typeof createDocToolParams;
+
+export class CreateDocTool extends BaseTool<CreateListDocToolParamsType> {
+ private _addLinkedDoc: (doc_type: string, data: string, options: DocumentOptions, id: string) => void;
+
+ constructor(addLinkedDoc: (doc_type: string, data: string, options: DocumentOptions, id: string) => void) {
+ super(
+ 'createDoc',
+ 'Creates one or more documents that best fit users request',
+ createListDocToolParams,
+ 'Modify the data parameter and include title (and optionally color) for the document.',
+ 'Creates one or more documents represented by an array of strings with the provided content based on the instructions ' +
+ docInstructions +
+ 'Use if the user wants to create something that aligns with a document type in dash like a flashcard, flashcard deck/stack, or textbox or text document of some sort. Can use after a search or other tool to save information.'
+ );
+ this._addLinkedDoc = addLinkedDoc;
+ }
+
+ async execute(args: ParametersType<CreateListDocToolParamsType>): Promise<Observation[]> {
+ /**
+ * loop through each collection calling the
+ */
+
+ try {
+ console.log('EXE' + args.docs);
+ const parsedDoc = JSON.parse(args.docs);
+ console.log('parsed' + parsedDoc);
+ parsedDoc.forEach(doc => {
+ // console.log('THIS DOC' + firstDoc);
+ // console.log(typeof firstDoc);
+ // const doc = JSON.parse(firstDoc);
+ // console.log('NEW DOC' + doc);
+ // console.log('TYPE' + doc['doc_type']);
+ // console.log('WIDTH' + doc['width']);
+ // console.log('HEIGHT' + doc['height']);
+
+ this._addLinkedDoc(
+ doc['doc_type'],
+ doc['data'],
+ { title: doc['title'], backgroundColor: doc['backgroundColor'], text_fontColor: doc['font_color'], _width: doc['width'], _height: doc['height'], _layout_fitWidth: false, _layout_autoHeight: true },
+ uuidv4()
+ );
+ });
+ // this._addLinkedDoc(args.doc_type, args.data, { title: args.title, backgroundColor: args.background_color, text_fontColor: args.font_color }, uuidv4());
+ return [{ type: 'text', text: 'Created document.' }];
+ } catch (error) {
+ return [{ type: 'text', text: 'Error creating text document, ' + error }];
+ }
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts b/src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts
index d9b75219d..97b9ee023 100644
--- a/src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts
+++ b/src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts
@@ -1,5 +1,5 @@
import { Observation } from '../types/types';
-import { ParametersType } from './ToolTypes';
+import { ParametersType } from '../types/tool_types';
import { BaseTool } from './BaseTool';
const dataAnalysisToolParams = [
diff --git a/src/client/views/nodes/chatbot/tools/GetDocsTool.ts b/src/client/views/nodes/chatbot/tools/GetDocsTool.ts
index 26756522c..4286e7ffe 100644
--- a/src/client/views/nodes/chatbot/tools/GetDocsTool.ts
+++ b/src/client/views/nodes/chatbot/tools/GetDocsTool.ts
@@ -1,5 +1,5 @@
import { Observation } from '../types/types';
-import { ParametersType } from './ToolTypes';
+import { ParametersType } from '../types/tool_types';
import { BaseTool } from './BaseTool';
import { DocServer } from '../../../../DocServer';
import { Docs } from '../../../../documents/Documents';
diff --git a/src/client/views/nodes/chatbot/tools/NoTool.ts b/src/client/views/nodes/chatbot/tools/NoTool.ts
index a92e3fa23..5d652fd8d 100644
--- a/src/client/views/nodes/chatbot/tools/NoTool.ts
+++ b/src/client/views/nodes/chatbot/tools/NoTool.ts
@@ -1,6 +1,6 @@
import { BaseTool } from './BaseTool';
import { Observation } from '../types/types';
-import { ParametersType } from './ToolTypes';
+import { ParametersType } from '../types/tool_types';
const noToolParams = [] as const;
diff --git a/src/client/views/nodes/chatbot/tools/RAGTool.ts b/src/client/views/nodes/chatbot/tools/RAGTool.ts
index 482069f36..fcd93a07a 100644
--- a/src/client/views/nodes/chatbot/tools/RAGTool.ts
+++ b/src/client/views/nodes/chatbot/tools/RAGTool.ts
@@ -1,6 +1,6 @@
import { Networking } from '../../../../Network';
import { Observation, RAGChunk } from '../types/types';
-import { ParametersType } from './ToolTypes';
+import { ParametersType } from '../types/tool_types';
import { Vectorstore } from '../vectorstore/Vectorstore';
import { BaseTool } from './BaseTool';
diff --git a/src/client/views/nodes/chatbot/tools/SearchTool.ts b/src/client/views/nodes/chatbot/tools/SearchTool.ts
index fd5144dd6..03340aae5 100644
--- a/src/client/views/nodes/chatbot/tools/SearchTool.ts
+++ b/src/client/views/nodes/chatbot/tools/SearchTool.ts
@@ -2,7 +2,7 @@ import { v4 as uuidv4 } from 'uuid';
import { Networking } from '../../../../Network';
import { BaseTool } from './BaseTool';
import { Observation } from '../types/types';
-import { ParametersType } from './ToolTypes';
+import { ParametersType } from '../types/tool_types';
const searchToolParams = [
{
@@ -44,9 +44,10 @@ export class SearchTool extends BaseTool<SearchToolParamsType> {
});
const data = results.map((result: { url: string; snippet: string }) => {
const id = uuidv4();
+ this._addLinkedUrlDoc(result.url, id);
return {
type: 'text',
- text: `<chunk chunk_id="${id}" chunk_type="text"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
+ text: `<chunk chunk_id="${id}" chunk_type="url"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
};
});
return data;
diff --git a/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts b/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts
index f2e3863a6..ce659e344 100644
--- a/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts
+++ b/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts
@@ -2,7 +2,7 @@ import { v4 as uuidv4 } from 'uuid';
import { Networking } from '../../../../Network';
import { BaseTool } from './BaseTool';
import { Observation } from '../types/types';
-import { ParametersType } from './ToolTypes';
+import { ParametersType } from '../types/tool_types';
const websiteInfoScraperToolParams = [
{
diff --git a/src/client/views/nodes/chatbot/tools/WikipediaTool.ts b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
index 4fcffe2ed..f2dbf3cfd 100644
--- a/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
+++ b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
@@ -2,7 +2,7 @@ import { v4 as uuidv4 } from 'uuid';
import { Networking } from '../../../../Network';
import { BaseTool } from './BaseTool';
import { Observation } from '../types/types';
-import { ParametersType } from './ToolTypes';
+import { ParametersType } from '../types/tool_types';
const wikipediaToolParams = [
{
@@ -38,7 +38,7 @@ export class WikipediaTool extends BaseTool<WikipediaToolParamsType> {
return [
{
type: 'text',
- text: `<chunk chunk_id="${id}" chunk_type="text"> ${text} </chunk>`,
+ text: `<chunk chunk_id="${id}" chunk_type="url"> ${text} </chunk>`,
},
];
} catch (error) {
diff --git a/src/client/views/nodes/chatbot/tools/ToolTypes.ts b/src/client/views/nodes/chatbot/types/tool_types.ts
index d47a38952..c1150534d 100644
--- a/src/client/views/nodes/chatbot/tools/ToolTypes.ts
+++ b/src/client/views/nodes/chatbot/types/tool_types.ts
@@ -1,34 +1,4 @@
-import { Observation } from '../types/types';
-
-/**
- * The `Tool` interface represents a generic tool in the system.
- * It is generic over a type parameter `P`, which extends `ReadonlyArray<Parameter>`.
- * @template P - An array of `Parameter` objects defining the tool's parameters.
- */
-export interface Tool<P extends ReadonlyArray<Parameter>> {
- // The name of the tool (e.g., "calculate", "searchTool")
- name: string;
- // A description of the tool's functionality
- description: string;
- // An array of parameter definitions for the tool
- parameterRules: P;
- // Guidelines for how to handle citations when using the tool
- citationRules: string;
- // A brief summary of the tool's purpose
- briefSummary: string;
- /**
- * Executes the tool's main functionality.
- * @param args - The arguments for execution, with types inferred from `ParametersType<P>`.
- * @returns A promise that resolves to an array of `Observation` objects.
- */
- execute: (args: ParametersType<P>) => Promise<Observation[]>;
- /**
- * Generates an action rule object that describes the tool's usage.
- * @returns An object representing the tool's action rules.
- */
- getActionRule: () => Record<string, unknown>;
-}
-
+import { Observation } from './types';
/**
* The `Parameter` type defines the structure of a parameter configuration.
*/
diff --git a/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts b/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
index f96f55997..5ed784559 100644
--- a/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
+++ b/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
@@ -37,7 +37,7 @@ export class Vectorstore {
* @param doc_ids A function that returns a list of document IDs.
*/
constructor(id: string, doc_ids: () => string[]) {
- const pineconeApiKey = process.env.PINECONE_API_KEY;
+ const pineconeApiKey = '51738e9a-bea2-4c11-b6bf-48a825e774dc';
if (!pineconeApiKey) {
throw new Error('PINECONE_API_KEY is not defined.');
}