aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/ChatBox/ChatBox.tsx11
-rw-r--r--src/server/ApiManagers/AssistantManager.ts14
2 files changed, 18 insertions, 7 deletions
diff --git a/src/client/views/nodes/ChatBox/ChatBox.tsx b/src/client/views/nodes/ChatBox/ChatBox.tsx
index 9f4e6f07e..2283aad56 100644
--- a/src/client/views/nodes/ChatBox/ChatBox.tsx
+++ b/src/client/views/nodes/ChatBox/ChatBox.tsx
@@ -53,7 +53,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
this.openai = this.initializeOpenAI();
this.history = [{ role: ASSISTANT_ROLE.ASSISTANT, text: 'Welcome to the Document Analyser Assistant! Link a document or ask questions to get started.' }];
this.openai = this.initializeOpenAI();
- this.getLinkedDocs();
+ this.getOtherDocs();
this.vectorstore = new Vectorstore();
reaction(
@@ -64,13 +64,12 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
);
}
- getLinkedDocs = async () => {
- const visual_docs = (CollectionFreeFormDocumentView.from(this._props.DocumentView?.())?._props.parent as CollectionFreeFormView)?.childDocs.filter(doc => doc != this.Document);
- console.log('All Docs:', visual_docs);
+ getOtherDocs = async () => {
+ const visible_docs = (CollectionFreeFormDocumentView.from(this._props.DocumentView?.())?._props.parent as CollectionFreeFormView)?.childDocs.filter(doc => doc != this.Document);
+ console.log('All Docs:', visible_docs);
- visual_docs?.forEach(async doc => {
+ visible_docs?.forEach(async doc => {
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);
diff --git a/src/server/ApiManagers/AssistantManager.ts b/src/server/ApiManagers/AssistantManager.ts
index a35708ccd..8a5f12c2b 100644
--- a/src/server/ApiManagers/AssistantManager.ts
+++ b/src/server/ApiManagers/AssistantManager.ts
@@ -173,7 +173,19 @@ export default class AssistantManager extends ApiManager {
}
);
- res.send({ document: response.data });
+ const jobId = response.data.job_id;
+
+ // Poll for results
+ let result;
+ while (!result) {
+ await new Promise(resolve => setTimeout(resolve, 5000)); // Wait for 1 second
+ const resultResponse = await axios.get(`http://localhost:8080/getResult/${jobId}`);
+ if (resultResponse.status === 200) {
+ result = resultResponse.data;
+ }
+ }
+
+ res.send({ document_json: result });
} catch (error: any) {
console.error('Error communicating with chatbot:', error);
res.status(500).send({ error: 'Failed to communicate with the chatbot', details: error.message });