From 4f0322351ecb5eba52c923ccc9d4188d3c06db2f Mon Sep 17 00:00:00 2001 From: kingbri Date: Tue, 2 Apr 2024 00:59:21 -0400 Subject: [PATCH 1/3] Sampling: Add ability to send JSON schemas TabbyAPI supports the ability to send JSON schemas with prompts in addition to EBNF strings supported by outlines. Add an extra box for TabbyAPI only. Signed-off-by: kingbri --- public/index.html | 11 +++++++++++ public/scripts/textgen-settings.js | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/public/index.html b/public/index.html index 928061b0c..5d93ef362 100644 --- a/public/index.html +++ b/public/index.html @@ -1516,6 +1516,17 @@ +
+
+

JSON Schema + + + + + +

+ +

diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index fdd2380f7..4d7fe4007 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -128,6 +128,7 @@ const settings = { guidance_scale: 1, negative_prompt: '', grammar_string: '', + json_schema: {}, banned_tokens: '', sampler_priority: OOBA_DEFAULT_ORDER, samplers: LLAMACPP_DEFAULT_ORDER, @@ -201,6 +202,7 @@ const setting_names = [ 'guidance_scale', 'negative_prompt', 'grammar_string', + 'json_schema', 'banned_tokens', 'legacy_api', //'n_aphrodite', @@ -562,6 +564,16 @@ jQuery(function () { }, }); + $('#tabby_json_schema').on('input', function () { + const json_schema_string = $(this).val(); + + // Ignore errors from here + try { + settings.json_schema = JSON.parse(json_schema_string ?? "{}"); + } catch {} + saveSettingsDebounced(); + }); + $('#textgenerationwebui_default_order').on('click', function () { sortOobaItemsByOrder(OOBA_DEFAULT_ORDER); settings.sampler_priority = OOBA_DEFAULT_ORDER; @@ -757,6 +769,12 @@ function setSettingByName(setting, value, trigger) { return; } + if ('json_schema' === setting) { + settings.json_schema = value ?? {} + $('#tabby_json_schema').text(JSON.stringify(settings.json_schema, null, 2)) + return; + } + const isCheckbox = $(`#${setting}_textgenerationwebui`).attr('type') == 'checkbox'; const isText = $(`#${setting}_textgenerationwebui`).attr('type') == 'text' || $(`#${setting}_textgenerationwebui`).is('textarea'); if (isCheckbox) { @@ -1027,6 +1045,7 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, 'guidance_scale': cfgValues?.guidanceScale?.value ?? settings.guidance_scale ?? 1, 'negative_prompt': cfgValues?.negativePrompt ?? substituteParams(settings.negative_prompt) ?? '', 'grammar_string': settings.grammar_string, + 'json_schema': settings.type === TABBY ? settings.json_schema : undefined, // llama.cpp aliases. In case someone wants to use LM Studio as Text Completion API 'repeat_penalty': settings.rep_pen, 'tfs_z': settings.tfs, From 5210db567981ff46873c493dbbc69040196e4d8b Mon Sep 17 00:00:00 2001 From: kingbri Date: Tue, 2 Apr 2024 01:01:59 -0400 Subject: [PATCH 2/3] Format Signed-off-by: kingbri --- public/scripts/textgen-settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 4d7fe4007..11d2221cd 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -569,7 +569,7 @@ jQuery(function () { // Ignore errors from here try { - settings.json_schema = JSON.parse(json_schema_string ?? "{}"); + settings.json_schema = JSON.parse(json_schema_string ?? '{}'); } catch {} saveSettingsDebounced(); }); From 0b76e1d3509230f0093fed53ea6878dbeb8605d6 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 2 Apr 2024 11:23:29 +0300 Subject: [PATCH 3/3] Fix schema not loading from presets. Fix ESLint warnings --- public/scripts/textgen-settings.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index 11d2221cd..d7cee2625 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -565,12 +565,13 @@ jQuery(function () { }); $('#tabby_json_schema').on('input', function () { - const json_schema_string = $(this).val(); + const json_schema_string = String($(this).val()); - // Ignore errors from here try { settings.json_schema = JSON.parse(json_schema_string ?? '{}'); - } catch {} + } catch { + // Ignore errors from here + } saveSettingsDebounced(); }); @@ -770,8 +771,8 @@ function setSettingByName(setting, value, trigger) { } if ('json_schema' === setting) { - settings.json_schema = value ?? {} - $('#tabby_json_schema').text(JSON.stringify(settings.json_schema, null, 2)) + settings.json_schema = value ?? {}; + $('#tabby_json_schema').val(JSON.stringify(settings.json_schema, null, 2)); return; }