diff options
author | alyssaf16 <alyssa_feinberg@brown.edu> | 2025-01-13 16:54:19 -0500 |
---|---|---|
committer | alyssaf16 <alyssa_feinberg@brown.edu> | 2025-01-13 16:54:19 -0500 |
commit | 9e3ca3743437396a16b3e3f402e76336b056d6b7 (patch) | |
tree | b3de7eebfd721f1a0f08f31597dff24b4df5b546 | |
parent | 91b478e7bf69c2b4fe52185a0dd35ce8035b534b (diff) |
commit createdocumenttool
-rw-r--r-- | src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts | 118 |
1 files changed, 71 insertions, 47 deletions
diff --git a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts index 829ab97a4..63a6004a7 100644 --- a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts +++ b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts @@ -4,6 +4,14 @@ import { Observation } from '../types/types'; import { ParametersType } from '../types/tool_types'; import { DocumentOptions } from '../../../../documents/Documents'; +/** + * 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: 'equation', @@ -11,6 +19,8 @@ const example = [ data: 'x^2 + y^2 = 3', width: 300, height: 300, + x: 0, + y: 0, }, { doc_type: 'collection', @@ -22,11 +32,15 @@ const example = [ 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', }, { @@ -35,6 +49,8 @@ const example = [ 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: 'deck', @@ -50,6 +66,8 @@ const example = [ data: 'What is photosynthesis?', width: 300, height: 300, + x: 100, + y: 600, }, { doc_type: 'text', @@ -57,11 +75,15 @@ const example = [ 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: 'flashcard', @@ -73,6 +95,8 @@ const example = [ data: 'What is photosynthesis?', width: 300, height: 300, + x: 200, + y: 800, }, { doc_type: 'text', @@ -80,16 +104,22 @@ const example = [ 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: 'web', @@ -97,6 +127,8 @@ const example = [ data: 'https://en.wikipedia.org/wiki/Brown_University', width: 300, height: 300, + x: 1000, + y: 2000, }, { doc_type: 'simulation', @@ -104,6 +136,8 @@ const example = [ data: '', width: 300, height: 300, + x: 100, + y: 100, }, { doc_type: 'comparison', @@ -115,6 +149,8 @@ const example = [ 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: 'text', @@ -122,10 +158,14 @@ const example = [ 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: 'collection', @@ -160,6 +200,8 @@ const example = [ data: 'https://en.wikipedia.org/wiki/Brown_University', width: 300, height: 300, + x: 1100, + y: 1100, }, { doc_type: 'text', @@ -167,6 +209,8 @@ const example = [ data: 'The continuous movement of water on, above, and below the Earth’s surface.', width: 300, height: 300, + x: 1500, + y: 500, }, { doc_type: 'collection', @@ -183,11 +227,15 @@ const example = [ backgroundColor: '#00ff00', width: 600, height: 600, + x: 1100, + y: 500, type_collection: 'freeform', }, ], width: 600, height: 600, + x: 500, + y: 500, type_collection: 'freeform', }, ]; @@ -195,6 +243,7 @@ const example = [ // Stringify the entire structure for transmission if needed const finalJsonString = JSON.stringify(example); +// Instructions for creating various document types const docInstructions = { collection: { description: @@ -204,15 +253,14 @@ const docInstructions = { text: 'Provide text content as a plain string. Example: "This is a standalone text document."', flashcard: 'Two text documents with content for the front and back.', deck: 'A decks data is an array of flashcards.', - image: 'A URL to an image for data. Example: "https://example.com/image.jpg"', web: 'A URL to a webpage. Example: https://en.wikipedia.org/wiki/Brown_University', equation: 'Create an equation document, not a text document. Data is math equation.', noteboard: 'Create a noteboard document', - comparison: 'Create a comparison document - in type_collection specify the type of collection: masonry, freeform, tree, carousel.', simulation: 'Create a simulation document', audio: 'A url to an audio recording. Example: ', } as const; +// Parameters for creating individual documents const createDocToolParams = [ { name: 'data', @@ -223,7 +271,7 @@ const createDocToolParams = [ { name: 'doc_type', type: 'string', - description: 'The type of the document. Options: "collection", "text", "flashcard", "image", "web".', + description: 'The type of the document. Options: "collection", "text", "flashcard", "web".', required: true, }, { @@ -233,6 +281,18 @@ const createDocToolParams = [ 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: 'background_color', type: 'string', description: 'The background color of the document as a hex string.', @@ -264,12 +324,13 @@ const createDocToolParams = [ }, ] as const; +// Parameters for creating a list of documents const createListDocToolParams = [ { name: 'docs', - type: 'string', // Array of stringified JSON objects + 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", "image", "web", or "collection" (for nested documents). ' + + '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", "web", or "collection" (for nested documents). ' + 'Use this structure for nesting collections within collections. Each document should follow the structure in ' + createDocToolParams + '. Example: ' + @@ -280,14 +341,14 @@ const createListDocToolParams = [ type CreateListDocToolParamsType = typeof createListDocToolParams; +// Tool class for creating documents export class CreateDocTool extends BaseTool<CreateListDocToolParamsType> { private _addLinkedDoc: (doc_type: string, data: string, options: DocumentOptions, id: string) => void; constructor(addLinkedDoc: (doc_type: string, data: string, options: DocumentOptions, id: string) => void) { super( 'createDoc', - 'Creates one or more documents that best fit the user’s request. If the user requests a "dashboard," first call search tool and then generate a variety of document types individually, each with different content and color schemes. For example, create multiple individual documents like "text," "deck," "web," "image," "equation," and "comparison." Use decks instead of flashcards for dashboards. ' + - '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.', + '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. 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.', createListDocToolParams, '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, simulation, and equation documents, each with distinct titles and colors, following the user’s preferences. ' + @@ -295,49 +356,10 @@ export class CreateDocTool extends BaseTool<CreateListDocToolParamsType> { 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.' ); - - // super( - // 'createDoc', - // 'Creates one or more documents that best fit users request with input following the example below. Or creates a dashboard of many documents/collections with this as an example: ' + finalJsonString, - // createListDocToolParams, - // 'Modify the data parameter and include title (and optionally color) for the document. Web doc data type must be url from search tool.', - // 'Creates one or more documents represented by an array of strings with the provided content based on the instructions ' + - // docInstructions + - // 'Use if the user wants to create something that aligns with a document type in dash like a flashcard, flashcard deck/stack, or textbox or text document of some sort. Can use after the search tool to save information.' + - // 'When user asks for dashboard, create many documents/collections with different colors and texts while listening to their preferences, after using search tool to create a dashboard.' - // ); - // this._addLinkedDoc = addLinkedDoc; - - // super( - // 'createDoc', - // 'Creates one or more documents based on the user’s request. If the user asks for a "dashboard," generate multiple documents of different types, such as "text," "flashcard," "image," "web," "comparison," and "collection," and include no more than three web documents unless specified otherwise. For a single document request (like "a text document"), create only the requested document type, without extra templates. Follow the examples below to understand the structure of various document types and their required properties.', - // createListDocToolParams, - // 'Use the "data" parameter to specify document content and include the title (and optionally colors) for each document. For web documents, use a URL from a search tool if applicable.' + - // 'For dashboards, create a diverse array of documents including text, flashcard decks, images, comparisons, and collections, with a mix of colors and unique titles, adhering to the user’s preferences. Example structures are provided for both dashboards and individual document types.' + - // 'Examples:' + - // finalJsonString, - // '' - // ); - - // super( - // 'createDoc', - // 'Creates one or more documents that best fit users request with input following the example below. Or creates a dashboard for the user; there must be different kinds of documents. If the user asks for "a" document, only make one since it is singular - not an additional template one or more documents.', - // createListDocToolParams, - // 'Modify the data parameter and include title (and optionally color) for the document. ' + - // 'Web doc data type must be url from search tool. ' + - // 'Creates one or more documents represented by an array of strings with the provided content based on the instructions ' + - // docInstructions + - // //'. If user asks for dashboard, create many documents/collections, including text, web, image, flashcard, deck, comparison, and collection, after calling the search tool following this example but only have three websites max: ' + - // //'Use if the user wants to create something that aligns with a document type in dash like a flashcard, flashcard deck/stack, or textbox or text document of some sort. Can use after the search tool to save information. If use after the search tool, do not use than more than 3 websites unless specified if dashboard; have text documents, flashcards, and more documents.' + - // // 'When user asks for dashboard, create many documents/collections of different types, such as text, web, flashcard, with different colors and texts while listening to their preferences, after using search tool to create a dashboard. Documents, such as text and web, should not all be in a collection unless specified. Do not have too many websites, and all websites do not need to be in one collection. An example of a dashboard is ' + - // // finalJsonString - // '. If user asks for dashboard, first use search tool. Then create text, web, flashcard, collections, and comparison documents. There absolutely must be different kinds of documents.' + - // 'Do not only have web documents for dashboard; have other kinds of documents. Follow this example: ' + - // finalJsonString - // ); this._addLinkedDoc = addLinkedDoc; } + // Executes the tool logic for creating documents async execute(args: ParametersType<CreateListDocToolParamsType>): Promise<Observation[]> { try { console.log('EXE' + args.docs); @@ -356,6 +378,8 @@ export class CreateDocTool extends BaseTool<CreateListDocToolParamsType> { type_collection: doc['type_collection'], _layout_fitWidth: false, _layout_autoHeight: true, + x: doc['x'], + y: doc['y'], }, uuidv4() ); |