TC: Add a toggle for empty json schemas (#4807)
Signed| @@ -45,6 +45,7 @@ | ||
| 45 | 45 | "negative_prompt": "", |
| 46 | 46 | "grammar_string": "", |
| 47 | 47 | "json_schema": null, |
| 48 | + "json_schema_allow_empty": false, | |
| 48 | 49 | "banned_tokens": "", |
| 49 | 50 | "sampler_priority": [ |
| 50 | 51 | "repetition_penalty", |
| @@ -45,6 +45,7 @@ | ||
| 45 | 45 | "negative_prompt": "", |
| 46 | 46 | "grammar_string": "", |
| 47 | 47 | "json_schema": null, |
| 48 | + "json_schema_allow_empty": false, | |
| 48 | 49 | "banned_tokens": "", |
| 49 | 50 | "sampler_priority": [ |
| 50 | 51 | "repetition_penalty", |
| @@ -45,6 +45,7 @@ | ||
| 45 | 45 | "negative_prompt": "", |
| 46 | 46 | "grammar_string": "", |
| 47 | 47 | "json_schema": null, |
| 48 | + "json_schema_allow_empty": false, | |
| 48 | 49 | "banned_tokens": "", |
| 49 | 50 | "sampler_priority": [ |
| 50 | 51 | "repetition_penalty", |
| @@ -45,6 +45,7 @@ | ||
| 45 | 45 | "negative_prompt": "", |
| 46 | 46 | "grammar_string": "", |
| 47 | 47 | "json_schema": null, |
| 48 | + "json_schema_allow_empty": false, | |
| 48 | 49 | "banned_tokens": "", |
| 49 | 50 | "sampler_priority": [ |
| 50 | 51 | "repetition_penalty", |
| @@ -45,6 +45,7 @@ | ||
| 45 | 45 | "negative_prompt": "", |
| 46 | 46 | "grammar_string": "", |
| 47 | 47 | "json_schema": null, |
| 48 | + "json_schema_allow_empty": false, | |
| 48 | 49 | "banned_tokens": "", |
| 49 | 50 | "sampler_priority": [ |
| 50 | 51 | "repetition_penalty", |
| @@ -45,6 +45,7 @@ | ||
| 45 | 45 | "negative_prompt": "", |
| 46 | 46 | "grammar_string": "", |
| 47 | 47 | "json_schema": null, |
| 48 | + "json_schema_allow_empty": false, | |
| 48 | 49 | "banned_tokens": "", |
| 49 | 50 | "sampler_priority": [ |
| 50 | 51 | "repetition_penalty", |
| @@ -1707,6 +1707,10 @@ | ||
| 1707 | 1707 | </a> |
| 1708 | 1708 | </h4> |
| 1709 | 1709 | <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> |
| 1710 | + <label for="json_schema_allow_empty_textgenerationwebui" class="checkbox_label" title="Treat empty JSON object as a valid JSON schema." data-tg-type="all"> | |
| 1711 | + <input type="checkbox" id="json_schema_allow_empty_textgenerationwebui" /> | |
| 1712 | + <small data-i18n="Allow empty schema objects">Allow empty schema objects</small> | |
| 1713 | + </label> | |
| 1710 | 1714 | </div> |
| 1711 | 1715 | <div id="sampler_order_block_kcpp" data-tg-type="koboldcpp" data-tg-samplers="sampler_order" class="range-block flexFlowColumn wide100p"> |
| 1712 | 1716 | <hr class="wide100p"> |
| @@ -193,6 +193,7 @@ const settings = { | ||
| 193 | 193 | negative_prompt: '', |
| 194 | 194 | grammar_string: '', |
| 195 | 195 | json_schema: null, |
| 196 | + json_schema_allow_empty: false, | |
| 196 | 197 | banned_tokens: '', |
| 197 | 198 | global_banned_tokens: '', |
| 198 | 199 | send_banned_tokens: true, |
| @@ -311,6 +312,7 @@ export const setting_names = [ | ||
| 311 | 312 | 'min_keep', |
| 312 | 313 | 'generic_model', |
| 313 | 314 | 'extensions', |
| 315 | + 'json_schema_allow_empty', | |
| 314 | 316 | ]; |
| 315 | 317 | |
| 316 | 318 | const DYNATEMP_BLOCK = document.getElementById('dynatemp_block_ooba'); |
| @@ -1506,6 +1508,11 @@ export async function getTextGenGenerationData(finalPrompt, maxTokens, isImperso | ||
| 1506 | 1508 | const canMultiSwipe = !isContinue && !isImpersonate && type !== 'quiet'; |
| 1507 | 1509 | const dynatemp = isDynamicTemperatureSupported(); |
| 1508 | 1510 | const { banned_tokens, banned_strings } = getCustomTokenBans(); |
| 1511 | + const jsonSchema = isObject(settings.json_schema) | |
| 1512 | + ? settings.json_schema_allow_empty | |
| 1513 | + ? settings.json_schema | |
| 1514 | + : Object.keys(settings.json_schema).length > 0 ? settings.json_schema : undefined | |
| 1515 | + : undefined; | |
| 1509 | 1516 | |
| 1510 | 1517 | let params = { |
| 1511 | 1518 | 'prompt': finalPrompt, |
| @@ -1597,7 +1604,7 @@ export async function getTextGenGenerationData(finalPrompt, maxTokens, isImperso | ||
| 1597 | 1604 | 'guidance_scale': cfgValues?.guidanceScale?.value ?? settings.guidance_scale ?? 1, |
| 1598 | 1605 | 'negative_prompt': cfgValues?.negativePrompt ?? substituteParams(settings.negative_prompt) ?? '', |
| 1599 | 1606 | 'grammar_string': settings.grammar_string || undefined, |
| 1600 | 1607 | 'json_schema': [TABBY, LLAMACPP].includes(settings.type) && settings.json_schema ? settings.json_schemajsonSchema : undefined, |
| 1601 | 1608 | // llama.cpp aliases. In case someone wants to use LM Studio as Text Completion API |
| 1602 | 1609 | 'repeat_penalty': settings.rep_pen, |
| 1603 | 1610 | 'repeat_last_n': settings.rep_pen_range, |
| @@ -1639,7 +1646,7 @@ export async function getTextGenGenerationData(finalPrompt, maxTokens, isImperso | ||
| 1639 | 1646 | 'skip_special_tokens': settings.skip_special_tokens, |
| 1640 | 1647 | 'spaces_between_special_tokens': settings.spaces_between_special_tokens, |
| 1641 | 1648 | 'guided_grammar': settings.grammar_string || undefined, |
| 1642 | 1649 | 'guided_json': settings.json_schemajsonSchema || undefined, |
| 1643 | 1650 | 'early_stopping': false, // hacks |
| 1644 | 1651 | 'include_stop_str_in_output': false, |
| 1645 | 1652 | 'dynatemp_min': dynatemp ? settings.min_temp : undefined, |
| @@ -1734,7 +1741,7 @@ export async function getTextGenGenerationData(finalPrompt, maxTokens, isImperso | ||
| 1734 | 1741 | |
| 1735 | 1742 | // Grammar conflicts with with json_schema |
| 1736 | 1743 | if ([LLAMACPP, APHRODITE].includes(settings.type)) { |
| 1737 | 1744 | if (settings.json_schema && isObject(settings.json_schema)jsonSchema) { |
| 1738 | 1745 | delete params.grammar_string; |
| 1739 | 1746 | delete params.grammar; |
| 1740 | 1747 | delete params.guided_grammar; |