diff options
author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-10-10 11:39:19 -0400 |
---|---|---|
committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-10-10 11:39:19 -0400 |
commit | d347fc59feefd91a796012892da57511787bb6d0 (patch) | |
tree | 83b8950ade694a795a38fd2969d50978c1179b83 | |
parent | 75b98f184260567c0dabb54dd8ef22a8e2510512 (diff) |
added new file header comments and fixed some error handling
9 files changed, 77 insertions, 14 deletions
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... }); } }, |