Enable tool streaming for newer Z.ai models (#2732)

This commit is contained in:
Kao Félix
2026-03-31 13:28:24 +01:00
committed by GitHub
parent d86122cbd3
commit 758ede4da0
5 changed files with 183 additions and 20 deletions

View File

@@ -395,6 +395,9 @@ function buildParams(model: Model<"openai-completions">, context: Context, optio
if (context.tools) {
params.tools = convertTools(context.tools, compat);
if (compat.zaiToolStream) {
(params as any).tool_stream = true;
}
} else if (hasToolHistory(context.messages)) {
// Anthropic (via LiteLLM/proxy) requires tools param when conversation has tool_calls/tool_results
params.tools = [];
@@ -835,6 +838,7 @@ function detectCompat(model: Model<"openai-completions">): Required<OpenAIComple
: "openai",
openRouterRouting: {},
vercelGatewayRouting: {},
zaiToolStream: false,
supportsStrictMode: true,
};
}
@@ -861,6 +865,7 @@ function getCompat(model: Model<"openai-completions">): Required<OpenAICompletio
thinkingFormat: model.compat.thinkingFormat ?? detected.thinkingFormat,
openRouterRouting: model.compat.openRouterRouting ?? {},
vercelGatewayRouting: model.compat.vercelGatewayRouting ?? detected.vercelGatewayRouting,
zaiToolStream: model.compat.zaiToolStream ?? detected.zaiToolStream,
supportsStrictMode: model.compat.supportsStrictMode ?? detected.supportsStrictMode,
};
}

View File

@@ -277,6 +277,8 @@ export interface OpenAICompletionsCompat {
openRouterRouting?: OpenRouterRouting;
/** Vercel AI Gateway routing preferences. Only used when baseUrl points to Vercel AI Gateway. */
vercelGatewayRouting?: VercelGatewayRouting;
/** Whether z.ai supports top-level `tool_stream: true` for streaming tool call deltas. Default: false. */
zaiToolStream?: boolean;
/** Whether the provider supports the `strict` field in tool definitions. Default: true. */
supportsStrictMode?: boolean;
}