TC: Allow setting null JSON schema (#4746)
* TC: Allow setting empty JSON schema * Fix check for llamacpp schema * Handle grammar/schema for Aphrodite * Conditional include for guided_json * Update default presets with null value * Conditional include into payload for grammar/schema
This commit is contained in:
@@ -44,7 +44,7 @@
|
||||
"guidance_scale": 1,
|
||||
"negative_prompt": "",
|
||||
"grammar_string": "",
|
||||
"json_schema": {},
|
||||
"json_schema": null,
|
||||
"banned_tokens": "",
|
||||
"sampler_priority": [
|
||||
"repetition_penalty",
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
"guidance_scale": 1,
|
||||
"negative_prompt": "",
|
||||
"grammar_string": "",
|
||||
"json_schema": {},
|
||||
"json_schema": null,
|
||||
"banned_tokens": "",
|
||||
"sampler_priority": [
|
||||
"repetition_penalty",
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
"guidance_scale": 1,
|
||||
"negative_prompt": "",
|
||||
"grammar_string": "",
|
||||
"json_schema": {},
|
||||
"json_schema": null,
|
||||
"banned_tokens": "",
|
||||
"sampler_priority": [
|
||||
"repetition_penalty",
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
"guidance_scale": 1,
|
||||
"negative_prompt": "",
|
||||
"grammar_string": "",
|
||||
"json_schema": {},
|
||||
"json_schema": null,
|
||||
"banned_tokens": "",
|
||||
"sampler_priority": [
|
||||
"repetition_penalty",
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
"guidance_scale": 1,
|
||||
"negative_prompt": "",
|
||||
"grammar_string": "",
|
||||
"json_schema": {},
|
||||
"json_schema": null,
|
||||
"banned_tokens": "",
|
||||
"sampler_priority": [
|
||||
"repetition_penalty",
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
"guidance_scale": 1,
|
||||
"negative_prompt": "",
|
||||
"grammar_string": "",
|
||||
"json_schema": {},
|
||||
"json_schema": null,
|
||||
"banned_tokens": "",
|
||||
"sampler_priority": [
|
||||
"repetition_penalty",
|
||||
|
||||
@@ -25,7 +25,7 @@ import { getEventSourceStream } from './sse-stream.js';
|
||||
import { getCurrentDreamGenModelTokenizer, getCurrentOpenRouterModelTokenizer, loadAphroditeModels, loadDreamGenModels, loadFeatherlessModels, loadGenericModels, loadInfermaticAIModels, loadMancerModels, loadOllamaModels, loadOpenRouterModels, loadTabbyModels, loadTogetherAIModels, loadVllmModels } from './textgen-models.js';
|
||||
import { ENCODE_TOKENIZERS, TEXTGEN_TOKENIZERS, TOKENIZER_SUPPORTED_KEY, getTextTokens, tokenizers } from './tokenizers.js';
|
||||
import { AbortReason } from './util/AbortReason.js';
|
||||
import { getSortableDelay, onlyUnique, arraysEqual } from './utils.js';
|
||||
import { getSortableDelay, onlyUnique, arraysEqual, isObject } from './utils.js';
|
||||
|
||||
export const textgen_types = {
|
||||
OOBA: 'ooba',
|
||||
@@ -191,7 +191,7 @@ const settings = {
|
||||
guidance_scale: 1,
|
||||
negative_prompt: '',
|
||||
grammar_string: '',
|
||||
json_schema: {},
|
||||
json_schema: null,
|
||||
banned_tokens: '',
|
||||
global_banned_tokens: '',
|
||||
send_banned_tokens: true,
|
||||
@@ -851,11 +851,16 @@ export function initTextGenSettings() {
|
||||
$('#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
|
||||
if (json_schema_string) {
|
||||
try {
|
||||
settings.json_schema = JSON.parse(json_schema_string);
|
||||
} catch {
|
||||
settings.json_schema = null;
|
||||
}
|
||||
} else {
|
||||
settings.json_schema = null;
|
||||
}
|
||||
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
@@ -1152,8 +1157,8 @@ function setSettingByName(setting, value, trigger) {
|
||||
}
|
||||
|
||||
if ('json_schema' === setting) {
|
||||
settings.json_schema = value ?? {};
|
||||
$('#tabby_json_schema').val(JSON.stringify(settings.json_schema, null, 2));
|
||||
settings.json_schema = value ?? null;
|
||||
$('#tabby_json_schema').val(value ? JSON.stringify(settings.json_schema, null, 2) : '');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1555,8 +1560,8 @@ export async function getTextGenGenerationData(finalPrompt, maxTokens, isImperso
|
||||
'seed': settings.seed >= 0 ? settings.seed : undefined,
|
||||
'guidance_scale': cfgValues?.guidanceScale?.value ?? settings.guidance_scale ?? 1,
|
||||
'negative_prompt': cfgValues?.negativePrompt ?? substituteParams(settings.negative_prompt) ?? '',
|
||||
'grammar_string': settings.grammar_string,
|
||||
'json_schema': [TABBY, LLAMACPP].includes(settings.type) ? settings.json_schema : undefined,
|
||||
'grammar_string': settings.grammar_string || undefined,
|
||||
'json_schema': [TABBY, LLAMACPP].includes(settings.type) && settings.json_schema ? settings.json_schema : undefined,
|
||||
// llama.cpp aliases. In case someone wants to use LM Studio as Text Completion API
|
||||
'repeat_penalty': settings.rep_pen,
|
||||
'repeat_last_n': settings.rep_pen_range,
|
||||
@@ -1597,8 +1602,8 @@ export async function getTextGenGenerationData(finalPrompt, maxTokens, isImperso
|
||||
'min_tokens': settings.min_length,
|
||||
'skip_special_tokens': settings.skip_special_tokens,
|
||||
'spaces_between_special_tokens': settings.spaces_between_special_tokens,
|
||||
'guided_grammar': settings.grammar_string,
|
||||
'guided_json': settings.json_schema,
|
||||
'guided_grammar': settings.grammar_string || undefined,
|
||||
'guided_json': settings.json_schema || undefined,
|
||||
'early_stopping': false, // hacks
|
||||
'include_stop_str_in_output': false,
|
||||
'dynatemp_min': dynatemp ? settings.min_temp : undefined,
|
||||
@@ -1622,7 +1627,7 @@ export async function getTextGenGenerationData(finalPrompt, maxTokens, isImperso
|
||||
}
|
||||
|
||||
if (settings.type === KOBOLDCPP) {
|
||||
params.grammar = settings.grammar_string;
|
||||
params.grammar = settings.grammar_string || undefined;
|
||||
params.trim_stop = true;
|
||||
}
|
||||
|
||||
@@ -1691,17 +1696,19 @@ export async function getTextGenGenerationData(finalPrompt, maxTokens, isImperso
|
||||
}
|
||||
}
|
||||
|
||||
await eventSource.emit(event_types.TEXT_COMPLETION_SETTINGS_READY, params);
|
||||
|
||||
// Grammar conflicts with with json_schema
|
||||
if (settings.type === LLAMACPP) {
|
||||
if (params.json_schema && Object.keys(params.json_schema).length > 0) {
|
||||
if ([LLAMACPP, APHRODITE].includes(settings.type)) {
|
||||
if (settings.json_schema && isObject(settings.json_schema)) {
|
||||
delete params.grammar_string;
|
||||
delete params.grammar;
|
||||
delete params.guided_grammar;
|
||||
} else {
|
||||
delete params.json_schema;
|
||||
delete params.guided_json;
|
||||
}
|
||||
}
|
||||
|
||||
await eventSource.emit(event_types.TEXT_COMPLETION_SETTINGS_READY, params);
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ export const navigation_option = {
|
||||
* @param {any} item The item to check.
|
||||
* @returns {boolean} True if the item is an object, false otherwise.
|
||||
*/
|
||||
function isObject(item) {
|
||||
export function isObject(item) {
|
||||
return (item && typeof item === 'object' && !Array.isArray(item));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user