From 56a88bb21c3f006feaec1c1999c6e0a90d2ecb7d Mon Sep 17 00:00:00 2001 From: Pavel Jbanov Date: Fri, 15 Nov 2024 18:09:15 -0500 Subject: [PATCH] fix: splicitly set json format in the request when defaulting to it (#1317) --- js/ai/src/generate.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/js/ai/src/generate.ts b/js/ai/src/generate.ts index 9f4da9f7c..cb49c6d08 100755 --- a/js/ai/src/generate.ts +++ b/js/ai/src/generate.ts @@ -235,8 +235,9 @@ export async function generate< | GenerateOptions | PromiseLike> ): Promise>> { - const resolvedOptions: GenerateOptions = - await Promise.resolve(options); + const resolvedOptions: GenerateOptions = { + ...(await Promise.resolve(options)), + }; const resolvedModel = await resolveModel(registry, resolvedOptions.model); const tools = await toolsToActionRefs(registry, resolvedOptions.tools); @@ -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,