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
42904290 if (selected_group && !is_group_generating) {
42914291 if (!dryRun) {
42924292 // Returns the promise that generateGroupWrapper returns; resolves when generation is done
42934293 return generateGroupWrapper(false, type, { quiet_prompt, force_chid, signal: abortController.signal, quietImage, jsonSchema });
42944294 }
42954295
42964296 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
53305330 streamingProcessor.firstMessageText = '';
53315331 }
53325332
53335333 streamingProcessor.generator = await sendStreamingRequest(type, generate_data, { jsonSchema });
53345334
53355335 hideSwipeButtons();
53365336 let getMessage = await streamingProcessor.generate();
src/endpoints/backends/chat-completions.js+10 -0
@@ -2319,6 +2319,16 @@ router.post('/generate', async function (request, response) {
23192319 mergeObjectWithYaml(bodyParams, request.body.custom_include_body);
23202320 mergeObjectWithYaml(headers, request.body.custom_include_headers);
23212321 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+ }
23222332 } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.PERPLEXITY) {
23232333 apiUrl = API_PERPLEXITY;
23242334 apiKey = readSecret(request.user.directories, SECRET_KEYS.PERPLEXITY, request.body.secret_id);