Compare commits

..

1 Commits

Author SHA1 Message Date
596e99daa7 Use word count for summary (more predictable)
All checks were successful
Publish Library / Build NPM Project (push) Successful in 55s
Publish Library / Tag Version (push) Successful in 33s
2026-03-26 13:10:46 -04:00
2 changed files with 7 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ztimson/ai-utils", "name": "@ztimson/ai-utils",
"version": "0.8.14", "version": "0.8.15",
"description": "AI Utility library", "description": "AI Utility library",
"author": "Zak Timson", "author": "Zak Timson",
"license": "MIT", "license": "MIT",

View File

@@ -387,12 +387,12 @@ class LLM {
/** /**
* Create a summary of some text * Create a summary of some text
* @param {string} text Text to summarize * @param {string} text Text to summarize
* @param {number} tokens Max number of tokens * @param {number} length Max number of words
* @param options LLM request options * @param options LLM request options
* @returns {Promise<string>} Summary * @returns {Promise<string>} Summary
*/ */
async summarize(text: string, tokens: number = 500, options?: LLMRequest): Promise<string | null> { async summarize(text: string, length: number = 500, options?: LLMRequest): Promise<string | null> {
let system = `Your job is to summarize the users message using tool calls. Call the \`submit\` tool at least once with the shortest summary possible that's <= ${tokens} tokens. The tool call will respond with the token count. Responses are ignored`; let system = `Your job is to summarize the users message using tool calls. Call the \`submit\` tool at least once with the shortest summary possible that's <= ${length} words. The tool call will respond with the token count. Responses are ignored`;
if(options?.system) system += '\n\n' + options.system; if(options?.system) system += '\n\n' + options.system;
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
let done = false; let done = false;
@@ -406,11 +406,11 @@ class LLM {
args: {summary: {type: 'string', description: 'Text summarization', required: true}}, args: {summary: {type: 'string', description: 'Text summarization', required: true}},
fn: (args) => { fn: (args) => {
if(!args.summary) return 'No summary provided'; if(!args.summary) return 'No summary provided';
const count = this.estimateTokens(args.summary); const count = args.summary.split(' ').length;
if(count > tokens) return `Summary is too long (${count} tokens)`; if(count > length) return `Too long: ${length} words`;
done = true; done = true;
resolve(args.summary || null); resolve(args.summary || null);
return `Saved (${count} tokens)`; return `Saved: ${length} words`;
} }
}, ...(options?.tools || [])], }, ...(options?.tools || [])],
}); });