From 4791cd23af08da70895204a3a7fbaf889d9af2d5 Mon Sep 17 00:00:00 2001
From: "A.J. Shulman" <Shulman.aj@gmail.com>
Date: Sat, 7 Sep 2024 12:43:05 -0400
Subject: completely restructured, added comments, and significantly reduced
 the length of the prompt (~72% shorter and cheaper)

---
 .../chatbot/chatboxcomponents/ProgressBar.tsx      | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 src/client/views/nodes/chatbot/chatboxcomponents/ProgressBar.tsx

(limited to 'src/client/views/nodes/chatbot/chatboxcomponents/ProgressBar.tsx')

diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ProgressBar.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ProgressBar.tsx
new file mode 100644
index 000000000..b9fd08742
--- /dev/null
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ProgressBar.tsx
@@ -0,0 +1,22 @@
+import React from 'react';
+import './ProgressBar.scss';
+
+/**
+ * ProgressBar is a functional React component that displays a loading spinner
+ * to indicate progress or ongoing processing. It uses two bouncing elements
+ * to create a smooth animation that represents an active state.
+ *
+ * The animation consists of two divs (`double-bounce1` and `double-bounce2`),
+ * each of which will bounce in and out of view, creating a pulsating effect.
+ */
+export const ProgressBar: React.FC = () => {
+    return (
+        <div className="spinner-container">
+            {/* Spinner div containing two bouncing elements */}
+            <div className="spinner">
+                <div className="double-bounce1"></div> {/* First bouncing element */}
+                <div className="double-bounce2"></div> {/* Second bouncing element */}
+            </div>
+        </div>
+    );
+};
-- 
cgit v1.2.3-70-g09d2


From d347fc59feefd91a796012892da57511787bb6d0 Mon Sep 17 00:00:00 2001
From: "A.J. Shulman" <Shulman.aj@gmail.com>
Date: Thu, 10 Oct 2024 11:39:19 -0400
Subject: added new file header comments and fixed some error handling

---
 .../views/nodes/chatbot/agentsystem/prompts.ts     |  9 ++++++++-
 .../nodes/chatbot/chatboxcomponents/ChatBox.tsx    |  9 +++++++++
 .../chatbot/chatboxcomponents/MessageComponent.tsx |  9 +++++++++
 .../chatbot/chatboxcomponents/ProgressBar.tsx      |  8 ++++++++
 .../nodes/chatbot/response_parsers/AnswerParser.ts |  8 ++++++++
 .../response_parsers/StreamedAnswerParser.ts       |  8 ++++++++
 src/client/views/nodes/chatbot/tools/BaseTool.ts   |  8 ++++++++
 .../views/nodes/chatbot/vectorstore/Vectorstore.ts | 10 +++++++++-
 src/server/ApiManagers/AssistantManager.ts         | 22 ++++++++++------------
 9 files changed, 77 insertions(+), 14 deletions(-)

(limited to 'src/client/views/nodes/chatbot/chatboxcomponents/ProgressBar.tsx')

diff --git a/src/client/views/nodes/chatbot/agentsystem/prompts.ts b/src/client/views/nodes/chatbot/agentsystem/prompts.ts
index 01c30d444..f5aec3130 100644
--- a/src/client/views/nodes/chatbot/agentsystem/prompts.ts
+++ b/src/client/views/nodes/chatbot/agentsystem/prompts.ts
@@ -1,4 +1,11 @@
-// prompts.ts
+/**
+ * @file prompts.ts
+ * @description This file contains functions that generate prompts for various AI tasks, including
+ * generating system messages for structured AI assistant interactions and summarizing document chunks.
+ * It defines prompt structures to ensure the AI follows specific guidelines for response formatting,
+ * tool usage, and citation rules, with a rigid structure in mind for tasks such as answering user queries
+ * and summarizing content from provided text chunks.
+ */
 
 import { Tool } from '../types/types';
 
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
index 613cb7078..44c231c87 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -1,3 +1,12 @@
+/**
+ * @file ChatBox.tsx
+ * @description This file defines the ChatBox component, which manages user interactions with
+ * an AI assistant. It handles document uploads, chat history, message input, and integration
+ * with the OpenAI API. The ChatBox is MobX-observable and tracks the progress of tasks such as
+ * document analysis and AI-driven summaries. It also maintains real-time chat functionality
+ * with support for follow-up questions and citation management.
+ */
+
 import dotenv from 'dotenv';
 import { ObservableSet, action, computed, makeObservable, observable, observe, reaction, runInAction } from 'mobx';
 import { observer } from 'mobx-react';
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/MessageComponent.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/MessageComponent.tsx
index 801becb64..d48f46963 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/MessageComponent.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/MessageComponent.tsx
@@ -1,3 +1,12 @@
+/**
+ * @file MessageComponentBox.tsx
+ * @description This file defines the MessageComponentBox component, which renders the content
+ * of an AssistantMessage. It supports rendering various message types such as grounded text,
+ * normal text, and follow-up questions. The component uses React and MobX for state management
+ * and includes functionality for handling citation and follow-up actions, as well as displaying
+ * agent processing information.
+ */
+
 import React, { useState } from 'react';
 import { observer } from 'mobx-react';
 import { AssistantMessage, Citation, MessageContent, PROCESSING_TYPE, ProcessingInfo, TEXT_TYPE } from '../types/types';
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ProgressBar.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ProgressBar.tsx
index b9fd08742..240862f8b 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ProgressBar.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ProgressBar.tsx
@@ -1,3 +1,11 @@
+/**
+ * @file ProgressBar.tsx
+ * @description This file defines the ProgressBar component, which displays a loading spinner
+ * to indicate progress during ongoing tasks or processing. The animation consists of two
+ * bouncing elements that create a pulsating effect, providing a visual cue for active progress.
+ * The component is styled using the accompanying `ProgressBar.scss` for smooth animation.
+ */
+
 import React from 'react';
 import './ProgressBar.scss';
 
diff --git a/src/client/views/nodes/chatbot/response_parsers/AnswerParser.ts b/src/client/views/nodes/chatbot/response_parsers/AnswerParser.ts
index 1ac753790..ed78cc7cb 100644
--- a/src/client/views/nodes/chatbot/response_parsers/AnswerParser.ts
+++ b/src/client/views/nodes/chatbot/response_parsers/AnswerParser.ts
@@ -1,3 +1,11 @@
+/**
+ * @file AnswerParser.ts
+ * @description This file defines the AnswerParser class, which processes structured XML-like responses
+ * from the AI system, parsing grounded text, normal text, citations, follow-up questions, and loop summaries.
+ * The parser converts the XML response into an AssistantMessage format, extracting key information like
+ * citations and processing steps for further use in the assistant's workflow.
+ */
+
 import { v4 as uuid } from 'uuid';
 import { ASSISTANT_ROLE, AssistantMessage, Citation, ProcessingInfo, TEXT_TYPE, getChunkType } from '../types/types';
 
diff --git a/src/client/views/nodes/chatbot/response_parsers/StreamedAnswerParser.ts b/src/client/views/nodes/chatbot/response_parsers/StreamedAnswerParser.ts
index 4149f3da9..dbd568faa 100644
--- a/src/client/views/nodes/chatbot/response_parsers/StreamedAnswerParser.ts
+++ b/src/client/views/nodes/chatbot/response_parsers/StreamedAnswerParser.ts
@@ -1,3 +1,11 @@
+/**
+ * @file StreamedAnswerParser.ts
+ * @description This file defines the StreamedAnswerParser class, which parses incoming character streams
+ * to extract grounded or normal text based on the tags found in the input stream. It maintains state
+ * between grounded text and normal text sections, handling buffered input and ensuring proper text formatting
+ * for AI assistant responses.
+ */
+
 enum ParserState {
     Outside,
     InGroundedText,
diff --git a/src/client/views/nodes/chatbot/tools/BaseTool.ts b/src/client/views/nodes/chatbot/tools/BaseTool.ts
index 10780617b..a77f567a5 100644
--- a/src/client/views/nodes/chatbot/tools/BaseTool.ts
+++ b/src/client/views/nodes/chatbot/tools/BaseTool.ts
@@ -1,3 +1,11 @@
+/**
+ * @file BaseTool.ts
+ * @description This file defines the abstract BaseTool class, which serves as a blueprint
+ * for tool implementations in the AI assistant system. Each tool has a name, description,
+ * parameters, and citation rules. The BaseTool class provides a structure for executing actions
+ * and retrieving action rules for use within the assistant's workflow.
+ */
+
 import { Tool } from '../types/types';
 
 export abstract class BaseTool<T extends Record<string, unknown> = Record<string, unknown>> implements Tool<T> {
diff --git a/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts b/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
index 9575277f7..f96f55997 100644
--- a/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
+++ b/src/client/views/nodes/chatbot/vectorstore/Vectorstore.ts
@@ -1,3 +1,10 @@
+/**
+ * @file Vectorstore.ts
+ * @description This file defines the Vectorstore class, which integrates with Pinecone for vector-based document indexing and Cohere for text embeddings.
+ * It handles tasks such as AI document management, document chunking, and retrieval of relevant document sections based on user queries.
+ * The class supports adding documents to the vectorstore, managing document status, and querying Pinecone for document chunks matching a query.
+ */
+
 import { Index, IndexList, Pinecone, PineconeRecord, QueryResponse, RecordMetadata } from '@pinecone-database/pinecone';
 import { CohereClient } from 'cohere-ai';
 import { EmbedResponse } from 'cohere-ai/api';
@@ -128,7 +135,8 @@ export class Vectorstore {
                     }
                 }
                 if (!result) {
-                    throw new Error('no result received...'); // bcz: is this an Error?
+                    console.error('Error processing document.');
+                    return;
                 }
 
                 // Once completed, process the document and add it to the vectorstore.
diff --git a/src/server/ApiManagers/AssistantManager.ts b/src/server/ApiManagers/AssistantManager.ts
index b4ebb1eae..b7d4191ca 100644
--- a/src/server/ApiManagers/AssistantManager.ts
+++ b/src/server/ApiManagers/AssistantManager.ts
@@ -1,3 +1,13 @@
+/**
+ * @file AssistantManager.ts
+ * @description This file defines the AssistantManager class, responsible for managing various
+ * API routes related to the Assistant functionality. It provides features such as file handling,
+ * web scraping, and integration with third-party APIs like OpenAI and Google Custom Search.
+ * It also handles job tracking and progress reporting for tasks like document creation and web scraping.
+ * Utility functions for path manipulation and file operations are included, along with
+ * a mechanism for handling retry logic during API calls.
+ */
+
 import { Readability } from '@mozilla/readability';
 import axios from 'axios';
 import { spawn } from 'child_process';
@@ -76,12 +86,6 @@ export default class AssistantManager extends ApiManager {
      * @param register The registration method to register routes and handlers.
      */
     protected initialize(register: Registration): void {
-        // Initialize OpenAI API with client key
-        const openai = new OpenAI({ // bcz: is this needed?  variable is never used...
-            apiKey: process.env._CLIENT_OPENAI_KEY,
-            dangerouslyAllowBrowser: true,
-        }); // prettier-ignore
-
         // Initialize Google Custom Search API
         const customsearch = google.customsearch('v1');
 
@@ -107,7 +111,6 @@ export default class AssistantManager extends ApiManager {
                     console.error('Error retrieving Wikipedia summary:', error);
                     res.status(500).send({
                         error: 'Error retrieving article summary from Wikipedia.',
-                        details: (error as { message: string }).message ?? error, // bcz: don't know what the error type contains...
                     });
                 }
             },
@@ -140,7 +143,6 @@ export default class AssistantManager extends ApiManager {
                     console.error('Error performing web search:', error);
                     res.status(500).send({
                         error: 'Failed to perform web search',
-                        details: (error as { message: string }).message ?? error, // bcz: don't know wha tthe error type contains...
                     });
                 }
             },
@@ -199,7 +201,6 @@ export default class AssistantManager extends ApiManager {
                     console.error('Error fetching the URL:', error);
                     res.status(500).send({
                         error: 'Failed to fetch the URL',
-                        details: (error as { message: string }).message ?? error, // bcz: don't know wha tthe error type contains...
                     });
                 }
             },
@@ -241,7 +242,6 @@ export default class AssistantManager extends ApiManager {
                     console.error('Error scraping website:', error);
                     res.status(500).send({
                         error: 'Failed to scrape website',
-                        details: (error as { message: string }).message ?? error, // bcz: don't know wha tthe error type contains...
                     });
                 }
             },
@@ -272,7 +272,6 @@ export default class AssistantManager extends ApiManager {
                     console.error('Error initiating document creation:', error);
                     res.status(500).send({
                         error: 'Failed to initiate document creation',
-                        details: (error as { message: string }).message ?? error, // bcz: don't know wha tthe error type contains...
                     });
                 }
             },
@@ -430,7 +429,6 @@ export default class AssistantManager extends ApiManager {
                     console.error('Error creating CSV file:', error);
                     res.status(500).send({
                         error: 'Failed to create CSV file.',
-                        details: (error as { message: string }).message ?? error, // bcz: don't know what the error type contains...
                     });
                 }
             },
-- 
cgit v1.2.3-70-g09d2

