aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralyssaf16 <alyssa_feinberg@brown.edu>2024-10-30 22:17:57 -0400
committeralyssaf16 <alyssa_feinberg@brown.edu>2024-10-30 22:17:57 -0400
commitcd54cba6269dbc4e10b457fe7eddd5114a9d301e (patch)
tree91c0406991193b6f8667db09f4eec4e9afcb689b /src
parentf37c99bb332bba274dc93b7509696c6d61c3dd21 (diff)
version 5 working
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx21
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts91
2 files changed, 38 insertions, 74 deletions
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
index 0939247b7..4a39ee388 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -428,22 +428,22 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
// });
// };
@action
- private createCollectionWithChildren = async (data: string[]): Promise<Doc[]> => {
+ private createCollectionWithChildren = async (data: any): Promise<Doc[]> => {
console.log('Creating collection with nested documents');
// Create an array of promises for each document
const childDocPromises = data.map(async doc => {
- const parsedDoc = JSON.parse(doc);
+ const parsedDoc = doc;
console.log('Parse #3: ' + parsedDoc);
if (parsedDoc.doc_type !== 'collection') {
// Handle non-collection documents
- return await this.whichDoc(parsedDoc.doc_type, parsedDoc.data, parsedDoc.options, parsedDoc.id);
+ return await this.whichDoc(parsedDoc.doc_type, parsedDoc.data, { backgroundColor: parsedDoc.backgroundColor, _width: parsedDoc.width, _height: parsedDoc.height }, parsedDoc.id);
} else {
// Recursively process collections
- const nestedDocs = await this.createCollectionWithChildren(JSON.parse(parsedDoc.data) as string[]);
+ const nestedDocs = await this.createCollectionWithChildren(parsedDoc.data);
const collectionOptions: DocumentOptions = {
title: parsedDoc.title,
- backgroundColor: parsedDoc.background_color,
+ backgroundColor: parsedDoc.backgroundColor,
_width: parsedDoc.width,
_height: parsedDoc.height,
_layout_fitWidth: true,
@@ -491,13 +491,14 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
doc = DocCast(Docs.Create.SimulationDocument(options));
break;
case 'collection': {
- const par = JSON.parse(data);
- console.log('Parse #2: ' + par);
- const arr = await this.createCollectionWithChildren(par);
+ // const par = JSON.parse(data);
+ // console.log('Parse #2: ' + par);
+ const arr = await this.createCollectionWithChildren(data);
options._layout_fitWidth = true;
options._freeform_backgroundGrid = true;
- const opts = { _width: 500, _height: 800, _layout_fitWidth: true, _freeform_backgroundGrid: true };
- doc = DocCast(Docs.Create.FreeformDocument(arr, opts));
+
+ // const opts = { _width: 500, _height: 800, _layout_fitWidth: true, _freeform_backgroundGrid: true };
+ doc = DocCast(Docs.Create.FreeformDocument(arr, options));
break;
}
case 'web':
diff --git a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
index a1924ed82..0b83ff24f 100644
--- a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
+++ b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
@@ -3,18 +3,19 @@ import { BaseTool } from './BaseTool';
import { Observation } from '../types/types';
import { ParametersType } from '../types/tool_types';
import { DocumentOptions } from '../../../../documents/Documents';
-const jsonData = [
+
+const example = [
{
doc_type: 'collection',
title: 'Science Collection',
- data: JSON.stringify([
+ data: [
{
doc_type: 'flashcard',
title: 'Photosynthesis',
- data: JSON.stringify({ 'What is photosynthesis?': 'The process by which plants make food.' }),
+ data: { 'What is photosynthesis?': 'The process by which plants make food.' },
+ backgroundColor: '#00ff00',
width: 300,
height: 300,
- backgroundColor: '#0000FF',
},
{
doc_type: 'text',
@@ -26,11 +27,12 @@ const jsonData = [
{
doc_type: 'collection',
title: 'Advanced Biology',
- data: JSON.stringify([
+ data: [
{
doc_type: 'flashcard',
title: 'Respiration',
- data: JSON.stringify({ 'What is respiration?': 'Conversion of oxygen and glucose to energy.' }),
+ data: { 'What is respiration?': 'Conversion of oxygen and glucose to energy.' },
+ backgroundColor: '#00ff00',
width: 300,
height: 300,
},
@@ -41,67 +43,23 @@ const jsonData = [
width: 300,
height: 300,
},
- ]),
- width: 600,
- height: 600,
- },
- ]),
- width: 600,
- height: 600,
- },
- {
- doc_type: 'collection',
- title: 'Math Collection',
- data: JSON.stringify([
- {
- doc_type: 'flashcard',
- title: 'Pythagorean Theorem',
- data: JSON.stringify({ 'What is the Pythagorean theorem?': 'In a right triangle, a² + b² = c².' }),
- width: 300,
- height: 300,
- backgroundColor: '#FFA500',
- },
- {
- doc_type: 'text',
- title: 'Calculus Introduction',
- data: 'Calculus is the mathematical study of continuous change.',
- width: 300,
- height: 300,
- },
- {
- doc_type: 'collection',
- title: 'Algebra Concepts',
- data: JSON.stringify([
- {
- doc_type: 'flashcard',
- title: 'Quadratic Formula',
- data: JSON.stringify({ 'What is the quadratic formula?': 'x = (-b ± √(b² - 4ac)) / 2a' }),
- width: 300,
- height: 300,
- },
- {
- doc_type: 'text',
- title: 'Linear Equations',
- data: 'A linear equation is an equation between two variables that gives a straight line when plotted.',
- width: 300,
- height: 300,
- },
- ]),
+ ],
width: 600,
height: 600,
},
- ]),
+ ],
width: 600,
height: 600,
},
];
-// Stringify the entire object if needed for your API
-const finalJsonString = JSON.stringify(jsonData);
+// Stringify the entire structure for transmission if needed
+const finalJsonString = JSON.stringify(example);
const docInstructions = {
collection: {
- description: 'A recursive collection of documents. Each document can be a "text", "flashcard", "image", "web", or another "collection".',
+ description:
+ 'A recursive collection of documents as a stringified array. Each document can be a "text", "flashcard", "image", "web", "image", "comparison", "equation", "noteboard", "simulation", "diagram", "map", "screengrab", "webcam", "button", or another "collection".',
example: finalJsonString,
// example: [
// {
@@ -156,6 +114,10 @@ const docInstructions = {
flashcardDeck: 'A collection of flashcards under a common theme.',
image: 'A URL to an image. Example: "https://example.com/image.jpg"',
web: 'A URL to a webpage. Example: "https://example.com"',
+ equation: 'Create a equation document.',
+ noteboard: 'Create a noteboard document',
+ comparison: 'Create a comparison document',
+ simulation: 'Create a simulation document',
} as const;
const createDocToolParams = [
@@ -211,8 +173,9 @@ const createListDocToolParams = [
'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). ' +
'Use this structure for nesting collections within collections. Each document should follow the structure in ' +
createDocToolParams +
- '. Example: ' + finalJsonString,
- //Example: ["{"doc_type":"collection","title":"Science Topics","data":"[\\"{\\\\"doc_type\\\\":\\\\"text\\\\",\\\\"title\\\\":\\\\"Photosynthesis\\\\",\\\\"background_color\\\\":\\\\"#0000FF\\\\",\\\\"data\\\\":\\\\"Photosynthesis is the process by which plants make food.\\\\",\\\\"width\\\\":300,\\\\"height\\\\":300}\\",\\"{\\\\"doc_type\\\\":\\\\"collection\\\\",\\\\"title\\\\":\\\\"Advanced Biology\\\\",\\\\"data\\\\":\\\\"[\\\\"{\\\\"doc_type\\\\":\\\\"flashcard\\\\",\\\\"title\\\\":\\\\"Respiration\\\\",\\\\"data\\\\":{\\\\"What is respiration?\\\\":\\\\"Conversion of oxygen and glucose to energy.\\\\"},\\\\"width\\\\":300,\\\\"height\\\\":300}\\",\\\\"{\\\\"doc_type\\\\":\\\\"text\\\\",\\\\"title\\\\":\\\\"Cell Structure\\\\",\\\\"data\\\\":\\\\"Cells are the basic building blocks of all living organisms.\\\\",\\\\"width\\\\":300,\\\\"height\\\\":300}\\"]\\\\",\\\\"width\\\\":600,\\\\"height\\\\":600}\\"]","width":600,"height":600}"]',
+ '. Example: ' +
+ finalJsonString,
+ //["{"doc_type":"collection","title":"Science Topics","data":"[\\"{\\\\"doc_type\\\\":\\\\"text\\\\",\\\\"title\\\\":\\\\"Photosynthesis\\\\",\\\\"background_color\\\\":\\\\""#0000FF"\\\\",\\\\"data\\\\":\\\\"Photosynthesis is the process by which plants make food.\\\\",\\\\"width\\\\":300,\\\\"height\\\\":300}\\",\\"{\\\\"doc_type\\\\":\\\\"collection\\\\",\\\\"title\\\\":\\\\"Advanced Biology\\\\",\\\\"data\\\\":\\\\"[\\\\"{\\\\"doc_type\\\\":\\\\"flashcard\\\\",\\\\"title\\\\":\\\\"Respiration\\\\",\\\\"data\\\\":{\\\\"What is respiration?\\\\":\\\\"Conversion of oxygen and glucose to energy.\\\\"},\\\\"width\\\\":300,\\\\"height\\\\":300}\\",\\\\"{\\\\"doc_type\\\\":\\\\"text\\\\",\\\\"title\\\\":\\\\"Cell Structure\\\\",\\\\"data\\\\":\\\\"Cells are the basic building blocks of all living organisms.\\\\",\\\\"width\\\\":300,\\\\"height\\\\":300}\\"]\\\\",\\\\"width\\\\":600,\\\\"height\\\\":600}\\"]","width":600,"height":600}"]',
//["{"doc_type":"collection","title":"Science Topics","data":["{\\"doc_type\\":\\"text\\",\\"title\\":\\"Photosynthesis\\",\\"data\\":\\"Photosynthesis is the process by which plants make food.\\",\\"width\\":300,\\"height\\":300}","{\\"doc_type\\":\\"collection\\",\\"title\\":\\"Advanced Biology\\",\\"data\\":["{\\"doc_type\\":\\"flashcard\\",\\"title\\":\\"Respiration\\",\\"data\\":{\\"What is respiration?\\":\\"Conversion of oxygen and glucose to energy.\\"},\\"width\\":300,\\"height\\":300}","{\\"doc_type\\":\\"text\\",\\"title\\":\\"Cell Structure\\",\\"data\\":\\"Cells are the basic building blocks of all living organisms.\\",\\"width\\":300,\\"height\\":300}"],\\"width\\":600,\\"height\\":600}"],"width":600,"height":600}"]',
required: true,
@@ -244,14 +207,14 @@ export class CreateDocTool extends BaseTool<CreateListDocToolParamsType> {
*/
try {
- // console.log('EXE' + args.docs);
+ console.log('EXE' + args.docs);
const parsedDoc = JSON.parse(args.docs);
console.log('parsed' + parsedDoc);
- parsedDoc.forEach((firstDoc: string) => {
+ parsedDoc.forEach(doc => {
// console.log('THIS DOC' + firstDoc);
- console.log(typeof firstDoc);
- const doc = JSON.parse(firstDoc);
- console.log('NEW DOC' + doc);
+ // console.log(typeof firstDoc);
+ // const doc = JSON.parse(firstDoc);
+ // console.log('NEW DOC' + doc);
// console.log('TYPE' + doc['doc_type']);
// console.log('WIDTH' + doc['width']);
// console.log('HEIGHT' + doc['height']);
@@ -259,7 +222,7 @@ export class CreateDocTool extends BaseTool<CreateListDocToolParamsType> {
this._addLinkedDoc(
doc['doc_type'],
doc['data'],
- { title: doc['title'], backgroundColor: doc['background_color'], text_fontColor: doc['font_color'], _width: doc['width'], _height: doc['height'], _layout_fitWidth: false, _layout_autoHeight: true },
+ { title: doc['title'], backgroundColor: doc['backgroundColor'], text_fontColor: doc['font_color'], _width: doc['width'], _height: doc['height'], _layout_fitWidth: false, _layout_autoHeight: true },
uuidv4()
);
});