diff options
| author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-11-07 11:32:52 -0500 |
|---|---|---|
| committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-11-07 11:32:52 -0500 |
| commit | 68b07c07b41449067eec8f8cd22475a64eb91e67 (patch) | |
| tree | 665114eb69209c3d4f13ba86bfe116d3b6238939 /src/client/views/nodes/chatbot/agentsystem/Agent.ts | |
| parent | ab6672a702986d9b22de4f2df7955a0297308cab (diff) | |
working to create docs but wrong doc types/not compatible with LLM
Diffstat (limited to 'src/client/views/nodes/chatbot/agentsystem/Agent.ts')
| -rw-r--r-- | src/client/views/nodes/chatbot/agentsystem/Agent.ts | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/client/views/nodes/chatbot/agentsystem/Agent.ts b/src/client/views/nodes/chatbot/agentsystem/Agent.ts index 750bbbf4f..c934bd84b 100644 --- a/src/client/views/nodes/chatbot/agentsystem/Agent.ts +++ b/src/client/views/nodes/chatbot/agentsystem/Agent.ts @@ -12,13 +12,14 @@ import { NoTool } from '../tools/NoTool'; import { RAGTool } from '../tools/RAGTool'; import { SearchTool } from '../tools/SearchTool'; import { WebsiteInfoScraperTool } from '../tools/WebsiteInfoScraperTool'; -import { AgentMessage, AssistantMessage, Observation, PROCESSING_TYPE, ProcessingInfo } from '../types/types'; +import { AgentMessage, ASSISTANT_ROLE, AssistantMessage, Observation, PROCESSING_TYPE, ProcessingInfo, TEXT_TYPE } from '../types/types'; import { Vectorstore } from '../vectorstore/Vectorstore'; import { getReactPrompt } from './prompts'; import { BaseTool } from '../tools/BaseTool'; import { Parameter, ParametersType, TypeMap } from '../types/tool_types'; import { CreateTextDocTool } from '../tools/CreateTextDocumentTool'; import { DocumentOptions } from '../../../../documents/Documents'; +import { CreateAnyDocumentTool } from '../tools/CreateAnyDocTool'; dotenv.config(); @@ -57,7 +58,7 @@ export class Agent { history: () => string, csvData: () => { filename: string; id: string; text: string }[], addLinkedUrlDoc: (url: string, id: string) => void, - addLinkedDoc: (doc_type: string, data: string, options: DocumentOptions, id: string) => void, + addLinkedDoc: (doc_type: string, data: string | undefined, options: DocumentOptions, id: string) => void, createCSVInDash: (url: string, title: string, id: string, data: string) => void ) { // Initialize OpenAI client with API key from environment @@ -76,7 +77,8 @@ export class Agent { searchTool: new SearchTool(addLinkedUrlDoc), createCSV: new CreateCSVTool(createCSVInDash), noTool: new NoTool(), - createTextDoc: new CreateTextDocTool(addLinkedDoc), + //createTextDoc: new CreateTextDocTool(addLinkedDoc), + createAnyDocument: new CreateAnyDocumentTool(addLinkedDoc), }; } @@ -91,6 +93,13 @@ export class Agent { */ async askAgent(question: string, onProcessingUpdate: (processingUpdate: ProcessingInfo[]) => void, onAnswerUpdate: (answerUpdate: string) => void, maxTurns: number = 30): Promise<AssistantMessage> { console.log(`Starting query: ${question}`); + const MAX_QUERY_LENGTH = 1000; // adjust the limit as needed + + // Check if the question exceeds the maximum length + if (question.length > MAX_QUERY_LENGTH) { + return { role: ASSISTANT_ROLE.ASSISTANT, content: [{ text: 'User query too long. Please shorten your question and try again.', index: 0, type: TEXT_TYPE.NORMAL, citation_ids: null }], processing_info: [] }; + } + const sanitizedQuestion = escape(question); // Sanitized user input // Push sanitized user's question to message history |
