fix(ai): omit tools field instead of sending empty array (#3650)
DashScope / Aliyun Qwen (OpenAI-compatible) rejects `tools: []` with HTTP 400 `"[] is too short - 'tools'"`. Five providers used a truthy check (`if (context.tools)`) that treated an empty array as "send tools", so `pi --no-tools` produced `tools: []` in the request body. Matching the Google provider's pattern, we now guard on `context.tools.length > 0`: - openai-completions.ts - openai-responses.ts - openai-codex-responses.ts - azure-openai-responses.ts - anthropic.ts The openai-completions fallback that emits `tools: []` when the conversation has tool history (required by LiteLLM / Anthropic proxies) is preserved via the existing `else if (hasToolHistory)` branch. closes #3649 Co-authored-by: 槐聚 <huaiju@zbyte-inc.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com> Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
This commit is contained in:
@@ -877,7 +877,7 @@ function buildParams(
|
||||
params.temperature = options.temperature;
|
||||
}
|
||||
|
||||
if (context.tools) {
|
||||
if (context.tools && context.tools.length > 0) {
|
||||
params.tools = convertTools(
|
||||
context.tools,
|
||||
isOAuthToken,
|
||||
|
||||
@@ -236,7 +236,7 @@ function buildParams(
|
||||
params.temperature = options?.temperature;
|
||||
}
|
||||
|
||||
if (context.tools) {
|
||||
if (context.tools && context.tools.length > 0) {
|
||||
params.tools = convertResponsesTools(context.tools);
|
||||
}
|
||||
|
||||
|
||||
@@ -340,7 +340,7 @@ function buildRequestBody(
|
||||
body.service_tier = options.serviceTier;
|
||||
}
|
||||
|
||||
if (context.tools) {
|
||||
if (context.tools && context.tools.length > 0) {
|
||||
body.tools = convertResponsesTools(context.tools, { strict: null });
|
||||
}
|
||||
|
||||
|
||||
@@ -504,7 +504,7 @@ function buildParams(
|
||||
params.temperature = options.temperature;
|
||||
}
|
||||
|
||||
if (context.tools) {
|
||||
if (context.tools && context.tools.length > 0) {
|
||||
params.tools = convertTools(context.tools, compat);
|
||||
if (compat.zaiToolStream) {
|
||||
(params as any).tool_stream = true;
|
||||
|
||||
@@ -230,7 +230,7 @@ function buildParams(model: Model<"openai-responses">, context: Context, options
|
||||
params.service_tier = options.serviceTier;
|
||||
}
|
||||
|
||||
if (context.tools) {
|
||||
if (context.tools && context.tools.length > 0) {
|
||||
params.tools = convertResponsesTools(context.tools);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user