fix: force tool calls when outputFormat is json_schema
When structured output is requested, the model must call the StructuredOutput tool instead of responding with plain text. Changes: - Add toolChoice parameter to LLM.StreamInput - Pass toolChoice: "required" to streamText when outputFormat is json_schema - This forces the model to call a tool, ensuring structured output is capturedpull/8161/head
parent
34f9feb12d
commit
0e8f7694ed
|
|
@ -28,6 +28,7 @@ export namespace LLM {
|
|||
small?: boolean
|
||||
tools: Record<string, Tool>
|
||||
retries?: number
|
||||
toolChoice?: "auto" | "required" | "none"
|
||||
}
|
||||
|
||||
export type StreamOutput = StreamTextResult<ToolSet, unknown>
|
||||
|
|
@ -146,6 +147,7 @@ export namespace LLM {
|
|||
providerOptions: ProviderTransform.providerOptions(input.model, params.options),
|
||||
activeTools: Object.keys(tools).filter((x) => x !== "invalid"),
|
||||
tools,
|
||||
toolChoice: input.toolChoice,
|
||||
maxOutputTokens,
|
||||
abortSignal: input.abort,
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -573,6 +573,7 @@ export namespace SessionPrompt {
|
|||
],
|
||||
tools,
|
||||
model,
|
||||
toolChoice: outputFormat.type === "json_schema" ? "required" : undefined,
|
||||
})
|
||||
|
||||
// Handle structured output logic
|
||||
|
|
|
|||
Loading…
Reference in New Issue