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

This commit is contained in:
2026-03-26 12:33:50 -04:00
parent 5eae84f6cf
commit 7f88c2d1d0
2 changed files with 4 additions and 4 deletions

View File

@@ -358,7 +358,7 @@ class LLM {
* @returns {Promise<{} | {} | RegExpExecArray | null>}
*/
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;
return new Promise(async (resolve, reject) => {
let done = false;
@@ -392,7 +392,7 @@ class LLM {
* @returns {Promise<string>} Summary
*/
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;
return new Promise(async (resolve, reject) => {
let done = false;
@@ -403,7 +403,7 @@ class LLM {
tools: [{
name: 'submit',
description: 'Submit summary',
args: {summary: {type: 'string', description: 'Summarization', required: true}},
args: {summary: {type: 'string', description: 'Text summarization', required: true}},
fn: (args) => {
done = true;
resolve(args.summary || null);