diff options
author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-07-11 12:06:04 -0400 |
---|---|---|
committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-07-11 12:06:04 -0400 |
commit | f1cdfc1d02488c4a513fbf67f729f702526a345d (patch) | |
tree | 1f1145e4ecc7d00c77c66198003318f0fcc568b3 /src/client/views/nodes/ChatBox/ChatBox.tsx | |
parent | e0e4871224e626240dc899c653cd0eb9f54c3693 (diff) |
not working well (files don't get filename immediately_
Diffstat (limited to 'src/client/views/nodes/ChatBox/ChatBox.tsx')
-rw-r--r-- | src/client/views/nodes/ChatBox/ChatBox.tsx | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/src/client/views/nodes/ChatBox/ChatBox.tsx b/src/client/views/nodes/ChatBox/ChatBox.tsx index 64ab2888b..9b2a92564 100644 --- a/src/client/views/nodes/ChatBox/ChatBox.tsx +++ b/src/client/views/nodes/ChatBox/ChatBox.tsx @@ -11,7 +11,7 @@ import { LinkManager } from '../../../util/LinkManager'; import { ViewBoxAnnotatableComponent } from '../../DocComponent'; import { FieldView, FieldViewProps } from '../FieldView'; import './ChatBox.scss'; -import MessageComponent from './MessageComponent'; +import MessageComponentBox from './MessageComponent'; import { ASSISTANT_ROLE, AssistantMessage, AI_Document, convertToAIDocument, Citation } from './types'; import { Vectorstore } from './vectorstore/VectorstoreUpload'; import { CollectionFreeFormDocumentView } from '../CollectionFreeFormDocumentView'; @@ -19,6 +19,7 @@ import { CollectionFreeFormView } from '../../collections/collectionFreeForm'; import { Agent } from './Agent'; import dotenv from 'dotenv'; import { DocData } from '../../../../fields/DocSymbols'; +import { DocumentView } from '../DocumentView'; dotenv.config(); @observer @@ -33,7 +34,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { @observable inputValue: string = ''; @observable private _visibleDocs: Doc[] = []; private openai: OpenAI; - private vectorstore_id: string; + // private vectorstore_id: string; private documents: AI_Document[] = []; private _oldWheel: any; private vectorstore: Vectorstore; @@ -61,22 +62,8 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { } @action - addAIDocs = async (visible_docs: Doc[]) => { - console.log('All Docs:', visible_docs); - visible_docs?.forEach(async doc => { - if (doc[DocData].ai_document) { - this.documents.push(convertToAIDocument(JSON.parse(StrCast(doc[DocData].ai_document)))); - } else { - const local_file_path: string = CsvCast(doc.data, PDFCast(doc.data))?.url?.pathname; - if (local_file_path) { - const { document_json } = await Networking.PostToServer('/createDocument', { file_path: local_file_path }); - const ai_document: AI_Document = convertToAIDocument(document_json); - this.documents.push(ai_document); - await this.vectorstore.addDocument(ai_document); - doc[DocData].ai_document = JSON.stringify(document_json); - } - } - }); + addDocsToVectorstore = async (visible_docs: Doc[]) => { + await this.vectorstore.addAIDocs(visible_docs); this.isInitializing = false; }; @@ -107,6 +94,10 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { } }; + // getAssistantResponse() { + // return Docs.Create.MessageDocument(text, {}); + // } + @action askGPT = async (event: React.FormEvent<HTMLFormElement>): Promise<void> => { event.preventDefault(); @@ -241,7 +232,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { reaction( () => this.visibleDocs, visibleDocs => { - this._visibleDocs = visibleDocs; + this._visibleDocs.push(...visibleDocs.filter(visibleDoc => !this._visibleDocs.includes(visibleDoc))); } ); observe( @@ -255,7 +246,7 @@ 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[]); - this.addAIDocs((change as any).added as Doc[]); + this.addDocsToVectorstore((change as any).added as Doc[]); } // (change as any).removed.forEach((link: any) => remLinkFromDoc(toRealField(link))); break; @@ -295,10 +286,11 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { }}> <div className="messages"> {this.history.map((message, index) => ( - <MessageComponent key={index} message={message} index={index} onFollowUpClick={this.handleFollowUpClick} onCitationClick={this.handleCitationClick} updateMessageCitations={this.updateMessageCitations} /> + //<DocumentView key={index} Document={message} index={index} onFollowUpClick={this.handleFollowUpClick} onCitationClick={this.handleCitationClick} updateMessageCitations={this.updateMessageCitations} /> + <MessageComponentBox key={index} message={message} index={index} onFollowUpClick={this.handleFollowUpClick} onCitationClick={this.handleCitationClick} updateMessageCitations={this.updateMessageCitations} /> ))} {this.current_message && ( - <MessageComponent + <MessageComponentBox key={this.history.length} message={this.current_message} index={this.history.length} |