mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-24 06:45:22 +00:00
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 captured
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user