这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions server/utils/agents/aibitat/plugins/summarize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
},

Expand Down Expand Up @@ -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."
}`
);

Expand All @@ -111,7 +125,7 @@ const docSummarizer = {
}

this.super.introspect(
`${this.caller}: Summarizing ${document?.title ?? ""}...`
`${this.caller}: Summarizing ${filename ?? ""}...`
);

this.super.onAbort(() => {
Expand Down