Skip to content

Commit

Permalink
fix: splicitly set json format in the request when defaulting to it (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelgj authored Nov 15, 2024
1 parent cb919c5 commit 56a88bb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions js/ai/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ export async function generate<
| GenerateOptions<O, CustomOptions>
| PromiseLike<GenerateOptions<O, CustomOptions>>
): Promise<GenerateResponse<z.infer<O>>> {
const resolvedOptions: GenerateOptions<O, CustomOptions> =
await Promise.resolve(options);
const resolvedOptions: GenerateOptions<O, CustomOptions> = {
...(await Promise.resolve(options)),
};
const resolvedModel = await resolveModel(registry, resolvedOptions.model);

const tools = await toolsToActionRefs(registry, resolvedOptions.tools);
Expand All @@ -248,6 +249,10 @@ export async function generate<
jsonSchema: resolvedOptions.output?.jsonSchema,
});

// If is schema is set but format is not explicitly set, default to `json` format.
if (resolvedOptions.output?.schema && !resolvedOptions.output?.format) {
resolvedOptions.output.format = 'json';
}
const resolvedFormat = await resolveFormat(registry, resolvedOptions.output);
const instructions = resolveInstructions(
resolvedFormat,
Expand Down

0 comments on commit 56a88bb

Please sign in to comment.