Skip to content
Snippets Groups Projects
Unverified Commit 41978765 authored by Timothy Carambat's avatar Timothy Carambat Committed by GitHub
Browse files

Improve document summarizer by being able to reference by direct name versus...

Improve document summarizer by being able to reference by direct name versus ID, which sometimes models fail to chain (#1121)
parent 81fd82e1
No related branches found
No related tags found
No related merge requests found
......@@ -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(() => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment