aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/views/nodes/chatbot/agentsystem/Agent.ts4
-rw-r--r--src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx89
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts82
-rw-r--r--src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts2
4 files changed, 150 insertions, 27 deletions
diff --git a/src/client/views/nodes/chatbot/agentsystem/Agent.ts b/src/client/views/nodes/chatbot/agentsystem/Agent.ts
index 05d13d1db..0b0e211eb 100644
--- a/src/client/views/nodes/chatbot/agentsystem/Agent.ts
+++ b/src/client/views/nodes/chatbot/agentsystem/Agent.ts
@@ -69,9 +69,9 @@ export class Agent {
// Define available tools for the assistant
this.tools = {
calculate: new CalculateTool(),
- rag: new RAGTool(this.vectorstore),
+ // rag: new RAGTool(this.vectorstore),
dataAnalysis: new DataAnalysisTool(csvData),
- websiteInfoScraper: new WebsiteInfoScraperTool(addLinkedUrlDoc),
+ // websiteInfoScraper: new WebsiteInfoScraperTool(addLinkedUrlDoc),
searchTool: new SearchTool(addLinkedUrlDoc),
createCSV: new CreateCSVTool(createCSVInDash),
noTool: new NoTool(),
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
index 68d4383e7..95f3fbc5d 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -463,9 +463,11 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
doc = DocCast(Docs.Create.TextDocument(data, options));
break;
case 'flashcard':
- // doc = this.createSingleFlashcard(data, options);
doc = this.createFlashcard(data, options);
break;
+ case 'deck':
+ doc = this.createDeck(data, options);
+ break;
case 'image':
doc = DocCast(Docs.Create.ImageDocument(data, options));
break;
@@ -551,31 +553,82 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
await DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {});
};
- // TODO: DELEGATE TO DIFFERENT CLASS
@action
- createFlashcard = (data: string, options: DocumentOptions) => {
+ createDeck = (data: any, options: DocumentOptions) => {
const flashcardDeck: Doc[] = [];
- const parsedItems: { [key: string]: string } = JSON.parse(data);
- Object.entries(parsedItems).forEach(([key, val]) => {
- console.log('key' + key);
- console.log('key' + val);
-
- const side1 = Docs.Create.CenteredTextCreator('question', key, options);
- const side2 = Docs.Create.CenteredTextCreator('answer', val, options);
- const doc = DocCast(Docs.Create.FlashcardDocument(data, side1, side2, { _width: 300, _height: 300 }));
- this._props.addDocument?.(doc);
- flashcardDeck.push(doc);
+
+ // Parse `data` only if it’s a string
+ const deckData = typeof data === 'string' ? JSON.parse(data) : data;
+ console.log('Parsed Deck Data:', deckData);
+ const flashcardArray = Array.isArray(deckData) ? deckData : Object.values(deckData);
+ console.log(typeof flashcardArray);
+ // Process each flashcard document in the `deckData` array
+ flashcardArray.forEach(doc => {
+ const flashcardDoc = this.createFlashcard(doc, options);
+ if (flashcardDoc) flashcardDeck.push(flashcardDoc);
});
- const col = DocCast(
+
+ // Create a carousel to contain the flashcard deck
+ const carouselDoc = DocCast(
Docs.Create.CarouselDocument(flashcardDeck, {
- title: options.title,
- _width: 300,
- _height: 300,
+ title: options.title || 'Flashcard Deck',
+ _width: options._width || 300,
+ _height: options._height || 300,
_layout_fitWidth: false,
_layout_autoHeight: true,
})
);
- return col;
+
+ return carouselDoc;
+ };
+ @action
+ createFlashcard = (data: any, options: any) => {
+ // const flashcardDeck: Doc[] = [];
+
+ // Process each flashcard item in the data array
+ // const p = JSON.parse(data);
+ const deckData = typeof data === 'string' ? JSON.parse(data) : data;
+ const flashcardArray = Array.isArray(deckData) ? deckData : Object.values(deckData)[2];
+ console.log(typeof flashcardArray);
+
+ const [front, back] = flashcardArray;
+
+ // Check that both front and back are text documents
+ console.log('DATA' + data);
+ console.log('front' + front);
+ console.log('back' + back);
+ console.log(front.doc_type);
+ console.log(back.doc_type);
+ if (front.doc_type === 'text' && back.doc_type === 'text') {
+ const sideOptions: DocumentOptions = {
+ backgroundColor: options.backgroundColor,
+ _width: options._width,
+ _height: options._height,
+ };
+
+ // Create front and back text documents
+ const side1 = Docs.Create.CenteredTextCreator(front.title, front.data, sideOptions);
+ const side2 = Docs.Create.CenteredTextCreator(back.title, back.data, sideOptions);
+
+ // Create the flashcard document with both sides
+ const flashcardDoc = DocCast(Docs.Create.FlashcardDocument(data.title, side1, side2, sideOptions));
+ return flashcardDoc;
+ // this._props.addDocument?.(flashcardDoc);
+ // flashcardDeck.push(flashcardDoc);
+ }
+
+ // Create a carousel to contain the flashcard deck
+ // const carouselDoc = DocCast(
+ // Docs.Create.CarouselDocument(flashcardDeck, {
+ // title: options.title || data.title,
+ // _width: data.width || 300,
+ // _height: data.height || 300,
+ // _layout_fitWidth: false,
+ // _layout_autoHeight: true,
+ // })
+ // );
+
+ // return carouselDoc;
};
/**
diff --git a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
index b14a57779..ebe0448aa 100644
--- a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
+++ b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
@@ -6,16 +6,85 @@ import { DocumentOptions } from '../../../../documents/Documents';
const example = [
{
+ doc_type: 'deck',
+ title: 'Chemistry',
+ data: [
+ {
+ doc_type: 'flashcard',
+ title: 'Photosynthesis',
+ data: [
+ {
+ doc_type: 'text',
+ title: 'front_Photosynthesis',
+ data: 'What is photosynthesis?',
+ width: 300,
+ height: 300,
+ },
+ {
+ doc_type: 'text',
+ title: 'back_photosynthesis',
+ data: 'The process by which plants make food.',
+ width: 300,
+ height: 300,
+ },
+ ],
+ backgroundColor: '#00ff00',
+ width: 300,
+ height: 300,
+ },
+ {
+ doc_type: 'flashcard',
+ title: 'Photosynthesis',
+ data: [
+ {
+ doc_type: 'text',
+ title: 'front_Photosynthesis',
+ data: 'What is photosynthesis?',
+ width: 300,
+ height: 300,
+ },
+ {
+ doc_type: 'text',
+ title: 'back_photosynthesis',
+ data: 'The process by which plants make food.',
+ width: 300,
+ height: 300,
+ },
+ ],
+ backgroundColor: '#00ff00',
+ width: 300,
+ height: 300,
+ },
+ ],
+ backgroundColor: '#00ff00',
+ width: 600,
+ height: 600,
+ },
+ {
+ doc_type: 'web',
+ title: 'Brown University Wikipedia',
+ data: 'https://en.wikipedia.org/wiki/Brown_University',
+ width: 300,
+ height: 300,
+ },
+ {
doc_type: 'collection',
title: 'Science Collection',
data: [
{
+ doc_type: 'web',
+ title: 'Brown University Wikipedia',
+ data: 'https://en.wikipedia.org/wiki/Brown_University',
+ width: 300,
+ height: 300,
+ },
+ {
doc_type: 'flashcard',
title: 'Photosynthesis',
data: [
{
doc_type: 'text',
- title: 'Front Photosynthesis',
+ title: 'front_Photosynthesis',
data: 'What is photosynthesis?',
width: 300,
height: 300,
@@ -72,9 +141,9 @@ 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.',
- flashcardDeck: 'A collection of flashcards under a common theme.',
+ 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://example.com"',
+ web: 'A URL to a webpage. Example: https://en.wikipedia.org/wiki/Brown_University',
equation: 'Create a equation document.',
noteboard: 'Create a noteboard document',
comparison: 'Create a comparison document',
@@ -148,12 +217,13 @@ export class CreateDocTool extends BaseTool<CreateListDocToolParamsType> {
constructor(addLinkedDoc: (doc_type: string, data: string, options: DocumentOptions, id: string) => void) {
super(
'createDoc',
- 'Creates one or more documents that best fit users request',
+ 'Creates one or more documents that best fit users request with input following the example below. Or creates a dashboard of many documents/collections.',
createListDocToolParams,
- 'Modify the data parameter and include title (and optionally color) for the document.',
+ '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 a search or other tool to save information.'
+ '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;
}
diff --git a/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts b/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
index 5ed784559..cf7fa0ff3 100644
--- a/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
+++ b/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
@@ -44,7 +44,7 @@ export class Vectorstore {
// Initialize Pinecone and Cohere clients with API keys from the environment.
this.pinecone = new Pinecone({ apiKey: pineconeApiKey });
- this.cohere = new CohereClient({ token: process.env.COHERE_API_KEY });
+ // this.cohere = new CohereClient({ token: process.env.COHERE_API_KEY });
this._id = id;
this._doc_ids = doc_ids();
this.initializeIndex();