aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/chatbot/tools')
-rw-r--r--src/client/views/nodes/chatbot/tools/BaseTool.ts87
-rw-r--r--src/client/views/nodes/chatbot/tools/CalculateTool.ts33
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts158
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateCSVTool.ts59
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts497
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts57
-rw-r--r--src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts67
-rw-r--r--src/client/views/nodes/chatbot/tools/GetDocsTool.ts48
-rw-r--r--src/client/views/nodes/chatbot/tools/ImageCreationTool.ts68
-rw-r--r--src/client/views/nodes/chatbot/tools/NoTool.ts25
-rw-r--r--src/client/views/nodes/chatbot/tools/RAGTool.ts90
-rw-r--r--src/client/views/nodes/chatbot/tools/SearchTool.ts72
-rw-r--r--src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts103
-rw-r--r--src/client/views/nodes/chatbot/tools/WikipediaTool.ts50
14 files changed, 1414 insertions, 0 deletions
diff --git a/src/client/views/nodes/chatbot/tools/BaseTool.ts b/src/client/views/nodes/chatbot/tools/BaseTool.ts
new file mode 100644
index 000000000..8800e2238
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/BaseTool.ts
@@ -0,0 +1,87 @@
+import { Observation } from '../types/types';
+import { Parameter, ParametersType, ToolInfo } from '../types/tool_types';
+
+/**
+ * @file BaseTool.ts
+ * @description This file defines the abstract `BaseTool` class, which serves as a blueprint
+ * for tool implementations in the AI assistant system. Each tool has a name, description,
+ * parameters, and citation rules. The `BaseTool` class provides a structure for executing actions
+ * and retrieving action rules for use within the assistant's workflow.
+ */
+
+/**
+ * The `BaseTool` class is an abstract class that implements the `Tool` interface.
+ * 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>> {
+ // 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;
+
+ /**
+ * Constructs a new `BaseTool` instance.
+ * @param name - The name of the tool.
+ * @param description - A detailed description of what the tool does.
+ * @param parameterRules - A readonly array of parameter definitions (`ReadonlyArray<Parameter>`).
+ * @param citationRules - Rules or guidelines for citations.
+ */
+ constructor(toolInfo: ToolInfo<P>) {
+ this.name = toolInfo.name;
+ this.description = toolInfo.description;
+ this.parameterRules = toolInfo.parameterRules;
+ this.citationRules = toolInfo.citationRules;
+ }
+
+ /**
+ * The `execute` method is abstract and must be implemented by subclasses.
+ * It defines the action the tool performs when executed.
+ * @param args - The arguments for the tool's execution, whose types are inferred from `ParametersType<P>`.
+ * @returns A promise that resolves to an array of `Observation` objects.
+ */
+ abstract execute(args: ParametersType<P>): Promise<Observation[]>;
+
+ /**
+ * This is a hacky way for a tool to ignore required parameter errors.
+ * Used by crateDocTool to allow processing of simple arrays of Documents
+ * where the array doesn't conform to a normal Doc structure.
+ * @param inputParam
+ * @returns
+ */
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ inputValidator(inputParam: ParametersType<readonly Parameter[]>) {
+ return false;
+ }
+
+ /**
+ * Generates an action rule object that describes the tool's usage.
+ * This is useful for dynamically generating documentation or for tools that need to expose their parameters at runtime.
+ * @returns An object containing the tool's name, description, and parameter definitions.
+ */
+ getActionRule(): Record<string, unknown> {
+ return {
+ tool: this.name,
+ description: this.description,
+ citationRules: this.citationRules,
+ parameters: this.parameterRules.reduce(
+ (acc, param) => {
+ // Build an object for each parameter without the 'name' property, since it's used as the key
+ acc[param.name] = {
+ type: param.type,
+ description: param.description,
+ required: param.required,
+ // Conditionally include 'max_inputs' only if it is defined
+ ...(param.max_inputs !== undefined && { max_inputs: param.max_inputs }),
+ } as Omit<P[number], 'name'>; // Type assertion to exclude the 'name' property
+ return acc;
+ },
+ {} as Record<string, Omit<P[number], 'name'>> // Initialize the accumulator as an empty object
+ ),
+ };
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/CalculateTool.ts b/src/client/views/nodes/chatbot/tools/CalculateTool.ts
new file mode 100644
index 000000000..ca7223803
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/CalculateTool.ts
@@ -0,0 +1,33 @@
+import { Observation } from '../types/types';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+import { BaseTool } from './BaseTool';
+
+const calculateToolParams = [
+ {
+ name: 'expression',
+ type: 'string',
+ description: 'The mathematical expression to evaluate',
+ required: true,
+ },
+] as const;
+
+type CalculateToolParamsType = typeof calculateToolParams;
+
+const calculateToolInfo: ToolInfo<CalculateToolParamsType> = {
+ name: 'calculate',
+ citationRules: 'No citation needed.',
+ parameterRules: calculateToolParams,
+ description: 'Runs a calculation and returns the number - uses JavaScript so be sure to use floating point syntax if necessary',
+};
+
+export class CalculateTool extends BaseTool<CalculateToolParamsType> {
+ constructor() {
+ super(calculateToolInfo);
+ }
+
+ async execute(args: ParametersType<CalculateToolParamsType>): Promise<Observation[]> {
+ // TypeScript will ensure 'args.expression' is a string based on the param config
+ const result = eval(args.expression); // Be cautious with eval(), as it can be dangerous. Consider using a safer alternative.
+ return [{ type: 'text', text: result.toString() }];
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts b/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts
new file mode 100644
index 000000000..ef4bbbc47
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts
@@ -0,0 +1,158 @@
+import { toLower } from 'lodash';
+import { Doc } from '../../../../../fields/Doc';
+import { Id } from '../../../../../fields/FieldSymbols';
+import { DocumentOptions } from '../../../../documents/Documents';
+import { parsedDoc } from '../chatboxcomponents/ChatBox';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+import { Observation } from '../types/types';
+import { BaseTool } from './BaseTool';
+import { supportedDocTypes } from './CreateDocumentTool';
+
+const standardOptions = ['title', 'backgroundColor'];
+/**
+ * Description of document options and data field for each type.
+ */
+const documentTypesInfo: { [key in supportedDocTypes]: { options: string[]; dataDescription: string } } = {
+ [supportedDocumentTypes.flashcard]: {
+ options: [...standardOptions, 'fontColor', 'text_align'],
+ dataDescription: 'an array of two strings. the first string contains a question, and the second string contains an answer',
+ },
+ [supportedDocumentTypes.text]: {
+ options: [...standardOptions, 'fontColor', 'text_align'],
+ dataDescription: 'The text content of the document.',
+ },
+ [supportedDocumentTypes.html]: {
+ options: [],
+ dataDescription: 'The HTML-formatted text content of the document.',
+ },
+ [supportedDocumentTypes.equation]: {
+ options: [...standardOptions, 'fontColor'],
+ dataDescription: 'The equation content as a string.',
+ },
+ [supportedDocumentTypes.functionplot]: {
+ options: [...standardOptions, 'function_definition'],
+ dataDescription: 'The function definition(s) for plotting. Provide as a string or array of function definitions.',
+ },
+ [supportedDocumentTypes.dataviz]: {
+ options: [...standardOptions, 'chartType'],
+ dataDescription: 'A string of comma-separated values representing the CSV data.',
+ },
+ [supportedDocumentTypes.notetaking]: {
+ options: standardOptions,
+ dataDescription: 'The initial content or structure for note-taking.',
+ },
+ [supportedDocumentTypes.rtf]: {
+ options: standardOptions,
+ dataDescription: 'The rich text content in RTF format.',
+ },
+ [supportedDocumentTypes.image]: {
+ options: standardOptions,
+ dataDescription: 'The image content as an image file URL.',
+ },
+ [supportedDocumentTypes.pdf]: {
+ options: standardOptions,
+ dataDescription: 'the pdf content as a PDF file url.',
+ },
+ [supportedDocumentTypes.audio]: {
+ options: standardOptions,
+ dataDescription: 'The audio content as a file url.',
+ },
+ [supportedDocumentTypes.video]: {
+ options: standardOptions,
+ dataDescription: 'The video content as a file url.',
+ },
+ [supportedDocumentTypes.message]: {
+ options: standardOptions,
+ dataDescription: 'The message content of the document.',
+ },
+ [supportedDocumentTypes.diagram]: {
+ options: ['title', 'backgroundColor'],
+ dataDescription: 'diagram content as a text string in Mermaid format.',
+ },
+ [supportedDocumentTypes.script]: {
+ options: ['title', 'backgroundColor'],
+ dataDescription: 'The compilable JavaScript code. Use this for creating scripts.',
+ },
+};
+
+const createAnyDocumentToolParams = [
+ {
+ name: 'document_type',
+ type: 'string',
+ description: `The type of the document to create. Supported types are: ${Object.values(supportedDocTypes).join(', ')}`,
+ required: true,
+ },
+ {
+ name: 'data',
+ type: 'string',
+ description: 'The content or data of the document. The exact format depends on the document type.',
+ required: true,
+ },
+ {
+ name: 'options',
+ type: 'string',
+ required: false,
+ description: `A JSON string representing the document options. Available options depend on the document type. For example:
+ ${Object.entries(documentTypesInfo).map( ([doc_type, info]) => `
+- For '${doc_type}' documents, options include: ${info.options.join(', ')}`)
+ .join('\n')}`, // prettier-ignore
+ },
+] as const;
+
+type CreateAnyDocumentToolParamsType = typeof createAnyDocumentToolParams;
+
+const createAnyDocToolInfo: ToolInfo<CreateAnyDocumentToolParamsType> = {
+ name: 'createAnyDocument',
+ description:
+ `Creates any type of document with the provided options and data.
+ Supported document types are: ${Object.values(supportedDocTypes).join(', ')}.
+ dataviz is a csv table tool, so for CSVs, use dataviz. Here are the options for each type:
+ <supported_document_types>` +
+ Object.entries(documentTypesInfo)
+ .map(
+ ([doc_type, info]) =>
+ `<document_type name="${doc_type}">
+ <data_description>${info.dataDescription}</data_description>
+ <options>` +
+ info.options.map(option => `<option>${option}</option>`).join('\n') +
+ `</options>
+ </document_type>`
+ )
+ .join('\n') +
+ `</supported_document_types>`,
+ parameterRules: createAnyDocumentToolParams,
+ citationRules: 'No citation needed.',
+};
+
+export class CreateAnyDocumentTool extends BaseTool<CreateAnyDocumentToolParamsType> {
+ private _addLinkedDoc: (doc: parsedDoc) => Doc | undefined;
+
+ constructor(addLinkedDoc: (doc: parsedDoc) => Doc | undefined) {
+ super(createAnyDocToolInfo);
+ this._addLinkedDoc = addLinkedDoc;
+ }
+
+ async execute(args: ParametersType<CreateAnyDocumentToolParamsType>): Promise<Observation[]> {
+ try {
+ const documentType = toLower(args.document_type) as unknown as supportedDocTypes;
+ const info = documentTypesInfo[documentType];
+
+ if (info === undefined) {
+ throw new Error(`Unsupported document type: ${documentType}. Supported types are: ${Object.values(supportedDocTypes).join(', ')}.`);
+ }
+
+ if (!args.data) {
+ throw new Error(`Data is required for ${documentType} documents. ${info.dataDescription}`);
+ }
+
+ const options: DocumentOptions = !args.options ? {} : JSON.parse(args.options);
+
+ // Call the function to add the linked document (add default title that can be overriden if set in options)
+ const doc = this._addLinkedDoc({ doc_type: documentType, data: args.data, title: `New ${documentType.charAt(0).toUpperCase() + documentType.slice(1)} Document`, ...options });
+
+ return [{ type: 'text', text: `Created ${documentType} document with ID ${doc?.[Id]}.` }];
+ } catch (error) {
+ return [{ type: 'text', text: 'Error creating document: ' + (error as Error).message }];
+ }
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts b/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts
new file mode 100644
index 000000000..290c48d6c
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts
@@ -0,0 +1,59 @@
+import { BaseTool } from './BaseTool';
+import { Networking } from '../../../../Network';
+import { Observation } from '../types/types';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+
+const createCSVToolParams = [
+ {
+ name: 'csvData',
+ type: 'string',
+ description: 'A string of comma-separated values representing the CSV data.',
+ required: true,
+ },
+ {
+ name: 'filename',
+ type: 'string',
+ description: 'The base name of the CSV file to be created. Should end in ".csv".',
+ required: true,
+ },
+] as const;
+
+type CreateCSVToolParamsType = typeof createCSVToolParams;
+
+const createCSVToolInfo: ToolInfo<CreateCSVToolParamsType> = {
+ name: 'createCSV',
+ description: 'Creates a CSV file from the provided CSV string and saves it to the server with a unique identifier, returning the file URL and UUID.',
+ citationRules: 'No citation needed.',
+ parameterRules: createCSVToolParams,
+};
+
+export class CreateCSVTool extends BaseTool<CreateCSVToolParamsType> {
+ private _handleCSVResult: (url: string, filename: string, id: string, data: string) => void;
+
+ constructor(handleCSVResult: (url: string, title: string, id: string, data: string) => void) {
+ super(createCSVToolInfo);
+ this._handleCSVResult = handleCSVResult;
+ }
+
+ async execute(args: ParametersType<CreateCSVToolParamsType>): Promise<Observation[]> {
+ try {
+ console.log('Creating CSV file:', args.filename, ' with data:', args.csvData);
+ const { fileUrl, id } = (await Networking.PostToServer('/createCSV', {
+ filename: args.filename,
+ data: args.csvData,
+ })) as { fileUrl: string; id: string };
+
+ this._handleCSVResult(fileUrl, args.filename, id, args.csvData);
+
+ return [
+ {
+ type: 'text',
+ text: `File successfully created: ${fileUrl}. \nNow a CSV file with this data and the name ${args.filename} is available as a user doc.`,
+ },
+ ];
+ } catch (error) {
+ console.error('Error creating CSV file:', error);
+ throw new Error('Failed to create CSV file.');
+ }
+ }
+}
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..284879a4a
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
@@ -0,0 +1,497 @@
+import { BaseTool } from './BaseTool';
+import { Observation } from '../types/types';
+import { Parameter, ParametersType, ToolInfo } from '../types/tool_types';
+import { parsedDoc } from '../chatboxcomponents/ChatBox';
+import { CollectionViewType } from '../../../../documents/DocumentTypes';
+
+/**
+ * List of supported document types that can be created via text LLM.
+ */
+export enum supportedDocTypes {
+ flashcard = 'flashcard',
+ text = 'text',
+ html = 'html',
+ equation = 'equation',
+ functionplot = 'functionplot',
+ dataviz = 'dataviz',
+ notetaking = 'notetaking',
+ audio = 'audio',
+ video = 'video',
+ pdf = 'pdf',
+ rtf = 'rtf',
+ message = 'message',
+ collection = 'collection',
+ image = 'image',
+ deck = 'deck',
+ web = 'web',
+ comparison = 'comparison',
+ diagram = 'diagram',
+ script = 'script',
+}
+/**
+ * Tthe CreateDocTool class is responsible for creating
+ * documents of various types (e.g., text, flashcards, collections) and organizing them in a
+ * structured manner. The tool supports creating dashboards with diverse document types and
+ * ensures proper placement of documents without overlap.
+ */
+
+// Example document structure for various document types
+const example = [
+ {
+ doc_type: supportedDocTypes.equation,
+ title: 'quadratic',
+ data: 'x^2 + y^2 = 3',
+ _width: 300,
+ _height: 300,
+ x: 0,
+ y: 0,
+ },
+ {
+ doc_type: supportedDocTypes.collection,
+ title: 'Advanced Biology',
+ data: [
+ {
+ doc_type: supportedDocTypes.text,
+ title: 'Cell Structure',
+ data: 'Cells are the basic building blocks of all living organisms.',
+ _width: 300,
+ _height: 300,
+ x: 500,
+ y: 0,
+ },
+ ],
+ backgroundColor: '#00ff00',
+ _width: 600,
+ _height: 600,
+ x: 600,
+ y: 0,
+ type_collection: 'tree',
+ },
+ {
+ doc_type: supportedDocTypes.image,
+ title: 'experiment',
+ data: 'https://plus.unsplash.com/premium_photo-1694819488591-a43907d1c5cc?q=80&w=2628&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
+ _width: 300,
+ _height: 300,
+ x: 600,
+ y: 300,
+ },
+ {
+ doc_type: supportedDocTypes.deck,
+ title: 'Chemistry',
+ data: [
+ {
+ doc_type: supportedDocTypes.flashcard,
+ title: 'Photosynthesis',
+ data: [
+ {
+ doc_type: supportedDocTypes.text,
+ title: 'front_Photosynthesis',
+ data: 'What is photosynthesis?',
+ _width: 300,
+ _height: 300,
+ x: 100,
+ y: 600,
+ },
+ {
+ doc_type: supportedDocTypes.text,
+ title: 'back_photosynthesis',
+ data: 'The process by which plants make food.',
+ _width: 300,
+ _height: 300,
+ x: 100,
+ y: 700,
+ },
+ ],
+ backgroundColor: '#00ff00',
+ _width: 300,
+ _height: 300,
+ x: 300,
+ y: 1000,
+ },
+ {
+ doc_type: supportedDocTypes.flashcard,
+ title: 'Photosynthesis',
+ data: [
+ {
+ doc_type: supportedDocTypes.text,
+ title: 'front_Photosynthesis',
+ data: 'What is photosynthesis?',
+ _width: 300,
+ _height: 300,
+ x: 200,
+ y: 800,
+ },
+ {
+ doc_type: supportedDocTypes.text,
+ title: 'back_photosynthesis',
+ data: 'The process by which plants make food.',
+ _width: 300,
+ _height: 300,
+ x: 100,
+ y: -100,
+ },
+ ],
+ backgroundColor: '#00ff00',
+ _width: 300,
+ _height: 300,
+ x: 10,
+ y: 70,
+ },
+ ],
+ backgroundColor: '#00ff00',
+ _width: 600,
+ _height: 600,
+ x: 200,
+ y: 800,
+ },
+ {
+ doc_type: supportedDocTypes.web,
+ title: 'Brown University Wikipedia',
+ data: 'https://en.wikipedia.org/wiki/Brown_University',
+ _width: 300,
+ _height: 300,
+ x: 1000,
+ y: 2000,
+ },
+ {
+ doc_type: supportedDocTypes.comparison,
+ title: 'WWI vs. WWII',
+ data: [
+ {
+ doc_type: supportedDocTypes.text,
+ title: 'WWI',
+ data: 'From 1914 to 1918, fighting took place across several continents, at sea and, for the first time, in the air.',
+ _width: 300,
+ _height: 300,
+ x: 100,
+ y: 100,
+ },
+ {
+ doc_type: supportedDocTypes.text,
+ title: 'WWII',
+ data: 'A devastating global conflict spanning from 1939 to 1945, saw the Allied powers fight against the Axis powers.',
+ _width: 300,
+ _height: 300,
+ x: 100,
+ y: 100,
+ },
+ ],
+ _width: 300,
+ _height: 300,
+ x: 100,
+ y: 100,
+ },
+ {
+ doc_type: supportedDocTypes.collection,
+ title: 'Science Collection',
+ data: [
+ {
+ doc_type: supportedDocTypes.flashcard,
+ title: 'Photosynthesis',
+ data: [
+ {
+ doc_type: supportedDocTypes.text,
+ title: 'front_Photosynthesis',
+ data: 'What is photosynthesis?',
+ _width: 300,
+ _height: 300,
+ },
+ {
+ doc_type: supportedDocTypes.text,
+ title: 'back_photosynthesis',
+ data: 'The process by which plants make food.',
+ _width: 300,
+ _height: 300,
+ },
+ ],
+ backgroundColor: '#00ff00',
+ _width: 300,
+ _height: 300,
+ },
+ {
+ doc_type: supportedDocTypes.web,
+ title: 'Brown University Wikipedia',
+ data: 'https://en.wikipedia.org/wiki/Brown_University',
+ _width: 300,
+ _height: 300,
+ x: 1100,
+ y: 1100,
+ },
+ {
+ doc_type: supportedDocTypes.text,
+ title: 'Water Cycle',
+ data: 'The continuous movement of water on, above, and below the Earth’s surface.',
+ _width: 300,
+ _height: 300,
+ x: 1500,
+ y: 500,
+ },
+ {
+ doc_type: supportedDocTypes.collection,
+ title: 'Advanced Biology',
+ data: [
+ {
+ doc_type: 'text',
+ title: 'Cell Structure',
+ data: 'Cells are the basic building blocks of all living organisms.',
+ _width: 300,
+ _height: 300,
+ },
+ ],
+ backgroundColor: '#00ff00',
+ _width: 600,
+ _height: 600,
+ x: 1100,
+ y: 500,
+ type_collection: 'stacking',
+ },
+ ],
+ _width: 600,
+ _height: 600,
+ x: 500,
+ y: 500,
+ type_collection: 'carousel',
+ },
+];
+
+// Stringify the entire structure for transmission if needed
+const finalJsonString = JSON.stringify(example);
+
+const standardOptions = ['title', 'backgroundColor'];
+/**
+ * Description of document options and data field for each type.
+ */
+const documentTypesInfo: { [key in supportedDocTypes]: { options: string[]; dataDescription: string } } = {
+ comparison: {
+ options: [...standardOptions, 'fontColor', 'text_align'],
+ dataDescription: 'an array of two documents of any kind that can be compared.',
+ },
+ deck: {
+ options: [...standardOptions, 'fontColor', 'text_align'],
+ dataDescription: 'an array of flashcard docs',
+ },
+ flashcard: {
+ options: [...standardOptions, 'fontColor', 'text_align'],
+ dataDescription: 'an array of two strings. the first string contains a question, and the second string contains an answer',
+ },
+ text: {
+ options: [...standardOptions, 'fontColor', 'text_align'],
+ dataDescription: 'The text content of the document.',
+ },
+ web: {
+ options: [],
+ dataDescription: 'A URL to a webpage. Example: https://en.wikipedia.org/wiki/Brown_University',
+ },
+ html: {
+ options: [],
+ dataDescription: 'The HTML-formatted text content of the document.',
+ },
+ equation: {
+ options: [...standardOptions, 'fontColor'],
+ dataDescription: 'The equation content represented as a MathML string.',
+ },
+ functionplot: {
+ options: [...standardOptions, 'function_definition'],
+ dataDescription: 'The function definition(s) for plotting. Provide as a string or array of function definitions.',
+ },
+ dataviz: {
+ options: [...standardOptions, 'chartType'],
+ dataDescription: 'A string of comma-separated values representing the CSV data.',
+ },
+ notetaking: {
+ options: standardOptions,
+ dataDescription: 'An array of related text documents with small amounts of text.',
+ },
+ rtf: {
+ options: standardOptions,
+ dataDescription: 'The rich text content in RTF format.',
+ },
+ image: {
+ options: standardOptions,
+ dataDescription: `A url string that must end with '.png', '.jpeg', '.gif', or '.jpg'`,
+ },
+ pdf: {
+ options: standardOptions,
+ dataDescription: 'the pdf content as a PDF file url.',
+ },
+ audio: {
+ options: standardOptions,
+ dataDescription: 'The audio content as a file url.',
+ },
+ video: {
+ options: standardOptions,
+ dataDescription: 'The video content as a file url.',
+ },
+ message: {
+ options: standardOptions,
+ dataDescription: 'The message content of the document.',
+ },
+ diagram: {
+ options: standardOptions,
+ dataDescription: 'diagram content as a text string in Mermaid format.',
+ },
+ script: {
+ options: standardOptions,
+ dataDescription: 'The compilable JavaScript code. Use this for creating scripts.',
+ },
+ collection: {
+ options: [...standardOptions, 'type_collection'],
+ dataDescription: 'A collection of Docs represented as an array.',
+ },
+};
+
+// Parameters for creating individual documents
+const createDocToolParams: { name: string; type: 'string' | 'number' | 'boolean' | 'string[]' | 'number[]'; description: string; required: boolean }[] = [
+ {
+ name: 'data',
+ type: 'string', // Accepts either string or array, supporting individual and nested data
+ description:
+ 'the data that describes the Document contents. For collections this is an' +
+ `Array of documents in stringified JSON format. Each item in the array should be an individual stringified JSON object. ` +
+ `Creates any type of document with the provided options and data. Supported document types are: ${Object.keys(documentTypesInfo).join(', ')}.
+ dataviz is a csv table tool, so for CSVs, use dataviz. Here are the options for each type:
+ <supported_document_types>` +
+ Object.entries(documentTypesInfo)
+ .map(
+ ([doc_type, info]) =>
+ `<document_type name="${doc_type}">
+ <data_description>${info.dataDescription}</data_description>
+ <options>` +
+ info.options.map(option => `<option>${option}</option>`).join('\n') +
+ `
+ </options>
+ </document_type>`
+ )
+ .join('\n') +
+ `</supported_document_types> An example of the structure of a collection is:` +
+ finalJsonString, // prettier-ignore,
+ required: true,
+ },
+ {
+ name: 'doc_type',
+ type: 'string',
+ description: `The type of the document. Options: ${Object.keys(documentTypesInfo).join(',')}.`,
+ required: true,
+ },
+ {
+ name: 'title',
+ type: 'string',
+ description: 'The title of the document.',
+ required: true,
+ },
+ {
+ name: 'x',
+ type: 'number',
+ description: 'The x location of the document; 0 <= x.',
+ required: true,
+ },
+ {
+ name: 'y',
+ type: 'number',
+ description: 'The y location of the document; 0 <= y.',
+ required: true,
+ },
+ {
+ name: 'backgroundColor',
+ type: 'string',
+ description: 'The background color of the document as a hex string.',
+ required: false,
+ },
+ {
+ name: 'fontColor',
+ 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,
+ },
+ {
+ name: 'type_collection',
+ type: 'string',
+ description: `the visual style for a collection doc. Options include: ${Object.values(CollectionViewType).join(',')}.`,
+ required: false,
+ },
+] as const;
+
+type CreateDocToolParamsType = typeof createDocToolParams;
+
+const createDocToolInfo: ToolInfo<CreateDocToolParamsType> = {
+ name: 'createDoc',
+ description: `Creates one or more documents that best fit the user’s request.
+ If the user requests a "dashboard," first call the search tool and then generate a variety of document types individually, with absolutely a minimum of 20 documents
+ with two stacks of flashcards that are small and it should have a couple nested freeform collections of things, each with different content and color schemes.
+ For example, create multiple individual documents, including ${Object.keys(documentTypesInfo)
+ .map(t => '"' + t + '"')
+ .join(',')}
+ If the "doc_type" parameter is missing, set it to an empty string ("").
+ Use Decks instead of Flashcards for dashboards. Decks should have at least three flashcards.
+ Really think about what documents are useful to the user. If they ask for a dashboard about the skeletal system, include flashcards, as they would be helpful.
+ Arrange the documents in a grid layout, ensuring that the x and y coordinates are calculated so no documents overlap but they should be directly next to each other with 20 padding in between.
+ Take into account the width and height of each document, spacing them appropriately to prevent collisions.
+ Use a systematic approach, such as placing each document in a grid cell based on its order, where cell dimensions match the document dimensions plus a fixed margin for spacing.
+ Do not nest all documents within a single collection unless explicitly requested by the user.
+ Instead, create a set of independent documents with diverse document types. Each type should appear separately unless specified otherwise.
+ Use the "data" parameter for document content and include title, color, and document dimensions.
+ Ensure web documents use URLs from the search tool if relevant. Each document in a dashboard should be unique and well-differentiated in type and content,
+ without repetition of similar types in any single collection.
+ When creating a dashboard, ensure that it consists of a broad range of document types.
+ Include a variety of documents, such as text, web, deck, comparison, image, and equation documents,
+ each with distinct titles and colors, following the user’s preferences.
+ Do not overuse collections or nest all document types within a single collection; instead, represent document types individually. Use this example for reference:
+ ${finalJsonString} .
+ Which documents are created should be random with different numbers of each document type and different for each dashboard.
+ Must use search tool before creating a dashboard.`,
+ parameterRules: createDocToolParams,
+ citationRules: 'No citation needed.',
+};
+
+// Tool class for creating documents
+export class CreateDocTool extends BaseTool<
+ {
+ name: string;
+ type: 'string' | 'number' | 'boolean' | 'string[]' | 'number[]';
+ description: string;
+ required: boolean;
+ }[]
+> {
+ private _addLinkedDoc: (doc: parsedDoc) => void;
+
+ constructor(addLinkedDoc: (doc: parsedDoc) => void) {
+ super(createDocToolInfo);
+ this._addLinkedDoc = addLinkedDoc;
+ }
+
+ override inputValidator(inputParam: ParametersType<readonly Parameter[]>) {
+ return !!inputParam.data;
+ }
+ // Executes the tool logic for creating documents
+ async execute(
+ args: ParametersType<
+ {
+ name: 'string';
+ type: 'string' | 'number' | 'boolean' | 'string[]' | 'number[]';
+ description: 'string';
+ required: boolean;
+ }[]
+ >
+ ): Promise<Observation[]> {
+ try {
+ const parsedDocs = args instanceof Array ? args : Object.keys(args).length === 1 && 'data' in args ? JSON.parse(args.data as string) : [args];
+ parsedDocs.forEach((pdoc: parsedDoc) => this._addLinkedDoc({ ...pdoc, _layout_fitWidth: false, _layout_autoHeight: true }));
+ 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/CreateTextDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts
new file mode 100644
index 000000000..16dc938bb
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts
@@ -0,0 +1,57 @@
+import { parsedDoc } from '../chatboxcomponents/ChatBox';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+import { Observation } from '../types/types';
+import { BaseTool } from './BaseTool';
+const createTextDocToolParams = [
+ {
+ name: 'text_content',
+ type: 'string',
+ description: 'The text content that the document will display',
+ 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,
+ // },
+] as const;
+
+type CreateTextDocToolParamsType = typeof createTextDocToolParams;
+
+const createTextDocToolInfo: ToolInfo<CreateTextDocToolParamsType> = {
+ name: 'createTextDoc',
+ description: 'Creates a text document with the provided content and title. Use if the user wants to create a textbox or text document of some sort. Can use after a search or other tool to save information.',
+ citationRules: 'No citation needed.',
+ parameterRules: createTextDocToolParams,
+};
+
+export class CreateTextDocTool extends BaseTool<CreateTextDocToolParamsType> {
+ private _addLinkedDoc: (doc: parsedDoc) => void;
+
+ constructor(addLinkedDoc: (doc: parsedDoc) => void) {
+ super(createTextDocToolInfo);
+ this._addLinkedDoc = addLinkedDoc;
+ }
+
+ async execute(args: ParametersType<CreateTextDocToolParamsType>): Promise<Observation[]> {
+ try {
+ this._addLinkedDoc({ doc_type: 'text', data: args.text_content, title: args.title });
+ return [{ type: 'text', text: 'Created text 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
new file mode 100644
index 000000000..8c5e3d9cd
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/DataAnalysisTool.ts
@@ -0,0 +1,67 @@
+import { Observation } from '../types/types';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+import { BaseTool } from './BaseTool';
+
+const dataAnalysisToolParams = [
+ {
+ name: 'csv_file_names',
+ type: 'string[]',
+ description: 'List of names of the CSV files to analyze',
+ required: true,
+ max_inputs: 3,
+ },
+] as const;
+
+type DataAnalysisToolParamsType = typeof dataAnalysisToolParams;
+
+const dataAnalysisToolInfo: ToolInfo<DataAnalysisToolParamsType> = {
+ name: 'dataAnalysis',
+ description: 'Provides the full CSV file text for your analysis based on the user query and the available CSV file(s).',
+ citationRules: 'No citation needed.',
+ parameterRules: dataAnalysisToolParams,
+};
+
+export class DataAnalysisTool extends BaseTool<DataAnalysisToolParamsType> {
+ private csv_files_function: () => { filename: string; id: string; text: string }[];
+
+ constructor(csv_files: () => { filename: string; id: string; text: string }[]) {
+ super(dataAnalysisToolInfo);
+ this.csv_files_function = csv_files;
+ }
+
+ getFileContent(filename: string): string | undefined {
+ const files = this.csv_files_function();
+ const file = files.find(f => f.filename === filename);
+ return file?.text;
+ }
+
+ getFileID(filename: string): string | undefined {
+ const files = this.csv_files_function();
+ const file = files.find(f => f.filename === filename);
+ return file?.id;
+ }
+
+ async execute(args: ParametersType<DataAnalysisToolParamsType>): Promise<Observation[]> {
+ const filenames = args.csv_file_names;
+ const results: Observation[] = [];
+
+ for (const filename of filenames) {
+ const fileContent = this.getFileContent(filename);
+ const fileID = this.getFileID(filename);
+
+ if (fileContent && fileID) {
+ results.push({
+ type: 'text',
+ text: `<chunk chunk_id="${fileID}" chunk_type="csv">${fileContent}</chunk>`,
+ });
+ } else {
+ results.push({
+ type: 'text',
+ text: `File not found: ${filename}`,
+ });
+ }
+ }
+
+ return results;
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/GetDocsTool.ts b/src/client/views/nodes/chatbot/tools/GetDocsTool.ts
new file mode 100644
index 000000000..05482a66e
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/GetDocsTool.ts
@@ -0,0 +1,48 @@
+import { Observation } from '../types/types';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+import { BaseTool } from './BaseTool';
+import { DocServer } from '../../../../DocServer';
+import { Docs } from '../../../../documents/Documents';
+import { DocumentView } from '../../DocumentView';
+import { OpenWhere } from '../../OpenWhere';
+import { DocCast } from '../../../../../fields/Types';
+
+const getDocsToolParams = [
+ {
+ name: 'title',
+ type: 'string',
+ description: 'Title of the collection being created from retrieved documents',
+ required: true,
+ },
+ {
+ name: 'document_ids',
+ type: 'string[]',
+ description: 'List of document IDs to retrieve',
+ required: true,
+ },
+] as const;
+
+type GetDocsToolParamsType = typeof getDocsToolParams;
+
+const getDocsToolInfo: ToolInfo<GetDocsToolParamsType> = {
+ name: 'retrieveDocs',
+ description: 'Retrieves the contents of all Documents that the user is interacting with in Dash.',
+ citationRules: 'No citation needed.',
+ parameterRules: getDocsToolParams,
+};
+
+export class GetDocsTool extends BaseTool<GetDocsToolParamsType> {
+ private _docView: DocumentView;
+
+ constructor(docView: DocumentView) {
+ super(getDocsToolInfo);
+ this._docView = docView;
+ }
+
+ async execute(args: ParametersType<GetDocsToolParamsType>): Promise<Observation[]> {
+ const docs = args.document_ids.map(doc_id => DocCast(DocServer.GetCachedRefField(doc_id)));
+ const collection = Docs.Create.FreeformDocument(docs, { title: args.title });
+ this._docView._props.addDocTab(collection, OpenWhere.addRight);
+ return [{ type: 'text', text: `Collection created in Dash called ${args.title}` }];
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/ImageCreationTool.ts b/src/client/views/nodes/chatbot/tools/ImageCreationTool.ts
new file mode 100644
index 000000000..e92d87dfd
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/ImageCreationTool.ts
@@ -0,0 +1,68 @@
+import { RTFCast } from '../../../../../fields/Types';
+import { DocumentOptions } from '../../../../documents/Documents';
+import { Networking } from '../../../../Network';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+import { Observation } from '../types/types';
+import { BaseTool } from './BaseTool';
+import { Upload } from '../../../../../server/SharedMediaTypes';
+
+const imageCreationToolParams = [
+ {
+ name: 'image_prompt',
+ type: 'string',
+ description: 'The prompt for the image to be created. This should be a string that describes the image to be created in extreme detail for an AI image generator.',
+ required: true,
+ },
+] as const;
+
+type ImageCreationToolParamsType = typeof imageCreationToolParams;
+
+const imageCreationToolInfo: ToolInfo<ImageCreationToolParamsType> = {
+ name: 'imageCreationTool',
+ citationRules: 'No citation needed. Cannot cite image generation for a response.',
+ parameterRules: imageCreationToolParams,
+ description: 'Create an image of any style, content, or design, based on a prompt. The prompt should be a detailed description of the image to be created.',
+};
+
+export class ImageCreationTool extends BaseTool<ImageCreationToolParamsType> {
+ private _createImage: (result: Upload.FileInformation & Upload.InspectionResults, options: DocumentOptions) => void;
+ constructor(createImage: (result: Upload.FileInformation & Upload.InspectionResults, options: DocumentOptions) => void) {
+ super(imageCreationToolInfo);
+ this._createImage = createImage;
+ }
+
+ async execute(args: ParametersType<ImageCreationToolParamsType>): Promise<Observation[]> {
+ const image_prompt = args.image_prompt;
+
+ console.log(`Generating image for prompt: ${image_prompt}`);
+ // Create an array of promises, each one handling a search for a query
+ try {
+ const { result, url } = (await Networking.PostToServer('/generateImage', {
+ image_prompt,
+ })) as { result: Upload.FileInformation & Upload.InspectionResults; url: string };
+ console.log('Image generation result:', result);
+ this._createImage(result, { text: RTFCast(image_prompt) });
+ return url
+ ? [
+ {
+ type: 'image_url',
+ image_url: { url },
+ },
+ ]
+ : [
+ {
+ type: 'text',
+ text: `An error occurred while generating image.`,
+ },
+ ];
+ } catch (error) {
+ console.log(error);
+ return [
+ {
+ type: 'text',
+ text: `An error occurred while generating image.`,
+ },
+ ];
+ }
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/NoTool.ts b/src/client/views/nodes/chatbot/tools/NoTool.ts
new file mode 100644
index 000000000..40cc428b5
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/NoTool.ts
@@ -0,0 +1,25 @@
+import { BaseTool } from './BaseTool';
+import { Observation } from '../types/types';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+
+const noToolParams = [] as const;
+
+type NoToolParamsType = typeof noToolParams;
+
+const noToolInfo: ToolInfo<NoToolParamsType> = {
+ name: 'noTool',
+ description: 'A placeholder tool that performs no action to use when no action is needed but to complete the loop.',
+ parameterRules: noToolParams,
+ citationRules: 'No citation needed.',
+};
+
+export class NoTool extends BaseTool<NoToolParamsType> {
+ constructor() {
+ super(noToolInfo);
+ }
+
+ async execute(args: ParametersType<NoToolParamsType>): Promise<Observation[]> {
+ // Since there are no parameters, args will be an empty object
+ return [{ type: 'text', text: 'This tool does nothing.' }];
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/RAGTool.ts b/src/client/views/nodes/chatbot/tools/RAGTool.ts
new file mode 100644
index 000000000..ef374ed22
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/RAGTool.ts
@@ -0,0 +1,90 @@
+import { Networking } from '../../../../Network';
+import { Observation, RAGChunk } from '../types/types';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+import { Vectorstore } from '../vectorstore/Vectorstore';
+import { BaseTool } from './BaseTool';
+
+const ragToolParams = [
+ {
+ name: 'hypothetical_document_chunk',
+ type: 'string',
+ description: "A detailed prompt representing an ideal chunk to embed and compare against document vectors to retrieve the most relevant content for answering the user's query.",
+ required: true,
+ },
+] as const;
+
+type RAGToolParamsType = typeof ragToolParams;
+
+const ragToolInfo: ToolInfo<RAGToolParamsType> = {
+ name: 'rag',
+ description: 'Performs a RAG (Retrieval-Augmented Generation) search on user documents and returns a set of document chunks (text or images) to provide a grounded response based on user documents.',
+ citationRules: `When using the RAG tool, the structure must adhere to the format described in the ReAct prompt. Below are additional guidelines specifically for RAG-based responses:
+
+ 1. **Grounded Text Guidelines**:
+ - Each <grounded_text> tag must correspond to exactly one citation, ensuring a one-to-one relationship.
+ - Always cite a **subset** of the chunk, never the full text. The citation should be as short as possible while providing the relevant information (typically one to two sentences).
+ - Do not paraphrase the chunk text in the citation; use the original subset directly from the chunk. IT MUST BE EXACT AND WORD FOR WORD FROM THE ORIGINAL CHUNK!
+ - If multiple citations are needed for different sections of the response, create new <grounded_text> tags for each.
+ - !!!IMPORTANT: For video transcript citations, use a subset of the exact text from the transcript as the citation content. It should be just before the start of the section of the transcript that is relevant to the grounded_text tag.
+
+ 2. **Citation Guidelines**:
+ - The citation must include only the relevant excerpt from the chunk being referenced.
+ - Use unique citation indices and reference the chunk_id for the source of the information.
+ - For text chunks, the citation content must reflect the **exact subset** of the original chunk that is relevant to the grounded_text tag.
+
+ **Example**:
+
+ <answer>
+ <grounded_text citation_index="1">
+ Artificial Intelligence is revolutionizing various sectors, with healthcare seeing transformations in diagnosis and treatment planning.
+ </grounded_text>
+ <grounded_text citation_index="2">
+ Based on recent data, AI has drastically improved mammogram analysis, achieving 99% accuracy at a rate 30 times faster than human radiologists.
+ </grounded_text>
+
+ <citations>
+ <citation index="1" chunk_id="abc123" type="text">Artificial Intelligence is revolutionizing various industries, especially in healthcare.</citation>
+ <citation index="2" chunk_id="abc124" type="table"></citation>
+ </citations>
+
+ <follow_up_questions>
+ <question>How can AI enhance patient outcomes in fields outside radiology?</question>
+ <question>What are the challenges in implementing AI systems across different hospitals?</question>
+ <question>How might AI-driven advancements impact healthcare costs?</question>
+ </follow_up_questions>
+ </answer>
+
+ ***NOTE***:
+ - Prefer to cite visual elements (i.e. chart, image, table, etc.) over text, if they both can be used. Only if a visual element is not going to be helpful, then use text. Otherwise, use both!
+ - Use as many citations as possible (even when one would be sufficient), thus keeping text as grounded as possible.
+ - Cite from as many documents as possible and always use MORE, and as granular, citations as possible.
+ - CITATION TEXT MUST BE EXACTLY AS IT APPEARS IN THE CHUNK. DO NOT PARAPHRASE!`,
+ parameterRules: ragToolParams,
+};
+
+export class RAGTool extends BaseTool<RAGToolParamsType> {
+ constructor(private vectorstore: Vectorstore) {
+ super(ragToolInfo);
+ }
+
+ async execute(args: ParametersType<RAGToolParamsType>): Promise<Observation[]> {
+ const relevantChunks = await this.vectorstore.retrieve(args.hypothetical_document_chunk);
+ const formattedChunks = await this.getFormattedChunks(relevantChunks);
+ return formattedChunks;
+ }
+
+ async getFormattedChunks(relevantChunks: RAGChunk[]): Promise<Observation[]> {
+ try {
+ const { formattedChunks } = await Networking.PostToServer('/formatChunks', { relevantChunks }) as { formattedChunks: Observation[]}
+
+ if (!formattedChunks) {
+ throw new Error('Failed to format chunks');
+ }
+
+ return formattedChunks;
+ } catch (error) {
+ console.error('Error formatting chunks:', error);
+ throw error;
+ }
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/SearchTool.ts b/src/client/views/nodes/chatbot/tools/SearchTool.ts
new file mode 100644
index 000000000..6a11407a5
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/SearchTool.ts
@@ -0,0 +1,72 @@
+import { v4 as uuidv4 } from 'uuid';
+import { Networking } from '../../../../Network';
+import { BaseTool } from './BaseTool';
+import { Observation } from '../types/types';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+
+const searchToolParams = [
+ {
+ name: 'queries',
+ type: 'string[]',
+ description:
+ 'The search query or queries to use for finding websites. Provide up to 3 search queries to find a broad range of websites. Should be in the form of a TypeScript array of strings (e.g. <queries>["search term 1", "search term 2", "search term 3"]</queries>).',
+ required: true,
+ max_inputs: 3,
+ },
+] as const;
+
+type SearchToolParamsType = typeof searchToolParams;
+
+const searchToolInfo: ToolInfo<SearchToolParamsType> = {
+ name: 'searchTool',
+ citationRules: 'No citation needed. Cannot cite search results for a response. Use web scraping tools to cite specific information.',
+ parameterRules: searchToolParams,
+ description: 'Search the web to find a wide range of websites related to a query or multiple queries. Returns a list of websites and their overviews based on the search queries.',
+};
+
+export class SearchTool extends BaseTool<SearchToolParamsType> {
+ private _addLinkedUrlDoc: (url: string, id: string) => void;
+ private _max_results: number;
+
+ constructor(addLinkedUrlDoc: (url: string, id: string) => void, max_results: number = 4) {
+ super(searchToolInfo);
+ this._addLinkedUrlDoc = addLinkedUrlDoc;
+ this._max_results = max_results;
+ }
+
+ async execute(args: ParametersType<SearchToolParamsType>): Promise<Observation[]> {
+ const queries = args.queries;
+
+ console.log(`Searching the web for queries: ${queries[0]}`);
+ // Create an array of promises, each one handling a search for a query
+ const searchPromises = queries.map(async query => {
+ try {
+ const { results } = (await Networking.PostToServer('/getWebSearchResults', {
+ query,
+ max_results: this._max_results,
+ })) as { results: { url: string; snippet: string }[] };
+ const data = results.map((result: { url: string; snippet: string }) => {
+ const id = uuidv4();
+ this._addLinkedUrlDoc(result.url, id);
+ return {
+ type: 'text' as const,
+ text: `<chunk chunk_id="${id}" chunk_type="url"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
+ };
+ });
+ return data;
+ } catch (error) {
+ console.log(error);
+ return [
+ {
+ type: 'text' as const,
+ text: `An error occurred while performing the web search for query: ${query}`,
+ },
+ ];
+ }
+ });
+
+ const allResultsArrays = await Promise.all(searchPromises);
+
+ return allResultsArrays.flat();
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts b/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts
new file mode 100644
index 000000000..19ccd0b36
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts
@@ -0,0 +1,103 @@
+import { v4 as uuidv4 } from 'uuid';
+import { Networking } from '../../../../Network';
+import { BaseTool } from './BaseTool';
+import { Observation } from '../types/types';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+
+const websiteInfoScraperToolParams = [
+ {
+ name: 'urls',
+ type: 'string[]',
+ description: 'The URLs of the websites to scrape',
+ required: true,
+ max_inputs: 3,
+ },
+] as const;
+
+type WebsiteInfoScraperToolParamsType = typeof websiteInfoScraperToolParams;
+
+const websiteInfoScraperToolInfo: ToolInfo<WebsiteInfoScraperToolParamsType> = {
+ name: 'websiteInfoScraper',
+ description: 'Scrape detailed information from specific websites relevant to the user query. Returns the text content of the webpages for further analysis and grounding.',
+ citationRules: `
+ Your task is to provide a comprehensive response to the user's prompt using the content scraped from relevant websites. Ensure you follow these guidelines for structuring your response:
+
+ 1. Grounded Text Tag Structure:
+ - Wrap all text derived from the scraped website(s) in <grounded_text> tags.
+ - **Do not include non-sourced information** in <grounded_text> tags.
+ - Use a single <grounded_text> tag for content derived from a single website. If citing multiple websites, create new <grounded_text> tags for each.
+ - Ensure each <grounded_text> tag has a citation index corresponding to the scraped URL.
+
+ 2. Citation Tag Structure:
+ - Create a <citation> tag for each distinct piece of information used from the website(s).
+ - Each <citation> tag must reference a URL chunk using the chunk_id attribute.
+ - For URL-based citations, leave the citation content empty, but reference the chunk_id and type as 'url'.
+
+ 3. Structural Integrity Checks:
+ - Ensure all opening and closing tags are matched properly.
+ - Verify that all citation_index attributes in <grounded_text> tags correspond to valid citations.
+ - Do not over-cite—cite only the most relevant parts of the websites.
+
+ Example Usage:
+
+ <answer>
+ <grounded_text citation_index="1">
+ Based on data from the World Bank, economic growth has stabilized in recent years, following a surge in investments.
+ </grounded_text>
+ <grounded_text citation_index="2">
+ According to information retrieved from the International Monetary Fund, the inflation rate has been gradually decreasing since 2020.
+ </grounded_text>
+
+ <citations>
+ <citation index="1" chunk_id="1234" type="url"></citation>
+ <citation index="2" chunk_id="5678" type="url"></citation>
+ </citations>
+
+ <follow_up_questions>
+ <question>What are the long-term economic impacts of increased investments on GDP?</question>
+ <question>How might inflation trends affect future monetary policy?</question>
+ <question>Are there additional factors that could influence economic growth beyond investments and inflation?</question>
+ </follow_up_questions>
+ </answer>
+
+ ***NOTE***: Ensure that the response is structured correctly and adheres to the guidelines provided. Also, if needed/possible, cite multiple websites to provide a comprehensive response.
+ `,
+ parameterRules: websiteInfoScraperToolParams,
+};
+
+export class WebsiteInfoScraperTool extends BaseTool<WebsiteInfoScraperToolParamsType> {
+ private _addLinkedUrlDoc: (url: string, id: string) => void;
+
+ constructor(addLinkedUrlDoc: (url: string, id: string) => void) {
+ super(websiteInfoScraperToolInfo);
+ this._addLinkedUrlDoc = addLinkedUrlDoc;
+ }
+
+ async execute(args: ParametersType<WebsiteInfoScraperToolParamsType>): Promise<Observation[]> {
+ const urls = args.urls;
+
+ // Create an array of promises, each one handling a website scrape for a URL
+ const scrapingPromises = urls.map(async url => {
+ try {
+ const { website_plain_text } = await Networking.PostToServer('/scrapeWebsite', { url });
+ const id = uuidv4();
+ this._addLinkedUrlDoc(url, id);
+ return {
+ type: 'text',
+ text: `<chunk chunk_id="${id}" chunk_type="url">\n${website_plain_text}\n</chunk>`,
+ } as Observation;
+ } catch (error) {
+ console.log(error);
+ return {
+ type: 'text',
+ text: `An error occurred while scraping the website: ${url}`,
+ } as Observation;
+ }
+ });
+
+ // Wait for all scraping promises to resolve
+ const results = await Promise.all(scrapingPromises);
+
+ return results;
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/WikipediaTool.ts b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
new file mode 100644
index 000000000..ee815532a
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
@@ -0,0 +1,50 @@
+import { v4 as uuidv4 } from 'uuid';
+import { Networking } from '../../../../Network';
+import { BaseTool } from './BaseTool';
+import { Observation } from '../types/types';
+import { ParametersType, ToolInfo } from '../types/tool_types';
+
+const wikipediaToolParams = [
+ {
+ name: 'title',
+ type: 'string',
+ description: 'The title of the Wikipedia article to search',
+ required: true,
+ },
+] as const;
+
+type WikipediaToolParamsType = typeof wikipediaToolParams;
+
+const wikipediaToolInfo: ToolInfo<WikipediaToolParamsType> = {
+ name: 'wikipedia',
+ citationRules: 'No citation needed.',
+ parameterRules: wikipediaToolParams,
+ description: 'Returns a summary from searching an article title on Wikipedia.',
+};
+
+export class WikipediaTool extends BaseTool<WikipediaToolParamsType> {
+ private _addLinkedUrlDoc: (url: string, id: string) => void;
+
+ constructor(addLinkedUrlDoc: (url: string, id: string) => void) {
+ super(wikipediaToolInfo);
+ this._addLinkedUrlDoc = addLinkedUrlDoc;
+ }
+
+ async execute(args: ParametersType<WikipediaToolParamsType>): Promise<Observation[]> {
+ try {
+ const { text } = await Networking.PostToServer('/getWikipediaSummary', { title: args.title });
+ const id = uuidv4();
+ const url = `https://en.wikipedia.org/wiki/${args.title.replace(/ /g, '_')}`;
+ this._addLinkedUrlDoc(url, id);
+ return [
+ {
+ type: 'text',
+ text: `<chunk chunk_id="${id}" chunk_type="url"> ${text} </chunk>`,
+ },
+ ];
+ } catch (error) {
+ console.log(error);
+ return [{ type: 'text', text: 'An error occurred while fetching the article.' }];
+ }
+ }
+}