diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/nodes/chatbot/agentsystem/Agent.ts | 15 | ||||
-rw-r--r-- | src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts | 8 |
2 files changed, 19 insertions, 4 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 diff --git a/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts b/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts index af0dcc79c..bb1761cee 100644 --- a/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts +++ b/src/client/views/nodes/chatbot/tools/CreateAnyDocTool.ts @@ -51,7 +51,13 @@ const createAnyDocumentToolParams = [ { name: 'options', type: 'string', - description: `A JSON string representing the document options. Available options depend on the document type. For example, for 'text' documents, options include: ${documentOptionsDescription['text'].join(', ')}.`, + description: `A JSON string representing the document options. Available options depend on the document type.\n + For example, for 'text' documents, options include: ${documentOptionsDescription['text'].join(', ')}.\n + For 'image' documents, options include: ${documentOptionsDescription['image'].join(', ')}.\n + For 'pdf' documents, options include: ${documentOptionsDescription['pdf'].join(', ')}.\n + For 'video' documents, options include: ${documentOptionsDescription['video'].join(', ')}.\n + For 'audio' documents, options include: ${documentOptionsDescription['audio'].join(', ')}.\n + For 'web' documents, options include: ${documentOptionsDescription['web'].join(', ')}.\n`, required: false, }, ] as const; |