diff options
5 files changed, 234 insertions, 158 deletions
diff --git a/src/client/views/nodes/chatbot/agentsystem/Agent.ts b/src/client/views/nodes/chatbot/agentsystem/Agent.ts index 689c152dd..a7b34392b 100644 --- a/src/client/views/nodes/chatbot/agentsystem/Agent.ts +++ b/src/client/views/nodes/chatbot/agentsystem/Agent.ts @@ -7,7 +7,7 @@ import { AnswerParser } from '../response_parsers/AnswerParser'; import { StreamedAnswerParser } from '../response_parsers/StreamedAnswerParser'; import { BaseTool } from '../tools/BaseTool'; import { CalculateTool } from '../tools/CalculateTool'; -import { CreateAnyDocumentTool } from '../tools/CreateAnyDocTool'; +//import { CreateAnyDocumentTool } from '../tools/CreateAnyDocTool'; import { CreateDocTool } from '../tools/CreateDocumentTool'; import { DataAnalysisTool } from '../tools/DataAnalysisTool'; import { ImageCreationTool } from '../tools/ImageCreationTool'; @@ -21,7 +21,7 @@ import { getReactPrompt } from './prompts'; import { ChatCompletionMessageParam } from 'openai/resources'; import { Doc } from '../../../../../fields/Doc'; import { parsedDoc } from '../chatboxcomponents/ChatBox'; -import { CreateTextDocTool } from '../tools/CreateTextDocumentTool'; +//import { CreateTextDocTool } from '../tools/CreateTextDocumentTool'; dotenv.config(); @@ -81,10 +81,10 @@ export class Agent { searchTool: new SearchTool(addLinkedUrlDoc), // createCSV: new CreateCSVTool(createCSVInDash), noTool: new NoTool(), - imageCreationTool: new ImageCreationTool(createImage), - createTextDoc: new CreateTextDocTool(addLinkedDoc), + //imageCreationTool: new ImageCreationTool(createImage), + // createTextDoc: new CreateTextDocTool(addLinkedDoc), createDoc: new CreateDocTool(addLinkedDoc), - createAnyDocument: new CreateAnyDocumentTool(addLinkedDoc), + // createAnyDocument: new CreateAnyDocumentTool(addLinkedDoc), // dictionary: new DictionaryTool(), }; } @@ -471,7 +471,7 @@ export class Agent { // Check if the input is a valid array of the expected type const parsedArray = this.parseArray(input as string, expectedType); actionInput[param.name] = parsedArray as TypeMap[typeof param.type]; - } else if (typeof input !== expectedType) { + } else if (input !== undefined && typeof input !== expectedType) { throw new Error(`Invalid type for parameter ${param.name}: expected ${expectedType}`); } } diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx index f13116fdd..a9cf849cc 100644 --- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx +++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx @@ -35,7 +35,7 @@ import { PDFBox } from '../../PDFBox'; import { ScriptingBox } from '../../ScriptingBox'; import { VideoBox } from '../../VideoBox'; import { Agent } from '../agentsystem/Agent'; -import { supportedDocumentTypes } from '../tools/CreateDocumentTool'; +import { supportedDocTypes } from '../tools/CreateDocumentTool'; import { ASSISTANT_ROLE, AssistantMessage, CHUNK_TYPE, Citation, ProcessingInfo, SimplifiedChunk, TEXT_TYPE } from '../types/types'; import { Vectorstore } from '../vectorstore/Vectorstore'; import './ChatBox.scss'; @@ -443,18 +443,18 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { const ndoc = (() => { switch (doc.doc_type) { default: - case supportedDocumentTypes.text: return Docs.Create.TextDocument(data as string, options); - case supportedDocumentTypes.comparison: return this.createComparison(data as parsedDoc[], options); - case supportedDocumentTypes.flashcard: return this.createFlashcard(data as parsedDoc[], options); - case supportedDocumentTypes.deck: return this.createDeck(data as parsedDoc[], options); - case supportedDocumentTypes.image: return Docs.Create.ImageDocument(data as string, options); - case supportedDocumentTypes.equation: return Docs.Create.EquationDocument(data as string, options); - case supportedDocumentTypes.notetaking: return Docs.Create.NoteTakingDocument([], options); - case supportedDocumentTypes.web: return Docs.Create.WebDocument(data as string, { ...options, data_useCors: true }); - case supportedDocumentTypes.dataviz: return Docs.Create.DataVizDocument('/users/rz/Downloads/addresses.csv', options); - case supportedDocumentTypes.pdf: return Docs.Create.PdfDocument(data as string, options); - case supportedDocumentTypes.video: return Docs.Create.VideoDocument(data as string, options); - case supportedDocumentTypes.mermaid: return Docs.Create.DiagramDocument(undefined, { text: data as unknown as RichTextField, ...options}); // text: can take a string or RichTextField but it's typed for RichTextField. + case supportedDocTypes.text: return Docs.Create.TextDocument(data as string, options); + case supportedDocTypes.comparison: return this.createComparison(JSON.parse(data as string) as parsedDoc[], options); + case supportedDocTypes.flashcard: return this.createFlashcard(JSON.parse(data as string) as parsedDoc[], options); + case supportedDocTypes.deck: return this.createDeck(JSON.parse(data as string) as parsedDoc[], options); + case supportedDocTypes.image: return Docs.Create.ImageDocument(data as string, options); + case supportedDocTypes.equation: return Docs.Create.EquationDocument(data as string, options); + case supportedDocTypes.notetaking: return Docs.Create.NoteTakingDocument([], options); + case supportedDocTypes.web: return Docs.Create.WebDocument(data as string, { ...options, data_useCors: true }); + case supportedDocTypes.dataviz: return Docs.Create.DataVizDocument('/users/rz/Downloads/addresses.csv', options); + case supportedDocTypes.pdf: return Docs.Create.PdfDocument(data as string, options); + case supportedDocTypes.video: return Docs.Create.VideoDocument(data as string, options); + case supportedDocTypes.diagram: return Docs.Create.DiagramDocument(undefined, { text: data as unknown as RichTextField, ...options}); // text: can take a string or RichTextField but it's typed for RichTextField. // case supportedDocumentTypes.dataviz: // { @@ -466,7 +466,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { // this.addCSVForAnalysis(doc, id); // return doc; // } - case supportedDocumentTypes.script: { + case supportedDocTypes.script: { const result = !(data as string).trim() ? ({ compiled: false, errors: [] } as CompileError) : CompileScript(data as string, {}); const script_field = result.compiled ? new ScriptField(result, undefined, data as string) : undefined; const sdoc = Docs.Create.ScriptingDocument(script_field, options); @@ -477,12 +477,13 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { }); return sdoc; } - case supportedDocumentTypes.collection: { - const arr = this.createCollectionWithChildren(data as parsedDoc[], true).filter(d=>d).map(d => d!); - const collOpts = { ...options, _layout_fitWidth: true, _width:300, _height: 300, _freeform_backgroundGrid: true }; + case supportedDocTypes.collection: { + const arr = this.createCollectionWithChildren(JSON.parse(data as string) as parsedDoc[], true).filter(d=>d).map(d => d!); + const collOpts = { _width:300, _height: 300, _layout_fitWidth: true, _freeform_backgroundGrid: true, ...options, }; return (() => { switch (options.type_collection) { case CollectionViewType.Tree: return Docs.Create.TreeDocument(arr, collOpts); + case CollectionViewType.Stacking: return Docs.Create.StackingDocument(arr, collOpts); case CollectionViewType.Masonry: return Docs.Create.MasonryDocument(arr, collOpts); case CollectionViewType.Card: return Docs.Create.CardDeckDocument(arr, collOpts); case CollectionViewType.Carousel: return Docs.Create.CarouselDocument(arr, collOpts); diff --git a/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts b/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts index 5cf858998..ef4bbbc47 100644 --- a/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts +++ b/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts @@ -6,13 +6,13 @@ import { parsedDoc } from '../chatboxcomponents/ChatBox'; import { ParametersType, ToolInfo } from '../types/tool_types'; import { Observation } from '../types/types'; import { BaseTool } from './BaseTool'; -import { supportedDocumentTypes } from './CreateDocumentTool'; +import { supportedDocTypes } from './CreateDocumentTool'; const standardOptions = ['title', 'backgroundColor']; /** * Description of document options and data field for each type. */ -const documentTypesInfo: { [key in supportedDocumentTypes]: { options: string[]; dataDescription: string } } = { +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', @@ -65,9 +65,9 @@ const documentTypesInfo: { [key in supportedDocumentTypes]: { options: string[]; options: standardOptions, dataDescription: 'The message content of the document.', }, - [supportedDocumentTypes.mermaid]: { + [supportedDocumentTypes.diagram]: { options: ['title', 'backgroundColor'], - dataDescription: 'The Mermaid diagram content.', + dataDescription: 'diagram content as a text string in Mermaid format.', }, [supportedDocumentTypes.script]: { options: ['title', 'backgroundColor'], @@ -79,7 +79,7 @@ const createAnyDocumentToolParams = [ { name: 'document_type', type: 'string', - description: `The type of the document to create. Supported types are: ${Object.values(supportedDocumentTypes).join(', ')}`, + description: `The type of the document to create. Supported types are: ${Object.values(supportedDocTypes).join(', ')}`, required: true, }, { @@ -105,7 +105,7 @@ const createAnyDocToolInfo: ToolInfo<CreateAnyDocumentToolParamsType> = { name: 'createAnyDocument', description: `Creates any type of document with the provided options and data. - Supported document types are: ${Object.values(supportedDocumentTypes).join(', ')}. + 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) @@ -134,11 +134,11 @@ export class CreateAnyDocumentTool extends BaseTool<CreateAnyDocumentToolParamsT async execute(args: ParametersType<CreateAnyDocumentToolParamsType>): Promise<Observation[]> { try { - const documentType = toLower(args.document_type) as unknown as supportedDocumentTypes; + 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(supportedDocumentTypes).join(', ')}.`); + throw new Error(`Unsupported document type: ${documentType}. Supported types are: ${Object.values(supportedDocTypes).join(', ')}.`); } if (!args.data) { diff --git a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts index 7d6964f44..34ab9206b 100644 --- a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts +++ b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts @@ -2,11 +2,12 @@ import { BaseTool } from './BaseTool'; import { Observation } from '../types/types'; import { 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 supportedDocumentTypes { +export enum supportedDocTypes { flashcard = 'flashcard', text = 'text', html = 'html', @@ -24,7 +25,7 @@ export enum supportedDocumentTypes { deck = 'deck', web = 'web', comparison = 'comparison', - mermaid = 'mermaid', + diagram = 'diagram', script = 'script', } /** @@ -37,264 +38,340 @@ export enum supportedDocumentTypes { // Example document structure for various document types const example = [ { - doc_type: supportedDocumentTypes.equation, + doc_type: supportedDocTypes.equation, title: 'quadratic', data: 'x^2 + y^2 = 3', - width: 300, - height: 300, + _width: 300, + _height: 300, x: 0, y: 0, }, { - doc_type: supportedDocumentTypes.collection, + doc_type: supportedDocTypes.collection, title: 'Advanced Biology', data: [ { - doc_type: supportedDocumentTypes.text, + doc_type: supportedDocTypes.text, title: 'Cell Structure', data: 'Cells are the basic building blocks of all living organisms.', - width: 300, - height: 300, + _width: 300, + _height: 300, x: 500, y: 0, }, ], backgroundColor: '#00ff00', - width: 600, - height: 600, + _width: 600, + _height: 600, x: 600, y: 0, type_collection: 'tree', }, { - doc_type: supportedDocumentTypes.image, + 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, + _width: 300, + _height: 300, x: 600, y: 300, }, { - doc_type: supportedDocumentTypes.deck, + doc_type: supportedDocTypes.deck, title: 'Chemistry', data: [ { - doc_type: supportedDocumentTypes.flashcard, + doc_type: supportedDocTypes.flashcard, title: 'Photosynthesis', data: [ { - doc_type: supportedDocumentTypes.text, + doc_type: supportedDocTypes.text, title: 'front_Photosynthesis', data: 'What is photosynthesis?', - width: 300, - height: 300, + _width: 300, + _height: 300, x: 100, y: 600, }, { - doc_type: supportedDocumentTypes.text, + doc_type: supportedDocTypes.text, title: 'back_photosynthesis', data: 'The process by which plants make food.', - width: 300, - height: 300, + _width: 300, + _height: 300, x: 100, y: 700, }, ], backgroundColor: '#00ff00', - width: 300, - height: 300, + _width: 300, + _height: 300, x: 300, y: 1000, }, { - doc_type: supportedDocumentTypes.flashcard, + doc_type: supportedDocTypes.flashcard, title: 'Photosynthesis', data: [ { - doc_type: supportedDocumentTypes.text, + doc_type: supportedDocTypes.text, title: 'front_Photosynthesis', data: 'What is photosynthesis?', - width: 300, - height: 300, + _width: 300, + _height: 300, x: 200, y: 800, }, { - doc_type: supportedDocumentTypes.text, + doc_type: supportedDocTypes.text, title: 'back_photosynthesis', data: 'The process by which plants make food.', - width: 300, - height: 300, + _width: 300, + _height: 300, x: 100, y: -100, }, ], backgroundColor: '#00ff00', - width: 300, - height: 300, + _width: 300, + _height: 300, x: 10, y: 70, }, ], backgroundColor: '#00ff00', - width: 600, - height: 600, + _width: 600, + _height: 600, x: 200, y: 800, }, { - doc_type: supportedDocumentTypes.web, + doc_type: supportedDocTypes.web, title: 'Brown University Wikipedia', data: 'https://en.wikipedia.org/wiki/Brown_University', - width: 300, - height: 300, + _width: 300, + _height: 300, x: 1000, y: 2000, }, { - doc_type: supportedDocumentTypes.comparison, + doc_type: supportedDocTypes.comparison, title: 'WWI vs. WWII', data: [ { - doc_type: supportedDocumentTypes.text, + 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, + _width: 300, + _height: 300, x: 100, y: 100, }, { - doc_type: supportedDocumentTypes.text, + 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, + _width: 300, + _height: 300, x: 100, y: 100, }, ], - width: 300, - height: 300, + _width: 300, + _height: 300, x: 100, y: 100, }, { - doc_type: supportedDocumentTypes.collection, + doc_type: supportedDocTypes.collection, title: 'Science Collection', data: [ { - doc_type: supportedDocumentTypes.flashcard, + doc_type: supportedDocTypes.flashcard, title: 'Photosynthesis', data: [ { - doc_type: supportedDocumentTypes.text, + doc_type: supportedDocTypes.text, title: 'front_Photosynthesis', data: 'What is photosynthesis?', - width: 300, - height: 300, + _width: 300, + _height: 300, }, { - doc_type: supportedDocumentTypes.text, + doc_type: supportedDocTypes.text, title: 'back_photosynthesis', data: 'The process by which plants make food.', - width: 300, - height: 300, + _width: 300, + _height: 300, }, ], backgroundColor: '#00ff00', - width: 300, - height: 300, + _width: 300, + _height: 300, }, { - doc_type: supportedDocumentTypes.web, + doc_type: supportedDocTypes.web, title: 'Brown University Wikipedia', data: 'https://en.wikipedia.org/wiki/Brown_University', - width: 300, - height: 300, + _width: 300, + _height: 300, x: 1100, y: 1100, }, { - doc_type: supportedDocumentTypes.text, + 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, + _width: 300, + _height: 300, x: 1500, y: 500, }, { - doc_type: supportedDocumentTypes.collection, + 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, + _width: 300, + _height: 300, }, ], backgroundColor: '#00ff00', - width: 600, - height: 600, + _width: 600, + _height: 600, x: 1100, y: 500, - type_collection: 'freeform', + type_collection: 'stacking', }, ], - width: 600, - height: 600, + _width: 600, + _height: 600, x: 500, y: 500, - type_collection: 'freeform', + type_collection: 'carousel', }, ]; // Stringify the entire structure for transmission if needed const finalJsonString = JSON.stringify(example); -// Instructions for creating various document types -const docInstructions: [supportedDocumentTypes, string | { description: string; example: string }][] = [ - [ supportedDocumentTypes.collection, - { description: `A recursive collection of documents as a stringified array. Each document can be a ${Object.keys(supportedDocumentTypes).map(key => '"' + key + '"').join(',')}.`, - example: finalJsonString }, - ], // prettier-ignore - [supportedDocumentTypes.text, 'Provide text content as a plain string. Example: "This is a standalone text document."'], - [supportedDocumentTypes.flashcard, 'Two text documents with content for the front and back.'], - [supportedDocumentTypes.deck, 'A decks data is an array of flashcards.'], - [supportedDocumentTypes.comparison, 'two documents of any kind that can be compared.'], - [supportedDocumentTypes.image, `A url string that must end with '.png', '.jpeg', '.gif', or '.jpg'`], - [supportedDocumentTypes.web, 'A URL to a webpage. Example: https://en.wikipedia.org/wiki/Brown_University'], - [supportedDocumentTypes.equation, 'Create an equation document, not a text document. Data is math equation.'], - [supportedDocumentTypes.notetaking, 'Create a noteboard document'], - [supportedDocumentTypes.audio, 'A url to an audio recording. Example: '], -] as const; +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]: { + options: [...standardOptions, 'fontColor', 'text_align'], + dataDescription: 'an array of two documents of any kind that can be compared.', + }, + [supportedDocTypes.deck]: { + options: [...standardOptions, 'fontColor', 'text_align'], + dataDescription: 'an array of flashcard docs', + }, + [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.web]: { + options: [], + dataDescription: 'A URL to a webpage. Example: https://en.wikipedia.org/wiki/Brown_University', + }, + [supportedDocTypes.html]: { + options: [], + dataDescription: 'The HTML-formatted text content of the document.', + }, + [supportedDocTypes.equation]: { + options: [...standardOptions, 'fontColor'], + dataDescription: 'The equation content represented as a MathML 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: 'An array of related text documents with small amounts of text.', + }, + [supportedDocTypes.rtf]: { + options: standardOptions, + dataDescription: 'The rich text content in RTF format.', + }, + [supportedDocTypes.image]: { + options: standardOptions, + dataDescription: `A url string that must end with '.png', '.jpeg', '.gif', or '.jpg'`, + }, + [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: standardOptions, + dataDescription: 'diagram content as a text string in Mermaid format.', + }, + [supportedDocTypes.script]: { + options: standardOptions, + dataDescription: 'The compilable JavaScript code. Use this for creating scripts.', + }, + [supportedDocTypes.collection]: { + options: [...standardOptions, 'type_collection'], + dataDescription: 'A collection of Docs represented as an array.', + }, +}; // Parameters for creating individual documents -const createDocToolParams = [ +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: - typeof docInstructions === 'string' - ? docInstructions - : docInstructions.reduce( - (prev, [type, data]) => { - prev[type] = data; - return prev; - }, - {} as { [key: string]: string | { description: string; example: string } } - ), + '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: "collection", "text", "flashcard", "web".', + description: `The type of the document. Options: ${Object.keys(documentTypesInfo).join(',')}.`, required: true, }, { @@ -328,13 +405,13 @@ const createDocToolParams = [ required: false, }, { - name: 'width', + name: '_width', type: 'number', description: 'The width of the document in pixels.', required: true, }, { - name: 'height', + name: '_height', type: 'number', description: 'The height of the document in pixels.', required: true, @@ -342,37 +419,20 @@ const createDocToolParams = [ { name: 'type_collection', type: 'string', - description: 'Either freeform, card, carousel, 3d-carousel, multicolumn, multirow, linear, map, notetaking, schema, stacking, grid, tree, or masonry.', + description: `the visual style for a collection doc. Options include: ${Object.values(CollectionViewType).join(',')}.`, required: false, }, ] as const; -// Parameters for creating a list of documents -const createListDocToolParams = [ - { - name: 'docs', - type: 'string', - description: - 'Array of documents in stringified JSON format. Each item in the array should be an individual stringified JSON object. Each document can be of type "text", "flashcard", "comparison", "web", or "collection" (for nested documents). ' + - 'Use this structure for nesting collections within collections. Each document should follow the structure in ' + - createDocToolParams + - '. Example: ' + - finalJsonString, - required: true, - }, -] as const; - -type CreateListDocToolParamsType = typeof createListDocToolParams; - -type CreateDocumentToolParamsType = typeof createDocToolParams; +type CreateDocToolParamsType = typeof createDocToolParams; -const createDocToolInfo: ToolInfo<CreateDocumentToolParamsType> = { - name: 'createAnyDocument', +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 like "text," "deck," "web", "equation," and "comparison." - Use decks instead of flashcards for dashboards. Decks should have at least three flashcards. + 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. @@ -394,7 +454,14 @@ const createDocToolInfo: ToolInfo<CreateDocumentToolParamsType> = { }; // Tool class for creating documents -export class CreateDocTool extends BaseTool<CreateListDocToolParamsType> { +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) { @@ -403,9 +470,18 @@ export class CreateDocTool extends BaseTool<CreateListDocToolParamsType> { } // Executes the tool logic for creating documents - async execute(args: ParametersType<CreateListDocToolParamsType>): Promise<Observation[]> { + async execute( + args: ParametersType< + { + name: 'string'; + type: 'string' | 'number' | 'boolean' | 'string[]' | 'number[]'; + description: 'string'; + required: boolean; + }[] + > + ): Promise<Observation[]> { try { - const parsedDocs = JSON.parse(args.docs) as parsedDoc[]; + const parsedDocs = args instanceof Array ? args : [args]; // JSON.parse((args as any).data) as parsedDoc[]; parsedDocs.forEach(doc => this._addLinkedDoc({ ...doc, _layout_fitWidth: false, _layout_autoHeight: true })); return [{ type: 'text', text: 'Created document.' }]; } catch (error) { diff --git a/src/client/views/nodes/chatbot/types/tool_types.ts b/src/client/views/nodes/chatbot/types/tool_types.ts index 6fbb7225b..6ae48992d 100644 --- a/src/client/views/nodes/chatbot/types/tool_types.ts +++ b/src/client/views/nodes/chatbot/types/tool_types.ts @@ -1,4 +1,3 @@ -import { Observation } from './types'; /** * The `Parameter` type defines the structure of a parameter configuration. */ |