diff --git a/server/utils/agents/aibitat/plugins/summarize.js b/server/utils/agents/aibitat/plugins/summarize.js index ac1ad82c50ec090381c6771562f6a2318e5925d1..d0cfc6c1b2a475e3df140c63984f41b3b8ef4278 100644 --- a/server/utils/agents/aibitat/plugins/summarize.js +++ b/server/utils/agents/aibitat/plugins/summarize.js @@ -27,21 +27,21 @@ const docSummarizer = { type: "string", enum: ["list", "summarize"], description: - "The action to take. 'list' will return all files available and their document ids. 'summarize' will open and summarize the file by the document_id, in the format of a uuid.", + "The action to take. 'list' will return all files available with their filename and descriptions. 'summarize' will open and summarize the file by the a document name.", }, - document_id: { + document_filename: { type: "string", "x-nullable": true, description: - "A document id to summarize the content of. Document id must be a uuid.", + "The file name of the document you want to get the full content of.", }, }, additionalProperties: false, }, - handler: async function ({ action, document_id }) { + handler: async function ({ action, document_filename }) { if (action === "list") return await this.listDocuments(); if (action === "summarize") - return await this.summarizeDoc(document_id); + return await this.summarizeDoc(document_filename); return "There is nothing we can do. This function call returns no information."; }, @@ -81,19 +81,33 @@ const docSummarizer = { } }, - summarizeDoc: async function (documentId) { + summarizeDoc: async function (filename) { try { - if (!validate(documentId)) { + const availableDocs = safeJsonParse( + await this.listDocuments(), + [] + ); + if (!availableDocs.length) { + this.super.handlerProps.log( + `${this.caller}: No available documents to summarize.` + ); + return "No documents were found."; + } + + const docInfo = availableDocs.find( + (info) => info.filename === filename + ); + if (!docInfo) { this.super.handlerProps.log( - `${this.caller}: documentId ${documentId} is not a valid UUID` + `${this.caller}: No available document by the name "${filename}".` ); - return "This was not a valid documentID because it was not a uuid. No content was found."; + return `No available document by the name "${filename}".`; } - const document = await Document.content(documentId); + const document = await Document.content(docInfo.document_id); this.super.introspect( `${this.caller}: Grabbing all content for ${ - document?.title ?? "a discovered file." + filename ?? "a discovered file." }` ); @@ -111,7 +125,7 @@ const docSummarizer = { } this.super.introspect( - `${this.caller}: Summarizing ${document?.title ?? ""}...` + `${this.caller}: Summarizing ${filename ?? ""}...` ); this.super.onAbort(() => {