Compare commits

...

1 Commits

Author SHA1 Message Date
7f88c2d1d0 Added JSON / Summary LLM safeguard
All checks were successful
Publish Library / Build NPM Project (push) Successful in 1m17s
Publish Library / Tag Version (push) Successful in 13s
2026-03-26 12:33:50 -04:00
2 changed files with 4 additions and 4 deletions

View File

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

View File

@@ -358,7 +358,7 @@ class LLM {
* @returns {Promise<{} | {} | RegExpExecArray | null>} * @returns {Promise<{} | {} | RegExpExecArray | null>}
*/ */
async json(text: string, schema: string, options?: LLMRequest): Promise<any> { async json(text: string, schema: string, options?: LLMRequest): Promise<any> {
let system = `Your job is to convert input to JSON. Call \`submit\` exactly once with JSON matching this schema:\n\`\`\`json\n${schema}\n\`\`\``; let system = `Your job is to convert input to JSON. Call the \`submit\` tool exactly once with JSON matching this schema:\n\`\`\`json\n${schema}\n\`\`\``;
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;
@@ -392,7 +392,7 @@ class LLM {
* @returns {Promise<string>} Summary * @returns {Promise<string>} Summary
*/ */
async summarize(text: string, tokens: number = 500, options?: LLMRequest): Promise<string | null> { async summarize(text: string, tokens: number = 500, options?: LLMRequest): Promise<string | null> {
let system = `Your job is to summarize the users message. Call \`submit\` exactly once with the shortest summary possible that's <= ${tokens} tokens. Output nothing else`; let system = `Your job is to summarize the users message. Call the \`submit\` tool exactly once with the shortest summary possible that's <= ${tokens} tokens. Output nothing else`;
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;
@@ -403,7 +403,7 @@ class LLM {
tools: [{ tools: [{
name: 'submit', name: 'submit',
description: 'Submit summary', description: 'Submit summary',
args: {summary: {type: 'string', description: 'Summarization', required: true}}, args: {summary: {type: 'string', description: 'Text summarization', required: true}},
fn: (args) => { fn: (args) => {
done = true; done = true;
resolve(args.summary || null); resolve(args.summary || null);