aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-02-09 15:43:08 -0500
committerbobzel <zzzman@gmail.com>2025-02-09 15:43:08 -0500
commit5df52296c65c4eed27b06e4d3fd22e935df5427c (patch)
treee866cbc8b6198f3cfb425c007e0abc65a9c3ff5e
parentbb624694da02a56ce10e3bfa4c75957592e3a86d (diff)
trying to get assistant to create Docs properly
-rw-r--r--.env21
-rw-r--r--src/client/views/nodes/chatbot/agentsystem/Agent.ts5
-rw-r--r--src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx178
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts23
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts143
-rw-r--r--src/server/ApiManagers/AssistantManager.ts5
-rw-r--r--src/server/server_Initialization.ts2
7 files changed, 158 insertions, 199 deletions
diff --git a/.env2 b/.env2
index 08ee154e1..9c58d07cc 100644
--- a/.env2
+++ b/.env2
@@ -2,3 +2,4 @@
export _CLIENT_FIREFLY_CLIENT_ID='62eb3cc56d8d47c88ff67103ded0003f'
export _CLIENT_FIREFLY_SECRET='p8e-4JxcVXG6izNEnf0ceEPO1zSZ7U13TMUQ'
export _CLIENT_FIREFLY_TOKEN='eyJhbGciOiJSUzI1NiIsIng1dSI6Imltc19uYTEta2V5LWF0LTEuY2VyIiwia2lkIjoiaW1zX25hMS1rZXktYXQtMSIsIml0dCI6ImF0In0.eyJpZCI6IjE3MzMyMzgwMjg3NDVfNDg0ODM3ZTAtMmU3Zi00NWFkLTkzZjEtZjM0NWRkNDM3MzAwX3VlMSIsIm9yZyI6IjVEOEUxREMzNjcyNTQ2MDIwQTQ5NUZGMEBBZG9iZU9yZyIsInR5cGUiOiJhY2Nlc3NfdG9rZW4iLCJjbGllbnRfaWQiOiI2MmViM2NjNTZkOGQ0N2M4OGZmNjcxMDNkZWQwMDAzZiIsInVzZXJfaWQiOiI2MzQ1MUQ5RTY3MjU1MEQ4MEE0OTVFQ0FAdGVjaGFjY3QuYWRvYmUuY29tIiwiYXMiOiJpbXMtbmExIiwiYWFfaWQiOiI2MzQ1MUQ5RTY3MjU1MEQ4MEE0OTVFQ0FAdGVjaGFjY3QuYWRvYmUuY29tIiwiY3RwIjozLCJtb2kiOiI3NDc2MDZiZCIsImV4cGlyZXNfaW4iOiI4NjQwMDAwMCIsInNjb3BlIjoiZmlyZWZseV9hcGksYWRkaXRpb25hbF9pbmZvLG9wZW5pZCxzZXNzaW9uLEFkb2JlSUQsZmZfYXBpcyxyZWFkX29yZ2FuaXphdGlvbnMiLCJjcmVhdGVkX2F0IjoiMTczMzIzODAyODc0NSJ9.O-HGx7ji_-RZJXmCnsPVzdTmJA4s_fA0Gj0s7z1FZ6MPtzdXa9MSYkMYdo4ImfiYZGf73SeJACEpfTdgyd7shG3qXBydeZV2exGQcN6eve88zXMBsc98aCi0mPz2eql4MomJk9xGXuk3ZuZmVAbsAVfwScPU_uyl75DZAq4_4e6lyXakEti9ACYnEl-7TQQeEgK6Mr4R8giUWvYVAdmSK4xOq67yjBToj6S-fv_s2dBRY58x_fMkORCrJnDLEnSdXS2LXHXAyM_Up9EaezIovlVhwz04BuwrH0vVOJN7uHgFOeWbjULaGGYy2Wzb1hPeRVd7VIRiw3sHavthTSJ3KA'
+export _CLIENT_GOOGLE_API_KEY='AIzaSyBj6OSkxD3NxEycRKjTyJoP1MSRs1P3vqk' \ No newline at end of file
diff --git a/src/client/views/nodes/chatbot/agentsystem/Agent.ts b/src/client/views/nodes/chatbot/agentsystem/Agent.ts
index ee91ccb92..25e471ce8 100644
--- a/src/client/views/nodes/chatbot/agentsystem/Agent.ts
+++ b/src/client/views/nodes/chatbot/agentsystem/Agent.ts
@@ -8,8 +8,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, supportedDocumentTypes } from '../tools/CreateAnyDocTool';
-import { CreateDocTool } from '../tools/CreateDocumentTool';
+import { CreateDocTool, supportedDocumentTypes } from '../tools/CreateDocumentTool';
import { DataAnalysisTool } from '../tools/DataAnalysisTool';
import { NoTool } from '../tools/NoTool';
import { SearchTool } from '../tools/SearchTool';
@@ -77,7 +76,7 @@ export class Agent {
noTool: new NoTool(),
createDoc: new CreateDocTool(addLinkedDoc),
//createTextDoc: new CreateTextDocTool(addLinkedDoc),
- createAnyDocument: new CreateAnyDocumentTool(addLinkedDoc),
+ //createAnyDocument: new CreateAnyDocumentTool(addLinkedDoc),
};
}
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
index 076f49831..47d4fb8a7 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -14,10 +14,9 @@ import OpenAI, { ClientOptions } from 'openai';
import * as React from 'react';
import { v4 as uuidv4 } from 'uuid';
import { ClientUtils } from '../../../../../ClientUtils';
-import { Doc, DocListCast, FieldType, Opt } from '../../../../../fields/Doc';
+import { Doc, DocListCast, Opt } from '../../../../../fields/Doc';
import { DocData, DocViews } from '../../../../../fields/DocSymbols';
import { CsvCast, DocCast, NumCast, PDFCast, RTFCast, StrCast } from '../../../../../fields/Types';
-import { Networking } from '../../../../Network';
import { DocUtils } from '../../../../documents/DocUtils';
import { CollectionViewType, DocumentType } from '../../../../documents/DocumentTypes';
import { Docs, DocumentOptions } from '../../../../documents/Documents';
@@ -33,9 +32,11 @@ import { Vectorstore } from '../vectorstore/Vectorstore';
import './ChatBox.scss';
import MessageComponentBox from './MessageComponent';
import { ProgressBar } from './ProgressBar';
+import { supportedDocumentTypes } from '../tools/CreateDocumentTool';
dotenv.config();
+type parsedDoc = { doc_type: string; id: string; data: unknown; title: string; width: number; height: number; backgroundColor: string };
/**
* ChatBox is the main class responsible for managing the interaction between the user and the assistant,
* handling documents, and integrating with OpenAI for tasks such as document analysis, chat functionality,
@@ -399,48 +400,26 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
* @param id The unique ID for the document.
*/
@action
- private createCollectionWithChildren = (data: { doc_type: string; id: string; data: any; title: string; width: number; height: number; backgroundColor: string }[], insideCol: boolean): Promise<Doc[]> =>
- Promise.all(
- data.map(doc =>
- doc.doc_type !== 'collection' // Handle non-collection documents
- ? this.whichDoc(doc.doc_type, doc.data, { backgroundColor: doc.backgroundColor, _width: doc.width, _height: doc.height }, doc.id, insideCol)
- : this.createCollectionWithChildren(doc.data, true).then(nestedDocs =>
- Docs.Create.FreeformDocument(nestedDocs, {
- title: doc.title,
- backgroundColor: doc.backgroundColor,
- _width: doc.width,
- _height: doc.height,
- _layout_fitWidth: true,
- _freeform_backgroundGrid: true,
- })
- )
- ) // prettier-ignore
- ).then(childDocs => childDocs.filter(doc => doc).map(doc => doc!));
- // .then(nestedResults => {
- // // Flatten any nested arrays from recursive collection calls
- // const childDocs = nestedResults.flat() as Doc[];
- // childDocs.forEach(doc => {
- // console.log(DocCast(doc));
- // console.log(DocCast(doc)[DocData].data);
- // console.log(DocCast(doc)[DocData].data);
- // });
- // return childDocs;
- // });
+ private createCollectionWithChildren = (data: parsedDoc[], insideCol: boolean): Opt<Doc>[] =>
+ data.map(doc => this.whichDoc(doc.doc_type, doc.data, { backgroundColor: doc.backgroundColor, _width: doc.width, _height: doc.height }, doc.id, insideCol));
@action
- whichDoc = (doc_type: string, data: unknown, options: DocumentOptions, id: string, insideCol: boolean): Promise<Opt<Doc>> =>
- (async () => {
+ whichDoc = (doc_type: string, data: unknown, options: DocumentOptions, id: string, insideCol: boolean): Opt<Doc> => {
+ const ndoc = (() => {
switch (doc_type) {
- case 'text': return Docs.Create.TextDocument(data as string, options);
- case 'flashcard': return this.createFlashcard(data as string[], options);
- case 'deck': return this.createDeck(data as string, options);
- case 'image': return Docs.Create.ImageDocument(data as string, options);
- case 'equation': return Docs.Create.EquationDocument(data as string, options);
- case 'noteboard': return Docs.Create.NoteTakingDocument([], options);
- case 'simulation': return Docs.Create.SimulationDocument(options);
- case 'collection': return this.createCollectionWithChildren(data as { doc_type: string; id: string; data: any; title: string; width: number; height: number; backgroundColor: string }[] , true).
- then((arr, collOpts = { ...options, _layout_fitWidth: true, _freeform_backgroundGrid: true }) =>
- (() => {
+ 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.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 };
+ return (() => {
switch (options.type_collection) {
case CollectionViewType.Tree: return Docs.Create.TreeDocument(arr, collOpts);
case CollectionViewType.Masonry: return Docs.Create.MasonryDocument(arr, collOpts);
@@ -450,31 +429,26 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
case CollectionViewType.Multicolumn: return Docs.Create.CarouselDocument(arr, collOpts);
default: return Docs.Create.FreeformDocument(arr, collOpts);
}
- })()
- );
- case 'web': return Docs.Create.WebDocument(data as string, { ...options, data_useCors: true });
- case 'comparison': return this.createComparison(data as {left: {width:number ,height: number, backgroundColor: string, data: string}, right: {width:number ,height: number, backgroundColor: string, data: string}}, options);
- case 'diagram': return Docs.Create.DiagramDocument(options);
- case 'audio': return Docs.Create.AudioDocument(data as string, options);
- case 'map': return Docs.Create.MapDocument([], options);
- case 'screengrab': return Docs.Create.ScreenshotDocument(options);
- case 'webcam': return Docs.Create.WebCamDocument('', options);
- case 'button': return Docs.Create.ButtonDocument(options);
- case 'script': return Docs.Create.ScriptingDocument(null, options);
- case 'dataviz': return Docs.Create.DataVizDocument('/users/rz/Downloads/addresses.csv', options);
- case 'chat': return Docs.Create.ChatDocument(options);
- case 'trail': return Docs.Create.PresDocument(options);
- case 'tab': return Docs.Create.FreeformDocument([], options);
- case 'slide': return Docs.Create.TreeDocument([], options);
+ })();
+ }
+ // case supportedDocumentTypes.diagram: return Docs.Create.DiagramDocument(options);
+ // case supportedDocumentTypes.audio: return Docs.Create.AudioDocument(data as string, options);
+ // case supportedDocumentTypes.map: return Docs.Create.MapDocument([], options);
+ // case supportedDocumentTypes.button: return Docs.Create.ButtonDocument(options);
+ // case supportedDocumentTypes.script: return Docs.Create.ScriptingDocument(null, options);
+ // case supportedDocumentTypes.chat: return Docs.Create.ChatDocument(options);
+ // case supportedDocumentTypes.trail: return Docs.Create.PresDocument(options);
+ // case supportedDocumentTypes.trail: return Docs.Create.FreeformDocument([], options);
default: return Docs.Create.TextDocument(data as string, options);
} // prettier-ignore
- })().then(doc => {
- if (doc) {
- doc.x = NumCast((options.x as number) ?? 0) + (insideCol ? 0 : NumCast(this.layoutDoc.x) + NumCast(this.layoutDoc.width)) + 100;
- doc.y = NumCast(options.y as number) + (insideCol ? 0 : NumCast(this.layoutDoc.y));
- }
- return doc;
- });
+ })();
+
+ if (ndoc) {
+ ndoc.x = NumCast((options.x as number) ?? 0) + (insideCol ? 0 : NumCast(this.layoutDoc.x) + NumCast(this.layoutDoc.width)) + 100;
+ ndoc.y = NumCast(options.y as number) + (insideCol ? 0 : NumCast(this.layoutDoc.y));
+ }
+ return ndoc;
+ };
/**
* Creates a document in the dashboard.
@@ -494,32 +468,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {});
}
};
- const doc = (() => {
- switch (doc_type.toLowerCase()) {
- case 'flashcard': return this.createFlashcard(data as string[], options);
- case 'text': return Docs.Create.TextDocument(data as string || '', options);
- case 'image': return Docs.Create.ImageDocument(data as string || '', options);
- case 'pdf': return Docs.Create.PdfDocument(data as string || '', options);
- case 'video': return Docs.Create.VideoDocument(data as string || '', options);
- case 'audio': return Docs.Create.AudioDocument(data as string || '', options);
- case 'web': return Docs.Create.WebDocument(data as string || '', options);
- case 'equation': return Docs.Create.EquationDocument(data as string || '', options);
- case 'chat': return Docs.Create.ChatDocument(options);
- case 'functionplot': return Docs.Create.FunctionPlotDocument([], options);
- case 'dataviz': Networking.PostToServer('/createCSV', {
- filename: (options.title as string).replace(/\s+/g, '') + '.csv',
- data: data,
- })?.then(({ fileUrl, id }) => {
- const vdoc = Docs.Create.DataVizDocument(fileUrl, { ...options, text: RTFCast(data as FieldType) });
- this.addCSVForAnalysis(vdoc, id);
- linkAndShowDoc(vdoc);
- });
- return undefined;
- // Add more cases for other document types
- default: console.error('Unknown or unsupported document type:', doc_type);
- return undefined;
- } // prettier-ignore
- })();
+ const doc = this.whichDoc(doc_type, data, options, uuidv4(), false);
if (doc) linkAndShowDoc(doc);
};
@@ -531,17 +480,14 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
* @returns {Doc} A carousel document containing the flashcard deck.
*/
@action
- createDeck = (data: string | unknown[], options: DocumentOptions) => {
+ createDeck = (data: parsedDoc[], options: DocumentOptions) => {
const flashcardDeck: Doc[] = [];
- // Parse `data` only if it’s a string
- const deckData = typeof data === 'string' ? (JSON.parse(data) as unknown) : data;
- const flashcardArray = Array.isArray(deckData) ? deckData : Object.values(deckData as object);
// Process each flashcard document in the `deckData` array
- if (flashcardArray.length == 2 && flashcardArray[0].doc_type == 'text' && flashcardArray[1].doc_type == 'text') {
- this.createFlashcard(flashcardArray as string[], options);
+ if (data.length == 2 && data[0].doc_type == 'text' && data[1].doc_type == 'text') {
+ this.createFlashcard(data, options);
} else {
- flashcardArray.forEach(doc => {
- const flashcardDoc = this.createFlashcard(doc, options);
+ data.forEach(doc => {
+ const flashcardDoc = this.createFlashcard(doc.data as parsedDoc[] | string[], options);
if (flashcardDoc) flashcardDeck.push(flashcardDoc);
});
}
@@ -564,25 +510,21 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
* @returns {Doc | undefined} The created flashcard document, or undefined if the flashcard cannot be created.
*/
@action
- createFlashcard = (data: string[], options: DocumentOptions) => {
- const deckData = typeof data === 'string' ? JSON.parse(data) : data;
- const flashcardArray = Array.isArray(deckData) ? deckData : (Object.values(deckData)[2] as string[]);
- const [front, back] = flashcardArray;
-
- if (typeof front === 'string' && typeof back === 'string') {
- const sideOptions: DocumentOptions = {
- backgroundColor: options.backgroundColor,
- _width: options._width,
- _height: options._height || 300,
- };
+ createFlashcard = (data: parsedDoc[] | string[], options: DocumentOptions) => {
+ const [front, back] = data;
- // Create front and back text documents
- const side1 = Docs.Create.CenteredTextCreator('question', front, sideOptions);
- const side2 = Docs.Create.CenteredTextCreator('answer', back, sideOptions);
+ const sideOptions: DocumentOptions = {
+ backgroundColor: options.backgroundColor,
+ _width: options._width,
+ _height: options._height || 300,
+ };
- // Create the flashcard document with both sides
- return Docs.Create.FlashcardDocument('flashcard', side1, side2, sideOptions);
- }
+ // Create front and back text documents
+ const side1 = typeof front === 'string' ? Docs.Create.CenteredTextCreator('question', front as string, sideOptions) : this.whichDoc(front.doc_type, front.data, options, front.id, false);
+ const side2 = typeof back === 'string' ? Docs.Create.CenteredTextCreator('answer', back as string, sideOptions) : this.whichDoc(back.doc_type, back.data, options, back.id, false);
+
+ // Create the flashcard document with both sides
+ return Docs.Create.FlashcardDocument('flashcard', side1, side2, sideOptions);
};
/**
@@ -593,10 +535,10 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
* @returns {Doc} The created comparison document.
*/
@action
- createComparison = (doc: { left: { width: number; height: number; backgroundColor: string; data: string }; right: { width: number; height: number; backgroundColor: string; data: string } }, options: DocumentOptions) =>
+ createComparison = (doc: parsedDoc[], options: DocumentOptions) =>
Docs.Create.ComparisonDocument(options.title as string, {
- data_back: Docs.Create.TextDocument(doc.left.data, { backgroundColor: doc.left.backgroundColor, _width: doc.left.width, _height: doc.left.height }),
- data_front: Docs.Create.TextDocument(doc.right.data, { backgroundColor: doc.right.backgroundColor, _width: doc.right.width, _height: doc.right.height }),
+ data_back: Docs.Create.TextDocument(doc[0].data as string, { backgroundColor: doc[0].backgroundColor, _width: doc[0].width, _height: doc[0].height }),
+ data_front: Docs.Create.TextDocument(doc[1].data as string, { backgroundColor: doc[1].backgroundColor, _width: doc[1].width, _height: doc[1].height }),
_width: options._width,
_height: options._height || 300,
backgroundColor: options.backgroundColor,
diff --git a/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts b/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts
index 0049612fd..efc66880f 100644
--- a/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts
+++ b/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts
@@ -1,23 +1,12 @@
+import { toLower } from 'lodash';
import { v4 as uuidv4 } from 'uuid';
-import { BaseTool } from './BaseTool';
-import { Observation } from '../types/types';
-import { ParametersType } from '../types/tool_types';
import { DocumentOptions } from '../../../../documents/Documents';
-import { toLower } from 'lodash';
-
-export enum supportedDocumentTypes {
- flashcard = 'flashcard',
- text = 'text',
- html = 'html',
- equation = 'equation',
- functionplot = 'functionplot',
- dataviz = 'dataviz',
- notetaking = 'notetaking',
- rtf = 'rtf',
- message = 'message',
-}
+import { ParametersType } from '../types/tool_types';
+import { Observation } from '../types/types';
+import { BaseTool } from './BaseTool';
+import { supportedDocumentTypes } from './CreateDocumentTool';
-const standardOptions = ['title', 'backgroundColor', 'layout'];
+const standardOptions = ['title', 'backgroundColor'];
/**
* Description of document options and data field for each type.
*/
diff --git a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
index f0f2fe703..b919b242c 100644
--- a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
+++ b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
@@ -3,8 +3,24 @@ import { BaseTool } from './BaseTool';
import { Observation } from '../types/types';
import { ParametersType } from '../types/tool_types';
import { DocumentOptions } from '../../../../documents/Documents';
-import { supportedDocumentTypes } from './CreateAnyDocTool';
+export enum supportedDocumentTypes {
+ flashcard = 'flashcard',
+ text = 'text',
+ html = 'html',
+ equation = 'equation',
+ functionplot = 'functionplot',
+ dataviz = 'dataviz',
+ notetaking = 'notetaking',
+ audio = 'audio',
+ rtf = 'rtf',
+ message = 'message',
+ collection = 'collection',
+ image = 'image',
+ deck = 'deck',
+ web = 'web',
+ comparison = 'comparison',
+}
/**
* Tthe CreateDocTool class is responsible for creating
* documents of various types (e.g., text, flashcards, collections) and organizing them in a
@@ -15,7 +31,7 @@ import { supportedDocumentTypes } from './CreateAnyDocTool';
// Example document structure for various document types
const example = [
{
- doc_type: 'equation',
+ doc_type: supportedDocumentTypes.equation,
title: 'quadratic',
data: 'x^2 + y^2 = 3',
width: 300,
@@ -24,11 +40,11 @@ const example = [
y: 0,
},
{
- doc_type: 'collection',
+ doc_type: supportedDocumentTypes.collection,
title: 'Advanced Biology',
data: [
{
- doc_type: 'text',
+ doc_type: supportedDocumentTypes.text,
title: 'Cell Structure',
data: 'Cells are the basic building blocks of all living organisms.',
width: 300,
@@ -45,7 +61,7 @@ const example = [
type_collection: 'tree',
},
{
- doc_type: 'image',
+ doc_type: supportedDocumentTypes.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,
@@ -54,15 +70,15 @@ const example = [
y: 300,
},
{
- doc_type: 'deck',
+ doc_type: supportedDocumentTypes.deck,
title: 'Chemistry',
data: [
{
- doc_type: 'flashcard',
+ doc_type: supportedDocumentTypes.flashcard,
title: 'Photosynthesis',
data: [
{
- doc_type: 'text',
+ doc_type: supportedDocumentTypes.text,
title: 'front_Photosynthesis',
data: 'What is photosynthesis?',
width: 300,
@@ -71,7 +87,7 @@ const example = [
y: 600,
},
{
- doc_type: 'text',
+ doc_type: supportedDocumentTypes.text,
title: 'back_photosynthesis',
data: 'The process by which plants make food.',
width: 300,
@@ -87,11 +103,11 @@ const example = [
y: 1000,
},
{
- doc_type: 'flashcard',
+ doc_type: supportedDocumentTypes.flashcard,
title: 'Photosynthesis',
data: [
{
- doc_type: 'text',
+ doc_type: supportedDocumentTypes.text,
title: 'front_Photosynthesis',
data: 'What is photosynthesis?',
width: 300,
@@ -100,7 +116,7 @@ const example = [
y: 800,
},
{
- doc_type: 'text',
+ doc_type: supportedDocumentTypes.text,
title: 'back_photosynthesis',
data: 'The process by which plants make food.',
width: 300,
@@ -123,7 +139,7 @@ const example = [
y: 800,
},
{
- doc_type: 'web',
+ doc_type: supportedDocumentTypes.web,
title: 'Brown University Wikipedia',
data: 'https://en.wikipedia.org/wiki/Brown_University',
width: 300,
@@ -132,20 +148,11 @@ const example = [
y: 2000,
},
{
- doc_type: 'simulation',
- title: 'Physics simulation',
- data: '',
- width: 300,
- height: 300,
- x: 100,
- y: 100,
- },
- {
- doc_type: 'comparison',
+ doc_type: supportedDocumentTypes.comparison,
title: 'WWI vs. WWII',
data: [
{
- doc_type: 'text',
+ doc_type: supportedDocumentTypes.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,
@@ -154,7 +161,7 @@ const example = [
y: 100,
},
{
- doc_type: 'text',
+ doc_type: supportedDocumentTypes.text,
title: 'WWII',
data: 'A devastating global conflict spanning from 1939 to 1945, saw the Allied powers fight against the Axis powers.',
width: 300,
@@ -169,22 +176,22 @@ const example = [
y: 100,
},
{
- doc_type: 'collection',
+ doc_type: supportedDocumentTypes.collection,
title: 'Science Collection',
data: [
{
- doc_type: 'flashcard',
+ doc_type: supportedDocumentTypes.flashcard,
title: 'Photosynthesis',
data: [
{
- doc_type: 'text',
+ doc_type: supportedDocumentTypes.text,
title: 'front_Photosynthesis',
data: 'What is photosynthesis?',
width: 300,
height: 300,
},
{
- doc_type: 'text',
+ doc_type: supportedDocumentTypes.text,
title: 'back_photosynthesis',
data: 'The process by which plants make food.',
width: 300,
@@ -196,7 +203,7 @@ const example = [
height: 300,
},
{
- doc_type: 'web',
+ doc_type: supportedDocumentTypes.web,
title: 'Brown University Wikipedia',
data: 'https://en.wikipedia.org/wiki/Brown_University',
width: 300,
@@ -205,7 +212,7 @@ const example = [
y: 1100,
},
{
- doc_type: 'text',
+ doc_type: supportedDocumentTypes.text,
title: 'Water Cycle',
data: 'The continuous movement of water on, above, and below the Earth’s surface.',
width: 300,
@@ -214,7 +221,7 @@ const example = [
y: 500,
},
{
- doc_type: 'collection',
+ doc_type: supportedDocumentTypes.collection,
title: 'Advanced Biology',
data: [
{
@@ -245,28 +252,37 @@ const example = [
const finalJsonString = JSON.stringify(example);
// Instructions for creating various document types
-const docInstructions = {
- collection: {
- description:
- 'A recursive collection of documents as a stringified array. Each document can be a "text", "deck", "flashcard", "image", "web", "image", "comparison", "equation", "noteboard", "simulation", "diagram", "map", "screengrab", "webcam", "button", or another "collection".',
- example: finalJsonString,
- },
- 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.',
- 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',
- simulation: 'Create a simulation document',
- audio: 'A url to an audio recording. Example: ',
-} as const;
+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;
// Parameters for creating individual documents
const createDocToolParams = [
{
name: 'data',
type: 'string', // Accepts either string or array, supporting individual and nested data
- description: docInstructions,
+ description:
+ typeof docInstructions === 'string'
+ ? docInstructions
+ : docInstructions.reduce(
+ (prev, [type, data]) => {
+ prev[type] = data;
+ return prev;
+ },
+ {} as { [key: string]: string | { description: string; example: string } }
+ ),
required: true,
},
{
@@ -331,7 +347,7 @@ 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", "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", "comparison", "web", or "collection" (for nested documents). ' +
'Use this structure for nesting collections within collections. Each document should follow the structure in ' +
createDocToolParams +
'. Example: ' +
@@ -349,13 +365,28 @@ export class CreateDocTool extends BaseTool<CreateListDocToolParamsType> {
constructor(addLinkedDoc: (doc_type: supportedDocumentTypes, data: unknown, 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 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.',
+ `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. ' +
- '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.'
+ `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.
+ 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.`
);
this._addLinkedDoc = addLinkedDoc;
}
@@ -363,9 +394,7 @@ export class CreateDocTool extends BaseTool<CreateListDocToolParamsType> {
// Executes the tool logic for creating documents
async execute(args: ParametersType<CreateListDocToolParamsType>): Promise<Observation[]> {
try {
- console.log('EXE' + args.docs);
const parsedDoc = JSON.parse(args.docs) as ({ doc_type: supportedDocumentTypes; data: unknown } & DocumentOptions)[];
- console.log('parsed' + parsedDoc);
parsedDoc.forEach(doc =>
this._addLinkedDoc(
doc.doc_type,
diff --git a/src/server/ApiManagers/AssistantManager.ts b/src/server/ApiManagers/AssistantManager.ts
index 4d2068014..b53581aa2 100644
--- a/src/server/ApiManagers/AssistantManager.ts
+++ b/src/server/ApiManagers/AssistantManager.ts
@@ -23,7 +23,6 @@ import { AI_Document } from '../../client/views/nodes/chatbot/types/types';
import { Method } from '../RouteManager';
import { filesDirectory, publicDirectory } from '../SocketData';
import ApiManager, { Registration } from './ApiManager';
-import { getServerPath } from '../../client/util/reportManager/reportManagerUtils';
// Enumeration of directories where different file types are stored
export enum Directory {
@@ -157,7 +156,7 @@ export default class AssistantManager extends ApiManager {
try {
// Fetch initial search results
let response = await fetchSearchResults(startIndex);
- let initialResults =
+ const initialResults =
response.data.items?.map(item => ({
url: item.link,
snippet: item.snippet,
@@ -531,7 +530,7 @@ function spawnPythonProcess(jobId: string, file_name: string, file_data: string)
try {
const errorOutput = JSON.parse(lastLine);
jobResults[jobId] = errorOutput;
- } catch (err) {
+ } catch {
jobResults[jobId] = { error: 'Python process failed' };
}
} else {
diff --git a/src/server/server_Initialization.ts b/src/server/server_Initialization.ts
index 12c5319b7..a56ab5d18 100644
--- a/src/server/server_Initialization.ts
+++ b/src/server/server_Initialization.ts
@@ -115,7 +115,7 @@ function registerEmbeddedBrowseRelativePathHandler(server: express.Express) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function proxyServe(req: any, requrl: string, response: any) {
- // eslint-disable-next-line global-require, @typescript-eslint/no-require-imports
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
const htmlBodyMemoryStream = new (require('memorystream'))();
let wasinBrFormat = false;
const sendModifiedBody = () => {