Fix json schema use for openAI compat CUSTOM endpoints in several use paths (#5561)

* pass jsonSchema options through sendStreamingRequest in Generate

* translate json_schema to response_format for CUSTOM chat completion source

* pass jsonSchema through generateGroupWrapper params in group chat generation
This commit is contained in:
Reithan
2026-04-30 13:38:01 -07:00
committed by GitHub
parent 5512473b29
commit 338e35fc8a
2 changed files with 12 additions and 2 deletions
+2 -2
View File
@@ -4290,7 +4290,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
if (selected_group && !is_group_generating) { if (selected_group && !is_group_generating) {
if (!dryRun) { if (!dryRun) {
// Returns the promise that generateGroupWrapper returns; resolves when generation is done // Returns the promise that generateGroupWrapper returns; resolves when generation is done
return generateGroupWrapper(false, type, { quiet_prompt, force_chid, signal: abortController.signal, quietImage }); return generateGroupWrapper(false, type, { quiet_prompt, force_chid, signal: abortController.signal, quietImage, jsonSchema });
} }
const characterIndexMap = new Map(characters.map((char, index) => [char.avatar, index])); const characterIndexMap = new Map(characters.map((char, index) => [char.avatar, index]));
@@ -5330,7 +5330,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
streamingProcessor.firstMessageText = ''; streamingProcessor.firstMessageText = '';
} }
streamingProcessor.generator = await sendStreamingRequest(type, generate_data); streamingProcessor.generator = await sendStreamingRequest(type, generate_data, { jsonSchema });
hideSwipeButtons(); hideSwipeButtons();
let getMessage = await streamingProcessor.generate(); let getMessage = await streamingProcessor.generate();
@@ -2319,6 +2319,16 @@ router.post('/generate', async function (request, response) {
mergeObjectWithYaml(bodyParams, request.body.custom_include_body); mergeObjectWithYaml(bodyParams, request.body.custom_include_body);
mergeObjectWithYaml(headers, request.body.custom_include_headers); mergeObjectWithYaml(headers, request.body.custom_include_headers);
embedOpenRouterMedia(request.body.messages, { audio: true, video: false }); embedOpenRouterMedia(request.body.messages, { audio: true, video: false });
if (request.body.json_schema) {
bodyParams['response_format'] = {
type: 'json_schema',
json_schema: {
name: request.body.json_schema.name,
strict: request.body.json_schema.strict ?? true,
schema: request.body.json_schema.value,
},
};
}
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.PERPLEXITY) { } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.PERPLEXITY) {
apiUrl = API_PERPLEXITY; apiUrl = API_PERPLEXITY;
apiKey = readSecret(request.user.directories, SECRET_KEYS.PERPLEXITY, request.body.secret_id); apiKey = readSecret(request.user.directories, SECRET_KEYS.PERPLEXITY, request.body.secret_id);