From e9d86097ac79632fb0c2db32e8f89f3f2e251c2e Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Fri, 13 Mar 2026 12:11:57 -0400 Subject: [PATCH] fix: Make sure params get passed through for compiled prompt --- js/src/logger.ts | 52 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/js/src/logger.ts b/js/src/logger.ts index e87d4bff..91d94d4d 100644 --- a/js/src/logger.ts +++ b/js/src/logger.ts @@ -75,6 +75,7 @@ import { type PromptSessionEventType as PromptSessionEvent, type RepoInfoType as RepoInfo, type PromptBlockDataType as PromptBlockData, + type ResponseFormatJsonSchemaType as ResponseFormatJsonSchema, } from "./generated_types"; const BRAINTRUST_ATTACHMENT = @@ -7052,10 +7053,31 @@ export class Dataset< } } +type CompiledPromptResponseFormat = + Exclude extends infer ResponseFormat + ? ResponseFormat extends { + type: "json_schema"; + json_schema: infer JsonSchema; + } + ? Omit & { + json_schema: Omit< + Extract, + "schema" + > & { + schema?: Record; + }; + } + : ResponseFormat + : never; + export type CompiledPromptParams = Omit< NonNullable["params"], - "use_cache" -> & { model: NonNullable["model"]> }; + "use_cache" | "response_format" +> & + Omit & { + response_format?: CompiledPromptResponseFormat; + model: NonNullable["model"]>; + }; export type ChatPrompt = { messages: OpenAIMessage[]; @@ -7386,19 +7408,21 @@ export class Prompt< ): CompiledPrompt { const { flavor } = options; - const params = { - ...this.defaults, - ...Object.fromEntries( - Object.entries(this.options.params || {}).filter( - ([k, _v]) => !BRAINTRUST_PARAMS.includes(k), + const params = Object.fromEntries( + Object.entries({ + ...this.defaults, + ...Object.fromEntries( + Object.entries(this.options.params || {}).filter( + ([k, _v]) => !BRAINTRUST_PARAMS.includes(k), + ), ), - ), - ...(!isEmpty(this.options.model) - ? { - model: this.options.model, - } - : {}), - }; + ...(!isEmpty(this.options.model) + ? { + model: this.options.model, + } + : {}), + }).filter(([key, value]) => key !== "response_format" || value !== null), + ); if (!("model" in params) || isEmpty(params.model)) { throw new Error(