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