diff options
-rw-r--r-- | src/client/views/nodes/ChatBox/ChatBox.tsx | 25 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts | 8 |
2 files changed, 19 insertions, 14 deletions
diff --git a/src/client/views/nodes/ChatBox/ChatBox.tsx b/src/client/views/nodes/ChatBox/ChatBox.tsx index 4d7381a57..4d1cd38a0 100644 --- a/src/client/views/nodes/ChatBox/ChatBox.tsx +++ b/src/client/views/nodes/ChatBox/ChatBox.tsx @@ -37,7 +37,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { @observable isInitializing: boolean = true; @observable expandedScratchpadIndex: number | null = null; @observable inputValue: string = ''; - @observable private currently_linked: Doc[] = []; + @observable private linked_docs_to_add: Doc[] = []; private openai: OpenAI; private vectorstore_id: string; private documents: AI_Document[] = []; @@ -158,7 +158,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { console.log('URL: ' + doc_url + ' Citation URL: ' + chunk_file_name); //const ai_field_id = doc[this.Document[Id] + '_ai_field_id']; if (chunk_file_name == doc_url) { - DocumentManager.Instance.showDocument(doc, {}, () => { + DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => { console.log(doc.data); //look at context path for each docview and choose the doc view that has as //its parent the same collection view the chatbox is in @@ -208,7 +208,6 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { componentDidMount() { this._props.setContentViewBox?.(this); - this.currently_linked = this.linkedDocs; if (this.dataDoc.data) { try { const storedHistory = JSON.parse(StrCast(this.dataDoc.data)); @@ -227,15 +226,21 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { } } reaction( - () => this.linkedDocs, - linkedDocs => { - this.currently_linked.push(...linkedDocs.filter(linkedDoc => !this.currently_linked.includes(linkedDoc))); - } + () => { + const linkedDocs = LinkManager.Instance.getAllRelatedLinks(this.Document) + .map(d => DocCast(LinkManager.getOppositeAnchor(d, this.Document))) + .map(d => DocCast(d?.annotationOn, d)) + .filter(d => d); + return linkedDocs; + }, + + linked => this.linked_docs_to_add.push(...linked.filter(linkedDoc => !this.linked_docs_to_add.includes(linkedDoc))) ); + observe( // right now this skips during initialization which is necessary because it would be blank // However, it will upload the same link twice when it is - this.currently_linked, + this.linked_docs_to_add, change => { // observe pushes/splices on a user link DB 'data' field (should only happen for local changes) switch (change.type as any) { @@ -243,7 +248,6 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { if ((change as any).addedCount > 0) { // maybe check here if its already in the urls datadoc array so doesn't add twice console.log((change as any).added as Doc[]); - console.log('here!'); this.addDocsToVectorstore((change as any).added as Doc[]); } // (change as any).removed.forEach((link: any) => remLinkFromDoc(toRealField(link))); @@ -254,9 +258,6 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { }, true ); - if (this.isInitializing) { - this.isInitializing = false; - } } @computed diff --git a/src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts b/src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts index 3a889bff2..64b89225c 100644 --- a/src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts +++ b/src/client/views/nodes/ChatBox/vectorstore/VectorstoreUpload.ts @@ -64,8 +64,12 @@ export class Vectorstore { } async addAIDoc(doc: Doc) { - if (doc.ai_document) { - if (doc.ai_document === 'IN PROGRESS') { + console.log('Adding AI Document:', doc); + console.log('AI Document1:', doc[DocData].ai_document); + console.log('AI Document2:', doc.ai_document); + const ai_document_string: string = StrCast(doc.ai_document); + if (ai_document_string !== undefined && ai_document_string !== null && ai_document_string !== '' && ai_document_string !== ' ' && ai_document_string !== '{}') { + if (ai_document_string === 'IN PROGRESS') { console.log('Already in progress.'); return; } |