mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2025-04-23 13:08:11 +00:00
Improve document summarizer by being able to reference by direct name versus ID, which sometimes models fail to chain (#1121)
This commit is contained in:
parent
81fd82e133
commit
41978765bc
1 changed files with 26 additions and 12 deletions
|
@ -27,21 +27,21 @@ const docSummarizer = {
|
||||||
type: "string",
|
type: "string",
|
||||||
enum: ["list", "summarize"],
|
enum: ["list", "summarize"],
|
||||||
description:
|
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",
|
type: "string",
|
||||||
"x-nullable": true,
|
"x-nullable": true,
|
||||||
description:
|
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,
|
additionalProperties: false,
|
||||||
},
|
},
|
||||||
handler: async function ({ action, document_id }) {
|
handler: async function ({ action, document_filename }) {
|
||||||
if (action === "list") return await this.listDocuments();
|
if (action === "list") return await this.listDocuments();
|
||||||
if (action === "summarize")
|
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.";
|
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 {
|
try {
|
||||||
if (!validate(documentId)) {
|
const availableDocs = safeJsonParse(
|
||||||
|
await this.listDocuments(),
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
if (!availableDocs.length) {
|
||||||
this.super.handlerProps.log(
|
this.super.handlerProps.log(
|
||||||
`${this.caller}: documentId ${documentId} is not a valid UUID`
|
`${this.caller}: No available documents to summarize.`
|
||||||
);
|
);
|
||||||
return "This was not a valid documentID because it was not a uuid. No content was found.";
|
return "No documents were found.";
|
||||||
}
|
}
|
||||||
|
|
||||||
const document = await Document.content(documentId);
|
const docInfo = availableDocs.find(
|
||||||
|
(info) => info.filename === filename
|
||||||
|
);
|
||||||
|
if (!docInfo) {
|
||||||
|
this.super.handlerProps.log(
|
||||||
|
`${this.caller}: No available document by the name "${filename}".`
|
||||||
|
);
|
||||||
|
return `No available document by the name "${filename}".`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const document = await Document.content(docInfo.document_id);
|
||||||
this.super.introspect(
|
this.super.introspect(
|
||||||
`${this.caller}: Grabbing all content for ${
|
`${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.super.introspect(
|
||||||
`${this.caller}: Summarizing ${document?.title ?? ""}...`
|
`${this.caller}: Summarizing ${filename ?? ""}...`
|
||||||
);
|
);
|
||||||
|
|
||||||
this.super.onAbort(() => {
|
this.super.onAbort(() => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue