From 9be434cddc30baada63aff0c5dae6dbf606f2590 Mon Sep 17 00:00:00 2001
From: "A.J. Shulman" <Shulman.aj@gmail.com>
Date: Thu, 22 Aug 2024 15:32:18 -0400
Subject: adding csv

---
 src/client/views/nodes/ChatBox/ChatBox.tsx | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

(limited to 'src/client/views/nodes/ChatBox/ChatBox.tsx')

diff --git a/src/client/views/nodes/ChatBox/ChatBox.tsx b/src/client/views/nodes/ChatBox/ChatBox.tsx
index d79233fae..ffede6901 100644
--- a/src/client/views/nodes/ChatBox/ChatBox.tsx
+++ b/src/client/views/nodes/ChatBox/ChatBox.tsx
@@ -3,7 +3,7 @@ import { observer } from 'mobx-react';
 import OpenAI, { ClientOptions } from 'openai';
 import * as React from 'react';
 import { Doc, DocListCast } from '../../../../fields/Doc';
-import { CsvCast, DocCast, PDFCast, StrCast } from '../../../../fields/Types';
+import { CsvCast, DocCast, PDFCast, RTFCast, StrCast } from '../../../../fields/Types';
 import { DocumentType } from '../../../documents/DocumentTypes';
 import { Docs } from '../../../documents/Documents';
 import { LinkManager } from '../../../util/LinkManager';
@@ -60,7 +60,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
             this.vectorstore_id = StrCast(this.dataDoc.vectorstore_id);
         }
         this.vectorstore = new Vectorstore(this.vectorstore_id, this.retrieveDocIds);
-        this.agent = new Agent(this.vectorstore, this.retrieveSummaries, this.retrieveFormattedHistory, this.retrieveCSVData, this.addLinkedUrlDoc);
+        this.agent = new Agent(this.vectorstore, this.retrieveSummaries, this.retrieveFormattedHistory, this.retrieveCSVData, this.addLinkedUrlDoc, this.createCSVInDash);
         this.messagesRef = React.createRef<HTMLDivElement>();
 
         reaction(
@@ -77,7 +77,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
     };
 
     @action
-    addCSVForAnalysis = async (newLinkedDoc: Doc) => {
+    addCSVForAnalysis = async (newLinkedDoc: Doc, id?: string) => {
         console.log('adding csv file for analysis');
         if (!newLinkedDoc.chunk_simpl) {
             const csvData: string = StrCast(newLinkedDoc.text);
@@ -104,7 +104,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
                 model: 'gpt-3.5-turbo',
             });
             console.log('CSV Data:', csvData);
-            const csvId = uuidv4();
+            const csvId = id ?? uuidv4();
 
             this.linked_csv_files.push({
                 filename: CsvCast(newLinkedDoc.data).url.pathname,
@@ -239,6 +239,20 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
         return ClientUtils.CurrentUserEmail;
     }
 
+    @action
+    createCSVInDash = async (url: string, title: string, id: string, data: string) => {
+        console.log('Creating CSV in Dash:', url, title);
+        const doc = DocCast(await DocUtils.DocumentFromType('csv', url, { title: title, text: RTFCast(data) }));
+
+        const linkDoc = Docs.Create.LinkDocument(this.Document, doc);
+        LinkManager.Instance.addLink(linkDoc);
+
+        doc && this._props.addDocument?.(doc);
+        await DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {});
+
+        this.addCSVForAnalysis(doc, id);
+    };
+
     @action
     handleCitationClick = (citation: Citation) => {
         console.log('Citation clicked:', citation);
-- 
cgit v1.2.3-70-g09d2

