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

338e35fc8af4f5e10df2f2a98843314d5350c49d

Reithan <bo122081@hotmail.com>

Signed
2 files changed, +12 -2Ignore whitespace
public/script.js+2 -2
@@ -4290,7 +4290,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
4290 if (selected_group && !is_group_generating) {4290 if (selected_group && !is_group_generating) {
4291 if (!dryRun) {4291 if (!dryRun) {
4292 // Returns the promise that generateGroupWrapper returns; resolves when generation is done4292 // Returns the promise that generateGroupWrapper returns; resolves when generation is done
4293 return generateGroupWrapper(false, type, { quiet_prompt, force_chid, signal: abortController.signal, quietImage });4293 return generateGroupWrapper(false, type, { quiet_prompt, force_chid, signal: abortController.signal, quietImage, jsonSchema });
4294 }4294 }
42954295
4296 const characterIndexMap = new Map(characters.map((char, index) => [char.avatar, index]));4296 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
5330 streamingProcessor.firstMessageText = '';5330 streamingProcessor.firstMessageText = '';
5331 }5331 }
53325332
5333 streamingProcessor.generator = await sendStreamingRequest(type, generate_data);5333 streamingProcessor.generator = await sendStreamingRequest(type, generate_data, { jsonSchema });
53345334
5335 hideSwipeButtons();5335 hideSwipeButtons();
5336 let getMessage = await streamingProcessor.generate();5336 let getMessage = await streamingProcessor.generate();
src/endpoints/backends/chat-completions.js+10 -0
@@ -2319,6 +2319,16 @@ router.post('/generate', async function (request, response) {
2319 mergeObjectWithYaml(bodyParams, request.body.custom_include_body);2319 mergeObjectWithYaml(bodyParams, request.body.custom_include_body);
2320 mergeObjectWithYaml(headers, request.body.custom_include_headers);2320 mergeObjectWithYaml(headers, request.body.custom_include_headers);
2321 embedOpenRouterMedia(request.body.messages, { audio: true, video: false });2321 embedOpenRouterMedia(request.body.messages, { audio: true, video: false });
2322 if (request.body.json_schema) {
2323 bodyParams['response_format'] = {
2324 type: 'json_schema',
2325 json_schema: {
2326 name: request.body.json_schema.name,
2327 strict: request.body.json_schema.strict ?? true,
2328 schema: request.body.json_schema.value,
2329 },
2330 };
2331 }
2322 } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.PERPLEXITY) {2332 } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.PERPLEXITY) {
2323 apiUrl = API_PERPLEXITY;2333 apiUrl = API_PERPLEXITY;
2324 apiKey = readSecret(request.user.directories, SECRET_KEYS.PERPLEXITY, request.body.secret_id);2334 apiKey = readSecret(request.user.directories, SECRET_KEYS.PERPLEXITY, request.body.secret_id);