LLM: allow sparse optional edits — disable strict JSON schema
The Responses API via Vercel AI Gateway requires `required` to
include every key when `strict:true`. Our TweakEditsSchema has 7
optional song knobs, so sparse edits (e.g. only {brightness: 0.3})
were rejected with 400: Missing 'arrangement'.
- src/llm/llmTweak.js: createOpenAI({ strictJsonSchema: false }) so
the gateway accepts optional properties; keeps zod validation +
clampEdits as the real guardrail.
- src/llm/spec.js: drop .strict() on TweakEditsSchema — extra keys
are stripped rather than erroring, more robust against model drift.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -97,6 +97,7 @@ export async function requestSongTweak({ spec, track, look, hint = '', config =
|
|||||||
baseURL: isDev ? '/__llm/v1' : cfg.gatewayUrl,
|
baseURL: isDev ? '/__llm/v1' : cfg.gatewayUrl,
|
||||||
apiKey: cfg.apiKey,
|
apiKey: cfg.apiKey,
|
||||||
fetch: isDev ? proxyFetch : undefined,
|
fetch: isDev ? proxyFetch : undefined,
|
||||||
|
strictJsonSchema: false,
|
||||||
});
|
});
|
||||||
const modelId = cfg.model;
|
const modelId = cfg.model;
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export const TweakEditsSchema = z.object({
|
|||||||
dynamics: z.number().min(0).max(1).optional(),
|
dynamics: z.number().min(0).max(1).optional(),
|
||||||
transition: z.number().min(0).max(1).optional(),
|
transition: z.number().min(0).max(1).optional(),
|
||||||
arrangement: z.enum(ARRANGEMENT_VALUES).optional(),
|
arrangement: z.enum(ARRANGEMENT_VALUES).optional(),
|
||||||
}).strict();
|
});
|
||||||
|
|
||||||
export const TweakResultSchema = z.object({
|
export const TweakResultSchema = z.object({
|
||||||
rationale: z.string().min(1).max(800),
|
rationale: z.string().min(1).max(800),
|
||||||
|
|||||||
Reference in New Issue
Block a user