From 526b96d87a52e88751a6d1d210f542f7ca640c49 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Sun, 2 Jun 2024 19:54:39 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ai-function-set.ts | 33 +++++++++++++++++++++++---------- src/services/searxng-client.ts | 12 ++++++++++-- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/ai-function-set.ts b/src/ai-function-set.ts index a053a56..53e7a97 100644 --- a/src/ai-function-set.ts +++ b/src/ai-function-set.ts @@ -7,6 +7,9 @@ import { AIFunctionsProvider } from './fns.js' * * This class mimics a built-in `Set`, but with additional utility * methods like `pick`, `omit`, and `map`. + * + * Function names are case-insensitive to make it easier to match them with + * possible LLM hallucinations. */ export class AIFunctionSet implements Iterable { protected readonly _map: Map @@ -20,7 +23,9 @@ export class AIFunctionSet implements Iterable { : [fn] ) - this._map = new Map(fns ? fns.map((fn) => [fn.spec.name, fn]) : null) + this._map = new Map( + fns ? fns.map((fn) => [transformName(fn.spec.name), fn]) : null + ) } get size(): number { @@ -28,21 +33,21 @@ export class AIFunctionSet implements Iterable { } add(fn: types.AIFunction): this { - this._map.set(fn.spec.name, fn) + this._map.set(transformName(fn.spec.name), fn) return this } get(name: string): types.AIFunction | undefined { - return this._map.get(name) + return this._map.get(transformName(name)) } set(name: string, fn: types.AIFunction): this { - this._map.set(name, fn) + this._map.set(transformName(name), fn) return this } has(name: string): boolean { - return this._map.has(name) + return this._map.has(transformName(name)) } clear(): void { @@ -50,20 +55,24 @@ export class AIFunctionSet implements Iterable { } delete(name: string): boolean { - return this._map.delete(name) + return this._map.delete(transformName(name)) } pick(...keys: string[]): AIFunctionSet { - const keysToIncludeSet = new Set(keys) + const keysToIncludeSet = new Set(keys.map(transformName)) return new AIFunctionSet( - Array.from(this).filter((fn) => keysToIncludeSet.has(fn.spec.name)) + Array.from(this).filter((fn) => + keysToIncludeSet.has(transformName(fn.spec.name)) + ) ) } omit(...keys: string[]): AIFunctionSet { - const keysToExcludeSet = new Set(keys) + const keysToExcludeSet = new Set(keys.map(transformName)) return new AIFunctionSet( - Array.from(this).filter((fn) => !keysToExcludeSet.has(fn.spec.name)) + Array.from(this).filter( + (fn) => !keysToExcludeSet.has(transformName(fn.spec.name)) + ) ) } @@ -90,3 +99,7 @@ export class AIFunctionSet implements Iterable { return this.entries } } + +function transformName(name: string): string { + return name.toLowerCase() +} diff --git a/src/services/searxng-client.ts b/src/services/searxng-client.ts index 1103af2..a19f98d 100644 --- a/src/services/searxng-client.ts +++ b/src/services/searxng-client.ts @@ -218,8 +218,16 @@ export namespace searxng { export const SearchOptionsSchema = z.object({ query: z.string().describe('search query'), - categories: z.array(SearchCategorySchema).optional(), - engines: z.array(SearchEngineSchema).optional(), + categories: z + .array(SearchCategorySchema) + .optional() + .describe( + 'narrows the search to only use search engines in specific categories' + ), + engines: z + .array(SearchEngineSchema) + .optional() + .describe('narrows the search to only use specific search engines'), language: z.string().optional(), pageno: z.number().int().optional() })