From 986f273006759c93a9c1b8af1f80a93eb3c1ffd6 Mon Sep 17 00:00:00 2001 From: Luk Date: Wed, 9 Apr 2025 21:34:55 +0800 Subject: [PATCH] add `summarize_story` --- tool_core.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tool_core.js b/tool_core.js index c463414..a11e368 100644 --- a/tool_core.js +++ b/tool_core.js @@ -349,6 +349,26 @@ module.exports = { } }, + summarize_story (story = []) { + // story is an array of objects, each object could either be {text:'some string'}, {image: url} or {video:url}. Please construct a summary object as result: { textLength, imageCount, VideoCount } + return story.reduce( + (summary, { text, image, video, file } = {}) => { + if (text) { + summary.textLength += text.length + summary.wordCount += text.split(/\s+/).length + } else if (image) { + summary.imageCount++ + } else if (video) { + summary.videoCount++ + } else if (file) { + summary.fileCount++ + } + return summary + }, + { textLength: 0, wordCount: 0, imageCount: 0, videoCount: 0 } + ) + }, + is_empty (data) { // empty: undefined, null, false, 0, NaN, '', '空格,tab, \n等', [], {} if (data) {