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.ts31
-rw-r--r--src/client/views/nodes/chatbot/tools/CalculateTool.ts17
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts158
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateCSVTool.ts21
-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.ts17
-rw-r--r--src/client/views/nodes/chatbot/tools/GetDocsTool.ts17
-rw-r--r--src/client/views/nodes/chatbot/tools/ImageCreationTool.ts69
-rw-r--r--src/client/views/nodes/chatbot/tools/NoTool.ts11
-rw-r--r--src/client/views/nodes/chatbot/tools/RAGTool.ts34
-rw-r--r--src/client/views/nodes/chatbot/tools/SearchTool.ts38
-rw-r--r--src/client/views/nodes/chatbot/tools/ToolTypes.ts76
-rw-r--r--src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts27
-rw-r--r--src/client/views/nodes/chatbot/tools/WikipediaTool.ts19
15 files changed, 914 insertions, 175 deletions
diff --git a/src/client/views/nodes/chatbot/tools/BaseTool.ts b/src/client/views/nodes/chatbot/tools/BaseTool.ts
index 58cd514d9..8800e2238 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, ToolInfo } 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
@@ -23,8 +23,6 @@ export abstract class BaseTool<P extends ReadonlyArray<Parameter>> implements To
parameterRules: P;
// Guidelines for how to handle citations when using the tool
citationRules: string;
- // A brief summary of the tool's purpose
- briefSummary: string;
/**
* Constructs a new `BaseTool` instance.
@@ -32,14 +30,12 @@ export abstract class BaseTool<P extends ReadonlyArray<Parameter>> implements To
* @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.
- * @param briefSummary - A short summary of the tool.
*/
- constructor(name: string, description: string, parameterRules: P, citationRules: string, briefSummary: string) {
- this.name = name;
- this.description = description;
- this.parameterRules = parameterRules;
- this.citationRules = citationRules;
- this.briefSummary = briefSummary;
+ constructor(toolInfo: ToolInfo<P>) {
+ this.name = toolInfo.name;
+ this.description = toolInfo.description;
+ this.parameterRules = toolInfo.parameterRules;
+ this.citationRules = toolInfo.citationRules;
}
/**
@@ -51,6 +47,18 @@ export abstract class BaseTool<P extends ReadonlyArray<Parameter>> implements To
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.
@@ -59,6 +67,7 @@ export abstract class BaseTool<P extends ReadonlyArray<Parameter>> implements To
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
diff --git a/src/client/views/nodes/chatbot/tools/CalculateTool.ts b/src/client/views/nodes/chatbot/tools/CalculateTool.ts
index e96c9a98a..ca7223803 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, ToolInfo } from '../types/tool_types';
import { BaseTool } from './BaseTool';
const calculateToolParams = [
@@ -13,15 +13,16 @@ const calculateToolParams = [
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(
- 'calculate',
- 'Perform a calculation',
- calculateToolParams, // Use the reusable param config here
- 'Provide a mathematical expression to calculate that would work with JavaScript eval().',
- 'Runs a calculation and returns the number - uses JavaScript so be sure to use floating point syntax if necessary'
- );
+ super(calculateToolInfo);
}
async execute(args: ParametersType<CalculateToolParamsType>): Promise<Observation[]> {
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..754d230c8
--- /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 } } = {
+ [supportedDocTypes.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',
+ },
+ [supportedDocTypes.text]: {
+ options: [...standardOptions, 'fontColor', 'text_align'],
+ dataDescription: 'The text content of the document.',
+ },
+ [supportedDocTypes.html]: {
+ options: [],
+ dataDescription: 'The HTML-formatted text content of the document.',
+ },
+ [supportedDocTypes.equation]: {
+ options: [...standardOptions, 'fontColor'],
+ dataDescription: 'The equation content as a string.',
+ },
+ [supportedDocTypes.functionplot]: {
+ options: [...standardOptions, 'function_definition'],
+ dataDescription: 'The function definition(s) for plotting. Provide as a string or array of function definitions.',
+ },
+ [supportedDocTypes.dataviz]: {
+ options: [...standardOptions, 'chartType'],
+ dataDescription: 'A string of comma-separated values representing the CSV data.',
+ },
+ [supportedDocTypes.notetaking]: {
+ options: standardOptions,
+ dataDescription: 'The initial content or structure for note-taking.',
+ },
+ [supportedDocTypes.rtf]: {
+ options: standardOptions,
+ dataDescription: 'The rich text content in RTF format.',
+ },
+ [supportedDocTypes.image]: {
+ options: standardOptions,
+ dataDescription: 'The image content as an image file URL.',
+ },
+ [supportedDocTypes.pdf]: {
+ options: standardOptions,
+ dataDescription: 'the pdf content as a PDF file url.',
+ },
+ [supportedDocTypes.audio]: {
+ options: standardOptions,
+ dataDescription: 'The audio content as a file url.',
+ },
+ [supportedDocTypes.video]: {
+ options: standardOptions,
+ dataDescription: 'The video content as a file url.',
+ },
+ [supportedDocTypes.message]: {
+ options: standardOptions,
+ dataDescription: 'The message content of the document.',
+ },
+ [supportedDocTypes.diagram]: {
+ options: ['title', 'backgroundColor'],
+ dataDescription: 'diagram content as a text string in Mermaid format.',
+ },
+ [supportedDocTypes.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
index b321d98ba..290c48d6c 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, ToolInfo } from '../types/tool_types';
const createCSVToolParams = [
{
@@ -20,27 +20,28 @@ const createCSVToolParams = [
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(
- 'createCSV',
- 'Creates a CSV file from raw CSV data and saves it to the server',
- createCSVToolParams,
- 'Provide a CSV string and a filename to create a CSV file.',
- '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.'
- );
+ 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', {
+ 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);
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
index d9b75219d..8c5e3d9cd 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, ToolInfo } from '../types/tool_types';
import { BaseTool } from './BaseTool';
const dataAnalysisToolParams = [
@@ -14,17 +14,18 @@ const dataAnalysisToolParams = [
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(
- 'dataAnalysis',
- 'Analyzes and provides insights from one or more CSV files',
- dataAnalysisToolParams,
- 'Provide the name(s) of up to 3 CSV files to analyze based on the user query and whichever available CSV files may be relevant.',
- 'Provides the full CSV file text for your analysis based on the user query and the available CSV file(s).'
- );
+ super(dataAnalysisToolInfo);
this.csv_files_function = csv_files;
}
diff --git a/src/client/views/nodes/chatbot/tools/GetDocsTool.ts b/src/client/views/nodes/chatbot/tools/GetDocsTool.ts
index 26756522c..05482a66e 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, ToolInfo } from '../types/tool_types';
import { BaseTool } from './BaseTool';
import { DocServer } from '../../../../DocServer';
import { Docs } from '../../../../documents/Documents';
@@ -24,17 +24,18 @@ const getDocsToolParams = [
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(
- 'retrieveDocs',
- 'Retrieves the contents of all Documents that the user is interacting with in Dash',
- getDocsToolParams,
- 'No need to provide anything. Just run the tool and it will retrieve the contents of all Documents that the user is interacting with in Dash.',
- 'Returns the documents in Dash in JSON form.'
- );
+ super(getDocsToolInfo);
this._docView = docView;
}
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..37907fd4f
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/ImageCreationTool.ts
@@ -0,0 +1,69 @@
+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';
+import { List } from '../../../../../fields/List';
+
+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), ai: 'dall-e-3', tags: new List<string>(['@ai']) });
+ 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
index a92e3fa23..40cc428b5 100644
--- a/src/client/views/nodes/chatbot/tools/NoTool.ts
+++ b/src/client/views/nodes/chatbot/tools/NoTool.ts
@@ -1,14 +1,21 @@
import { BaseTool } from './BaseTool';
import { Observation } from '../types/types';
-import { ParametersType } from './ToolTypes';
+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('noTool', 'A placeholder tool that performs no action', noToolParams, 'This tool does not require any input or perform any action.', 'Does nothing.');
+ super(noToolInfo);
}
async execute(args: ParametersType<NoToolParamsType>): Promise<Observation[]> {
diff --git a/src/client/views/nodes/chatbot/tools/RAGTool.ts b/src/client/views/nodes/chatbot/tools/RAGTool.ts
index 482069f36..ef374ed22 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, ToolInfo } from '../types/tool_types';
import { Vectorstore } from '../vectorstore/Vectorstore';
import { BaseTool } from './BaseTool';
@@ -15,20 +15,17 @@ const ragToolParams = [
type RAGToolParamsType = typeof ragToolParams;
-export class RAGTool extends BaseTool<RAGToolParamsType> {
- constructor(private vectorstore: Vectorstore) {
- super(
- 'rag',
- 'Perform a RAG search on user documents',
- ragToolParams,
- `
- 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:
+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.
+ - 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.
@@ -56,9 +53,18 @@ export class RAGTool extends BaseTool<RAGToolParamsType> {
<question>How might AI-driven advancements impact healthcare costs?</question>
</follow_up_questions>
</answer>
- `,
- `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.`
- );
+
+ ***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[]> {
@@ -69,7 +75,7 @@ export class RAGTool extends BaseTool<RAGToolParamsType> {
async getFormattedChunks(relevantChunks: RAGChunk[]): Promise<Observation[]> {
try {
- const { formattedChunks } = await Networking.PostToServer('/formatChunks', { relevantChunks });
+ const { formattedChunks } = await Networking.PostToServer('/formatChunks', { relevantChunks }) as { formattedChunks: Observation[]}
if (!formattedChunks) {
throw new Error('Failed to format chunks');
diff --git a/src/client/views/nodes/chatbot/tools/SearchTool.ts b/src/client/views/nodes/chatbot/tools/SearchTool.ts
index fd5144dd6..6a11407a5 100644
--- a/src/client/views/nodes/chatbot/tools/SearchTool.ts
+++ b/src/client/views/nodes/chatbot/tools/SearchTool.ts
@@ -2,13 +2,14 @@ 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, ToolInfo } from '../types/tool_types';
const searchToolParams = [
{
- name: 'query',
+ name: 'queries',
type: 'string[]',
- description: 'The search query or queries to use for finding websites',
+ 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,
},
@@ -16,37 +17,40 @@ const searchToolParams = [
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 = 5) {
- super(
- 'searchTool',
- 'Search the web to find a wide range of websites related to a query or multiple queries',
- searchToolParams,
- 'Provide up to 3 search queries to find a broad range of websites.',
- 'Returns a list of websites and their overviews based on the search queries.'
- );
+ 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.query;
+ 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', {
+ 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',
- text: `<chunk chunk_id="${id}" chunk_type="text"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
+ type: 'text' as const,
+ text: `<chunk chunk_id="${id}" chunk_type="url"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
};
});
return data;
@@ -54,7 +58,7 @@ export class SearchTool extends BaseTool<SearchToolParamsType> {
console.log(error);
return [
{
- type: 'text',
+ type: 'text' as const,
text: `An error occurred while performing the web search for query: ${query}`,
},
];
diff --git a/src/client/views/nodes/chatbot/tools/ToolTypes.ts b/src/client/views/nodes/chatbot/tools/ToolTypes.ts
deleted file mode 100644
index d47a38952..000000000
--- a/src/client/views/nodes/chatbot/tools/ToolTypes.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-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>;
-}
-
-/**
- * The `Parameter` type defines the structure of a parameter configuration.
- */
-export type Parameter = {
- // The type of the parameter; constrained to the types 'string', 'number', 'boolean', 'string[]', 'number[]'
- readonly type: 'string' | 'number' | 'boolean' | 'string[]' | 'number[]';
- // The name of the parameter
- readonly name: string;
- // A description of the parameter
- readonly description: string;
- // Indicates whether the parameter is required
- readonly required: boolean;
- // (Optional) The maximum number of inputs (useful for array types)
- readonly max_inputs?: number;
-};
-
-/**
- * A utility type that maps string representations of types to actual TypeScript types.
- * This is used to convert the `type` field of a `Parameter` into a concrete TypeScript type.
- */
-type TypeMap = {
- string: string;
- number: number;
- boolean: boolean;
- 'string[]': string[];
- 'number[]': number[];
-};
-
-/**
- * The `ParamType` type maps a `Parameter`'s `type` field to the corresponding TypeScript type.
- * If the `type` field matches a key in `TypeMap`, it returns the associated type.
- * Otherwise, it returns `unknown`.
- * @template P - A `Parameter` object.
- */
-export type ParamType<P extends Parameter> = P['type'] extends keyof TypeMap ? TypeMap[P['type']] : unknown;
-
-/**
- * The `ParametersType` type transforms an array of `Parameter` objects into an object type
- * where each key is the parameter's name, and the value is the corresponding TypeScript type.
- * This is used to define the types of the arguments passed to the `execute` method of a tool.
- * @template P - An array of `Parameter` objects.
- */
-export type ParametersType<P extends ReadonlyArray<Parameter>> = {
- [K in P[number] as K['name']]: ParamType<K>;
-};
diff --git a/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts b/src/client/views/nodes/chatbot/tools/WebsiteInfoScraperTool.ts
index f2e3863a6..19ccd0b36 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, ToolInfo } from '../types/tool_types';
const websiteInfoScraperToolParams = [
{
@@ -16,15 +16,10 @@ const websiteInfoScraperToolParams = [
type WebsiteInfoScraperToolParamsType = typeof websiteInfoScraperToolParams;
-export class WebsiteInfoScraperTool extends BaseTool<WebsiteInfoScraperToolParamsType> {
- private _addLinkedUrlDoc: (url: string, id: string) => void;
-
- constructor(addLinkedUrlDoc: (url: string, id: string) => void) {
- super(
- 'websiteInfoScraper',
- 'Scrape detailed information from specific websites relevant to the user query',
- 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:
@@ -64,9 +59,17 @@ export class WebsiteInfoScraperTool extends BaseTool<WebsiteInfoScraperToolParam
<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.
`,
- 'Returns the text content of the webpages for further analysis and grounding.'
- );
+ 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;
}
diff --git a/src/client/views/nodes/chatbot/tools/WikipediaTool.ts b/src/client/views/nodes/chatbot/tools/WikipediaTool.ts
index 4fcffe2ed..ee815532a 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, ToolInfo } from '../types/tool_types';
const wikipediaToolParams = [
{
@@ -15,17 +15,18 @@ const wikipediaToolParams = [
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(
- 'wikipedia',
- 'Search Wikipedia and return a summary',
- wikipediaToolParams,
- 'Provide simply the title you want to search on Wikipedia and nothing more. If re-using this tool, try a different title for different information.',
- 'Returns a summary from searching an article title on Wikipedia'
- );
+ super(wikipediaToolInfo);
this._addLinkedUrlDoc = addLinkedUrlDoc;
}
@@ -38,7 +39,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) {