Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion packages/actions/src/prepare-request-body.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { describe, expect, test } from "vitest";

import { models } from "@llmgateway/models";

import {
hashPromptCacheKey,
hashSessionCacheKey,
Expand Down Expand Up @@ -1101,6 +1103,59 @@ describe("prepareRequestBody - Moonshot thinking", () => {
expect(requestBody.max_completion_tokens).toBe(4096);
expect(requestBody.max_tokens).toBeUndefined();
});

type Effort = Parameters<typeof prepareRequestBody>[14];
const xaiEffortCases: Array<
[Parameters<typeof prepareRequestBody>[0], string, Extract<Effort, string>]
> = [
// xAI mappings that declare reasoning: true but previously omitted
// reasoning_effort from supportedParameters, silently dropping any
// effort value before the request was built (#3436, #3403).
["azure-ai-foundry", "grok-4-3", "medium"],
["azure-ai-foundry", "grok-4-1-fast-reasoning", "high"],
["vertex-openai", "grok-4-20-reasoning", "low"],
["xai", "grok-4", "high"],
["xai", "grok-4-20-beta-0309-reasoning", "medium"],
["xai", "grok-build-0-1", "low"],
];

test.each(xaiEffortCases)(
"forwards reasoning_effort for %s/%s once declared in supportedParameters",
async (provider, model, effort) => {
// Direct capability assertion on the mapping itself: the fix's
// whole point is that these mappings now declare
// reasoning_effort in supportedParameters. A serialization-only
// test could keep passing while the capability check silently
// regresses (e.g. a refactor that stops reading
// supportedParameters) — asserting the array directly catches
// that class of regression.
const modelDef = models.find((m) => m.id === model);
const mapping = modelDef?.providers.find(
(p) => p.providerId === provider,
);
expect(mapping?.supportedParameters).toContain("reasoning_effort");

const requestBody = (await prepareRequestBody(
provider,
model,
null,
model,
[{ role: "user", content: "Hello!" }],
false, // stream
undefined, // temperature
undefined, // max_tokens
undefined, // top_p
undefined, // frequency_penalty
undefined, // presence_penalty
undefined, // response_format
undefined, // tools
undefined, // tool_choice
effort,
true, // supportsReasoning
)) as unknown as Record<string, unknown>;
expect(requestBody.reasoning_effort).toBe(effort);
},
);
});

describe("prepareRequestBody - Alibaba thinking", () => {
Expand Down Expand Up @@ -4304,7 +4359,7 @@ describe("prepareRequestBody - max_tokens forwarding", () => {
expect(requestBody.max_tokens).toBe(8192);
expect(requestBody.max_completion_tokens).toBeUndefined();
expect(requestBody.top_p).toBe(0.9);
expect(requestBody.reasoning_effort).toBeUndefined();
expect(requestBody.reasoning_effort).toBe("medium");
expect(requestBody.inferenceConfig).toBeUndefined();
});
});
Expand Down
51 changes: 46 additions & 5 deletions packages/models/src/models/xai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,15 @@ export const xaiModels = [
reasoning: true,
tools: true,
jsonOutput: true,
supportedParameters: xaiSupportedParamsNoFreqPresence,
supportedParameters: [
"temperature",
"max_tokens",
"top_p",
"response_format",
"tools",
"tool_choice",
"reasoning_effort",
],
},
],
},
Expand Down Expand Up @@ -425,7 +433,15 @@ export const xaiModels = [
reasoningOutput: "omit",
tools: true,
jsonOutput: true,
supportedParameters: xaiSupportedParamsNoFreqPresence,
supportedParameters: [
"temperature",
"max_tokens",
"top_p",
"response_format",
"tools",
"tool_choice",
"reasoning_effort",
],
},
],
},
Expand Down Expand Up @@ -573,7 +589,15 @@ export const xaiModels = [
reasoning: true,
tools: true,
jsonOutput: true,
supportedParameters: xaiSupportedParamsNoFreqPresence,
supportedParameters: [
"temperature",
"max_tokens",
"top_p",
"response_format",
"tools",
"tool_choice",
"reasoning_effort",
],
},
],
},
Expand Down Expand Up @@ -641,7 +665,15 @@ export const xaiModels = [
reasoningOutput: "omit",
tools: true,
jsonOutput: true,
supportedParameters: xaiSupportedParamsNoFreqPresence,
supportedParameters: [
"temperature",
"max_tokens",
"top_p",
"response_format",
"tools",
"tool_choice",
"reasoning_effort",
],
},
],
},
Expand Down Expand Up @@ -770,6 +802,7 @@ export const xaiModels = [
"top_p",
"tools",
"tool_choice",
"reasoning_effort",
],
},
],
Expand Down Expand Up @@ -981,7 +1014,15 @@ export const xaiModels = [
tools: true,
jsonOutput: true,
reasoning: true,
supportedParameters: xaiSupportedParamsNoFreqPresence,
supportedParameters: [
"temperature",
"max_tokens",
"top_p",
"response_format",
"tools",
"tool_choice",
"reasoning_effort",
],
},
],
},
Expand Down
Loading