Merge pull request #2003 from bdashore3/json-schema

Add JSON schemas for TabbyAPI
This commit is contained in:
Cohee 2024-04-02 11:23:49 +03:00 committed by GitHub
commit 96a85ca688
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 0 deletions

View File

@ -1516,6 +1516,17 @@
</div>
</div>
</div>
<div data-newbie-hidden id="json_schema_block" data-tg-type="tabby" class="wide100p">
<hr class="wide100p">
<h4 class="wide100p textAlignCenter"><span data-i18n="JSON Schema">JSON Schema</span>
<a href="https://json-schema.org/learn/getting-started-step-by-step" target="_blank">
<small>
<div class="fa-solid fa-circle-question note-link-span"></div>
</small>
</a>
</h4>
<textarea id="tabby_json_schema" rows="4" class="text_pole textarea_compact monospace" data-i18n="[placeholder]Type in the desired JSON schema" placeholder="Type in the desired JSON schema"></textarea>
</div>
<div data-newbie-hidden id="grammar_block_ooba" class="wide100p">
<hr class="wide100p">
<h4 class="wide100p textAlignCenter">

View File

@ -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,17 @@ jQuery(function () {
},
});
$('#tabby_json_schema').on('input', function () {
const json_schema_string = String($(this).val());
try {
settings.json_schema = JSON.parse(json_schema_string ?? '{}');
} catch {
// Ignore errors from here
}
saveSettingsDebounced();
});
$('#textgenerationwebui_default_order').on('click', function () {
sortOobaItemsByOrder(OOBA_DEFAULT_ORDER);
settings.sampler_priority = OOBA_DEFAULT_ORDER;
@ -757,6 +770,12 @@ function setSettingByName(setting, value, trigger) {
return;
}
if ('json_schema' === setting) {
settings.json_schema = value ?? {};
$('#tabby_json_schema').val(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 +1046,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,