aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/chatbot/agentsystem/Agent.ts5
-rw-r--r--src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx101
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts115
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts61
-rw-r--r--src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts2
5 files changed, 219 insertions, 65 deletions
diff --git a/src/client/views/nodes/chatbot/agentsystem/Agent.ts b/src/client/views/nodes/chatbot/agentsystem/Agent.ts
index 9253175d5..23e7d4a9d 100644
--- a/src/client/views/nodes/chatbot/agentsystem/Agent.ts
+++ b/src/client/views/nodes/chatbot/agentsystem/Agent.ts
@@ -16,7 +16,7 @@ import { Vectorstore } from '../vectorstore/Vectorstore';
import { getReactPrompt } from './prompts';
import { BaseTool } from '../tools/BaseTool';
import { Parameter, ParametersType } from '../types/tool_types';
-import { CreateTextDocTool } from '../tools/CreateTextDocumentTool';
+import { CreateDocTool } from '../tools/CreateDocumentTool';
import { DocumentOptions } from '../../../../documents/Documents';
dotenv.config();
@@ -75,7 +75,7 @@ export class Agent {
searchTool: new SearchTool(addLinkedUrlDoc),
createCSV: new CreateCSVTool(createCSVInDash),
noTool: new NoTool(),
- createTextDoc: new CreateTextDocTool(addLinkedDoc),
+ createDoc: new CreateDocTool(addLinkedDoc),
};
}
@@ -168,6 +168,7 @@ export class Agent {
} else if (key === 'action_input') {
// Handle action input stage
const actionInput = stage[key];
+ console.log(`Action input full:`, actionInput);
console.log(`Action input:`, actionInput.inputs);
if (currentAction) {
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
index 98f242ebf..14fdd9b8d 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -418,16 +418,88 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
* @param options Other optional document options (e.g. color)
* @param id The unique ID for the document.
*/
+
+ // @action
+ // createDocInDash = async (docs: string[]) => {
+ // console.log('DOCS HERE' + docs);
+ // docs.forEach(doc => {
+ // const parsedDoc = JSON.parse(doc);
+ // this.createIndivDocInDash(parsedDoc.doc_type, parsedDoc.data, parsedDoc.options, '');
+ // });
+ // };
+
@action
createDocInDash = async (doc_type: string, data: string, options: DocumentOptions, id: string) => {
+ console.log('INDIV DOC' + doc_type);
let doc;
switch (doc_type) {
case 'text':
doc = DocCast(Docs.Create.TextDocument(data, options));
+ break;
+ case 'flashcard':
+ doc = this.createFlashcard(data, options);
+ break;
+ case 'image':
+ doc = DocCast(Docs.Create.ImageDocument(data, options));
+ break;
+ case 'equation':
+ doc = DocCast(Docs.Create.EquationDocument('', options));
+ break;
+ case 'noteboard':
+ doc = DocCast(Docs.Create.NoteTakingDocument([], options));
+ break;
+ case 'simulation':
+ doc = DocCast(Docs.Create.SimulationDocument(options));
+ break;
+ case 'collection':
+ doc = DocCast(Docs.Create.FreeformDocument([], options));
+ break;
+ case 'web':
+ doc = DocCast(Docs.Create.WebDocument(data, options));
+ break;
+ case 'comparison':
+ doc = Docs.Create.ComparisonDocument('', options);
+ break;
+ case 'diagram':
+ doc = Docs.Create.DiagramDocument(options);
+ break;
+ case 'audio':
+ doc = Docs.Create.AudioDocument(data, options);
+ break;
+ case 'map':
+ doc = Docs.Create.MapDocument([], options);
+ break;
+ case 'screengrab':
+ doc = Docs.Create.ScreenshotDocument(options);
+ break;
+ case 'webcam':
+ doc = Docs.Create.WebCamDocument('', options);
+ break;
+ case 'button':
+ doc = Docs.Create.ButtonDocument(options);
+ break;
+ case 'script':
+ doc = Docs.Create.ScriptingDocument(null, options);
+ break;
+ case 'dataviz':
+ doc = Docs.Create.DataVizDocument('/users/rz/Downloads/addresses.csv', options);
+ break;
+ case 'chat':
+ doc = Docs.Create.ChatDocument(options);
+ break;
+ case 'trail':
+ doc = Docs.Create.PresDocument(options);
+ break;
+ case 'tab':
+ doc = Docs.Create.FreeformDocument([], options);
+ break;
+ case 'slide':
+ doc = Docs.Create.TreeDocument([], options);
+ break;
default:
doc = DocCast(Docs.Create.TextDocument(data, options));
}
-
+ console.log('DOC' + doc_type);
const linkDoc = Docs.Create.LinkDocument(this.Document, doc);
LinkManager.Instance.addLink(linkDoc);
@@ -435,6 +507,33 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
await DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {});
};
+ // TODO: DELEGATE TO DIFFERENT CLASS
+ @action
+ createFlashcard = (data: string, 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);
+ });
+ const col = DocCast(
+ Docs.Create.CarouselDocument(flashcardDeck, {
+ title: options.title,
+ _width: 300,
+ _height: 300,
+ _layout_fitWidth: false,
+ _layout_autoHeight: true,
+ })
+ );
+ return col;
+ };
+
/**
* Event handler to manage citations click in the message components.
* @param citation The citation object clicked by the user.
diff --git a/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
new file mode 100644
index 000000000..992935b77
--- /dev/null
+++ b/src/client/views/nodes/chatbot/tools/CreateDocumentTool.ts
@@ -0,0 +1,115 @@
+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 { RTFCast, StrCast } from '../../../../../fields/Types';
+
+const docInstructions = {
+ text: 'Provide text content as string, not dictionary',
+ flashcard: 'A string dictionary mapping front to back of flashcard that the document will display. Follow this example: data: {"What is photosynthesis?":"The process by which g…t and absorb water and nutrients from the soil."}',
+ image: 'Provide a real image url',
+ web: 'Only provide real url to be displayed, not text content',
+} as const;
+
+// have recursive structure
+// get array of all documents that each have their options
+// (if its a collection)
+
+const createDocToolParams = [
+ {
+ name: 'data',
+ type: 'string',
+ description: docInstructions,
+ required: true,
+ },
+ {
+ name: 'doc_type',
+ type: 'string',
+ description: 'The type of the document',
+ required: true,
+ },
+ {
+ name: 'title',
+ type: 'string',
+ description: 'The title of the document',
+ required: true,
+ },
+ {
+ name: 'background_color',
+ type: 'string',
+ description: 'The background color of the document as a hex string',
+ required: false,
+ },
+ {
+ name: 'font_color',
+ type: 'string',
+ description: 'The font color of the document as a hex string',
+ required: false,
+ },
+ {
+ name: 'width',
+ type: 'number',
+ description: 'The height of the document as a number',
+ required: true,
+ },
+ {
+ name: 'height',
+ type: 'number',
+ description: 'The height of the document as a number',
+ required: true,
+ },
+] as const;
+
+const createListDocToolParams = [
+ {
+ name: 'docs',
+ type: 'string', // array of stringified documents
+ description:
+ 'docs is an array that contains stringified JSON objects representing different document types. Each item in the array is a stringified version of this: ' +
+ createDocToolParams +
+ 'Each document should be individually serialized (using JSON.stringify or equivalent) so that it fits within string[]. An example is ["{"data":"Plants are living organisms that belong to the kingdom Plantae.","doc_type":"text","title":"Introduction to Plants","width":300,"height":300}", "{"data":"Photosynthesis is the process by which plants make food.","type":"text","title":"Photosynthesis","width":300,"height":300}"]',
+ required: true,
+ },
+] as const;
+
+type CreateListDocToolParamsType = typeof createListDocToolParams;
+// type CreateDocToolParamsType = typeof createDocToolParams;
+
+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 users request',
+ createListDocToolParams,
+ 'Modify the data parameter and include title (and optionally color) for the document.',
+ '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.'
+ );
+ this._addLinkedDoc = addLinkedDoc;
+ }
+
+ async execute(args: ParametersType<CreateListDocToolParamsType>): Promise<Observation[]> {
+ try {
+ console.log('EXE' + args.docs);
+ const parsedDoc = JSON.parse(args.docs);
+ console.log('parsed' + parsedDoc);
+ parsedDoc.forEach((firstDoc: string) => {
+ console.log('THIS DOC' + firstDoc);
+ console.log(typeof firstDoc);
+ const doc = JSON.parse(firstDoc);
+ console.log('NEW DOC' + doc);
+ console.log('TYPE' + doc['doc_type']);
+
+ this._addLinkedDoc(doc['doc_type'], doc['data'], { title: doc['title'], backgroundColor: doc['background_color'], text_fontColor: doc['font_color'] }, uuidv4());
+ });
+ // this._addLinkedDoc(args.doc_type, args.data, { title: args.title, backgroundColor: args.background_color, text_fontColor: args.font_color }, uuidv4());
+ return [{ type: 'text', text: 'Created document.' }];
+ } catch (error) {
+ return [{ type: 'text', text: 'Error creating text document, ' + error }];
+ }
+ }
+}
diff --git a/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts b/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts
deleted file mode 100644
index fae78aa49..000000000
--- a/src/client/views/nodes/chatbot/tools/CreateTextDocumentTool.ts
+++ /dev/null
@@ -1,61 +0,0 @@
-import { v4 as uuidv4 } from 'uuid';
-import { Networking } from '../../../../Network';
-import { BaseTool } from './BaseTool';
-import { Observation } from '../types/types';
-import { ParametersType } from '../types/tool_types';
-import { DocumentOptions } from '../../../../documents/Documents';
-import { RTFCast, StrCast } from '../../../../../fields/Types';
-
-const createTextDocToolParams = [
- {
- name: 'text_content',
- type: 'string',
- description: 'The text content that the document will display',
- required: true,
- },
- {
- name: 'title',
- type: 'string',
- description: 'The title of the document',
- required: true,
- },
- {
- name: 'background_color',
- type: 'string',
- description: 'The background color of the document as a hex string',
- required: false,
- },
- {
- name: 'font_color',
- type: 'string',
- description: 'The font color of the document as a hex string',
- required: false,
- },
-] as const;
-
-type CreateTextDocToolParamsType = typeof createTextDocToolParams;
-
-export class CreateTextDocTool extends BaseTool<CreateTextDocToolParamsType> {
- private _addLinkedDoc: (doc_type: string, data: string, options: DocumentOptions, id: string) => void;
-
- constructor(addLinkedDoc: (text_content: string, data: string, options: DocumentOptions, id: string) => void) {
- super(
- 'createTextDoc',
- 'Creates a text document with the provided content and title (and of specified other options if wanted)',
- createTextDocToolParams,
- 'Provide the text content and title (and optionally color) for the document.',
- 'Creates a text document with the provided content and title (and of specified other options if wanted). Use if the user wants to create a textbox or text document of some sort. Can use after a search or other tool to save information.'
- );
- this._addLinkedDoc = addLinkedDoc;
- }
-
- async execute(args: ParametersType<CreateTextDocToolParamsType>): Promise<Observation[]> {
- try {
- console.log(RTFCast(args.text_content));
- this._addLinkedDoc('text', args.text_content, { title: args.title, backgroundColor: args.background_color, text_fontColor: args.font_color }, uuidv4());
- return [{ type: 'text', text: 'Created text document.' }];
- } catch (error) {
- return [{ type: 'text', text: 'Error creating text document, ' + error }];
- }
- }
-}
diff --git a/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts b/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
index f96f55997..5ed784559 100644
--- a/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
+++ b/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
@@ -37,7 +37,7 @@ export class Vectorstore {
* @param doc_ids A function that returns a list of document IDs.
*/
constructor(id: string, doc_ids: () => string[]) {
- const pineconeApiKey = process.env.PINECONE_API_KEY;
+ const pineconeApiKey = '51738e9a-bea2-4c11-b6bf-48a825e774dc';
if (!pineconeApiKey) {
throw new Error('PINECONE_API_KEY is not defined.');
}