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
Signed| @@ -4290,7 +4290,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 4290 | 4290 | if (selected_group && !is_group_generating) { |
| 4291 | 4291 | if (!dryRun) { |
| 4292 | 4292 | // Returns the promise that generateGroupWrapper returns; resolves when generation is done |
| 4293 | 4293 | return generateGroupWrapper(false, type, { quiet_prompt, force_chid, signal: abortController.signal, quietImage, jsonSchema }); |
| 4294 | 4294 | } |
| 4295 | 4295 | |
| 4296 | 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 | 5330 | streamingProcessor.firstMessageText = ''; |
| 5331 | 5331 | } |
| 5332 | 5332 | |
| 5333 | 5333 | streamingProcessor.generator = await sendStreamingRequest(type, generate_data, { jsonSchema }); |
| 5334 | 5334 | |
| 5335 | 5335 | hideSwipeButtons(); |
| 5336 | 5336 | let getMessage = await streamingProcessor.generate(); |
| @@ -2319,6 +2319,16 @@ router.post('/generate', async function (request, response) { | ||
| 2319 | 2319 | mergeObjectWithYaml(bodyParams, request.body.custom_include_body); |
| 2320 | 2320 | mergeObjectWithYaml(headers, request.body.custom_include_headers); |
| 2321 | 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 | 2332 | } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.PERPLEXITY) { |
| 2323 | 2333 | apiUrl = API_PERPLEXITY; |
| 2324 | 2334 | apiKey = readSecret(request.user.directories, SECRET_KEYS.PERPLEXITY, request.body.secret_id); |