From 75f44e24e9f8838b4b0b2c371f610e11dc71a1b8 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 20 Sep 2024 00:02:14 +0300 Subject: [PATCH] Use Fuse only as fallback --- public/scripts/sysprompt.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/public/scripts/sysprompt.js b/public/scripts/sysprompt.js index 9d298beef..0eb30c377 100644 --- a/public/scripts/sysprompt.js +++ b/public/scripts/sysprompt.js @@ -123,15 +123,20 @@ function selectSystemPromptCallback(args, name) { const quiet = isTrueBoolean(args?.quiet); const instructNames = system_prompts.map(preset => preset.name); - const fuse = new Fuse(instructNames); - const result = fuse.search(name); + let foundName = instructNames.find(x => x.toLowerCase() === name.toLowerCase()); - if (result.length === 0) { - !quiet && toastr.warning(`System prompt "${name}" not found`); - return ''; + if (!foundName) { + const fuse = new Fuse(instructNames); + const result = fuse.search(name); + + if (result.length === 0) { + !quiet && toastr.warning(`System prompt "${name}" not found`); + return ''; + } + + foundName = result[0].item; } - const foundName = result[0].item; $select.val(foundName).trigger('input'); !quiet && toastr.success(`System prompt "${foundName}" selected`); return foundName;