aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/tools
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-03-06 16:17:47 -0500
committerbobzel <zzzman@gmail.com>2025-03-06 16:17:47 -0500
commit5ad858090f3006631062877d90120e3cc505fada (patch)
tree9f87a8e1e7098a1025f6f4aac332dbc854db5be3 /src/client/views/nodes/chatbot/tools
parent9c2a7c14fd9d0e44609aab30c6323583162009db (diff)
parentadaa107aac8558fa6f46e6ba1263c650c212d506 (diff)
Merge branch 'master' into aarav_edit
Diffstat (limited to 'src/client/views/nodes/chatbot/tools')
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts30
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateCSVTool.ts4
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts38
-rw-r--r--src/client/views/nodes/chatbot/tools/ImageCreationTool.ts43
-rw-r--r--src/client/views/nodes/chatbot/tools/RAGTool.ts2
-rw-r--r--src/client/views/nodes/chatbot/tools/SearchTool.ts8
6 files changed, 61 insertions, 64 deletions
diff --git a/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts b/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts
index ef4bbbc47..754d230c8 100644
--- a/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts
+++ b/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts
@@ -13,63 +13,63 @@ 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]: {
+ [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',
},
- [supportedDocumentTypes.text]: {
+ [supportedDocTypes.text]: {
options: [...standardOptions, 'fontColor', 'text_align'],
dataDescription: 'The text content of the document.',
},
- [supportedDocumentTypes.html]: {
+ [supportedDocTypes.html]: {
options: [],
dataDescription: 'The HTML-formatted text content of the document.',
},
- [supportedDocumentTypes.equation]: {
+ [supportedDocTypes.equation]: {
options: [...standardOptions, 'fontColor'],
dataDescription: 'The equation content as a string.',
},
- [supportedDocumentTypes.functionplot]: {
+ [supportedDocTypes.functionplot]: {
options: [...standardOptions, 'function_definition'],
dataDescription: 'The function definition(s) for plotting. Provide as a string or array of function definitions.',
},
- [supportedDocumentTypes.dataviz]: {
+ [supportedDocTypes.dataviz]: {
options: [...standardOptions, 'chartType'],
dataDescription: 'A string of comma-separated values representing the CSV data.',
},
- [supportedDocumentTypes.notetaking]: {
+ [supportedDocTypes.notetaking]: {
options: standardOptions,
dataDescription: 'The initial content or structure for note-taking.',
},
- [supportedDocumentTypes.rtf]: {
+ [supportedDocTypes.rtf]: {
options: standardOptions,
dataDescription: 'The rich text content in RTF format.',
},
- [supportedDocumentTypes.image]: {
+ [supportedDocTypes.image]: {
options: standardOptions,
dataDescription: 'The image content as an image file URL.',
},
- [supportedDocumentTypes.pdf]: {
+ [supportedDocTypes.pdf]: {
options: standardOptions,
dataDescription: 'the pdf content as a PDF file url.',
},
- [supportedDocumentTypes.audio]: {
+ [supportedDocTypes.audio]: {
options: standardOptions,
dataDescription: 'The audio content as a file url.',
},
- [supportedDocumentTypes.video]: {
+ [supportedDocTypes.video]: {
options: standardOptions,
dataDescription: 'The video content as a file url.',
},
- [supportedDocumentTypes.message]: {
+ [supportedDocTypes.message]: {
options: standardOptions,
dataDescription: 'The message content of the document.',
},
- [supportedDocumentTypes.diagram]: {
+ [supportedDocTypes.diagram]: {
options: ['title', 'backgroundColor'],
dataDescription: 'diagram content as a text string in Mermaid format.',
},
- [supportedDocumentTypes.script]: {
+ [supportedDocTypes.script]: {
options: ['title', 'backgroundColor'],
dataDescription: 'The compilable JavaScript code. Use this for creating scripts.',
},
diff --git a/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts b/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts
index e8ef3fbfe..290c48d6c 100644
--- a/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts
+++ b/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts
@@ -38,10 +38,10 @@ export class CreateCSVTool extends BaseTool<CreateCSVToolParamsType> {
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
index 6dc36b0d1..284879a4a 100644
--- a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
+++ b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
@@ -263,79 +263,79 @@ const standardOptions = ['title', 'backgroundColor'];
* Description of document options and data field for each type.
*/
const documentTypesInfo: { [key in supportedDocTypes]: { options: string[]; dataDescription: string } } = {
- [supportedDocTypes.comparison]: {
+ comparison: {
options: [...standardOptions, 'fontColor', 'text_align'],
dataDescription: 'an array of two documents of any kind that can be compared.',
},
- [supportedDocTypes.deck]: {
+ deck: {
options: [...standardOptions, 'fontColor', 'text_align'],
dataDescription: 'an array of flashcard docs',
},
- [supportedDocTypes.flashcard]: {
+ 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]: {
+ text: {
options: [...standardOptions, 'fontColor', 'text_align'],
dataDescription: 'The text content of the document.',
},
- [supportedDocTypes.web]: {
+ web: {
options: [],
dataDescription: 'A URL to a webpage. Example: https://en.wikipedia.org/wiki/Brown_University',
},
- [supportedDocTypes.html]: {
+ html: {
options: [],
dataDescription: 'The HTML-formatted text content of the document.',
},
- [supportedDocTypes.equation]: {
+ equation: {
options: [...standardOptions, 'fontColor'],
dataDescription: 'The equation content represented as a MathML string.',
},
- [supportedDocTypes.functionplot]: {
+ functionplot: {
options: [...standardOptions, 'function_definition'],
dataDescription: 'The function definition(s) for plotting. Provide as a string or array of function definitions.',
},
- [supportedDocTypes.dataviz]: {
+ dataviz: {
options: [...standardOptions, 'chartType'],
dataDescription: 'A string of comma-separated values representing the CSV data.',
},
- [supportedDocTypes.notetaking]: {
+ notetaking: {
options: standardOptions,
dataDescription: 'An array of related text documents with small amounts of text.',
},
- [supportedDocTypes.rtf]: {
+ rtf: {
options: standardOptions,
dataDescription: 'The rich text content in RTF format.',
},
- [supportedDocTypes.image]: {
+ image: {
options: standardOptions,
dataDescription: `A url string that must end with '.png', '.jpeg', '.gif', or '.jpg'`,
},
- [supportedDocTypes.pdf]: {
+ pdf: {
options: standardOptions,
dataDescription: 'the pdf content as a PDF file url.',
},
- [supportedDocTypes.audio]: {
+ audio: {
options: standardOptions,
dataDescription: 'The audio content as a file url.',
},
- [supportedDocTypes.video]: {
+ video: {
options: standardOptions,
dataDescription: 'The video content as a file url.',
},
- [supportedDocTypes.message]: {
+ message: {
options: standardOptions,
dataDescription: 'The message content of the document.',
},
- [supportedDocTypes.diagram]: {
+ diagram: {
options: standardOptions,
dataDescription: 'diagram content as a text string in Mermaid format.',
},
- [supportedDocTypes.script]: {
+ script: {
options: standardOptions,
dataDescription: 'The compilable JavaScript code. Use this for creating scripts.',
},
- [supportedDocTypes.collection]: {
+ collection: {
options: [...standardOptions, 'type_collection'],
dataDescription: 'A collection of Docs represented as an array.',
},
diff --git a/src/client/views/nodes/chatbot/tools/ImageCreationTool.ts b/src/client/views/nodes/chatbot/tools/ImageCreationTool.ts
index 177552c5c..37907fd4f 100644
--- a/src/client/views/nodes/chatbot/tools/ImageCreationTool.ts
+++ b/src/client/views/nodes/chatbot/tools/ImageCreationTool.ts
@@ -1,10 +1,11 @@
-import { v4 as uuidv4 } from 'uuid';
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 = [
{
@@ -25,8 +26,8 @@ const imageCreationToolInfo: ToolInfo<ImageCreationToolParamsType> = {
};
export class ImageCreationTool extends BaseTool<ImageCreationToolParamsType> {
- private _createImage: (result: any, options: DocumentOptions) => void;
- constructor(createImage: (result: any, options: DocumentOptions) => void) {
+ 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;
}
@@ -37,28 +38,24 @@ export class ImageCreationTool extends BaseTool<ImageCreationToolParamsType> {
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', {
+ 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) });
- if (url) {
- const id = uuidv4();
-
- return [
- {
- type: 'image_url',
- image_url: { url },
- },
- ];
- } else {
- return [
- {
- type: 'text',
- text: `An error occurred while generating image.`,
- },
- ];
- }
+ 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 [
diff --git a/src/client/views/nodes/chatbot/tools/RAGTool.ts b/src/client/views/nodes/chatbot/tools/RAGTool.ts
index 2db61c768..ef374ed22 100644
--- a/src/client/views/nodes/chatbot/tools/RAGTool.ts
+++ b/src/client/views/nodes/chatbot/tools/RAGTool.ts
@@ -75,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 5fc6ab768..6a11407a5 100644
--- a/src/client/views/nodes/chatbot/tools/SearchTool.ts
+++ b/src/client/views/nodes/chatbot/tools/SearchTool.ts
@@ -41,15 +41,15 @@ export class SearchTool extends BaseTool<SearchToolParamsType> {
// 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',
+ type: 'text' as const,
text: `<chunk chunk_id="${id}" chunk_type="url"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
};
});
@@ -58,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}`,
},
];