fix(provider): normalize Mistral family tool call IDs (#37982)
Co-authored-by: tobwen <1864057+tobwen@users.noreply.github.com>
This commit is contained in:
parent
5a8ee27254
commit
3033afba51
2 changed files with 51 additions and 2 deletions
|
|
@ -227,10 +227,10 @@ function normalizeMessages(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const modelID = model.api.id.toLowerCase()
|
||||||
if (
|
if (
|
||||||
model.providerID === "mistral" ||
|
model.providerID === "mistral" ||
|
||||||
model.api.id.toLowerCase().includes("mistral") ||
|
["mistral", "devstral", "codestral", "pixtral", "mixtral"].some((family) => modelID.includes(family))
|
||||||
model.api.id.toLowerCase().includes("devstral")
|
|
||||||
) {
|
) {
|
||||||
const scrub = (id: string) => {
|
const scrub = (id: string) => {
|
||||||
return id
|
return id
|
||||||
|
|
|
||||||
|
|
@ -1672,6 +1672,55 @@ describe("ProviderTransform.schema - moonshot $ref siblings", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("ProviderTransform.message - Mistral tool call IDs", () => {
|
||||||
|
test.each(["codestral-latest", "pixtral-large-latest", "open-mixtral-8x22b"])(
|
||||||
|
"normalizes IDs for custom OpenAI-compatible %s models",
|
||||||
|
(id) => {
|
||||||
|
const result = ProviderTransform.message(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
role: "assistant",
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: "tool-call",
|
||||||
|
toolCallId: "toolu_01CBhTTz95qkd9LJMdC9sf8t",
|
||||||
|
toolName: "read",
|
||||||
|
input: { filePath: "/tmp/test" },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: "tool",
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: "tool-result",
|
||||||
|
toolCallId: "toolu_01CBhTTz95qkd9LJMdC9sf8t",
|
||||||
|
toolName: "read",
|
||||||
|
output: { type: "text", value: "test" },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
] as any,
|
||||||
|
{
|
||||||
|
id: `custom/${id}`,
|
||||||
|
providerID: "custom",
|
||||||
|
api: {
|
||||||
|
id,
|
||||||
|
url: "https://example.com/v1",
|
||||||
|
npm: "@ai-sdk/openai-compatible",
|
||||||
|
},
|
||||||
|
} as any,
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(result).toMatchObject([
|
||||||
|
{ role: "assistant", content: [{ type: "tool-call", toolCallId: "toolu01CB" }] },
|
||||||
|
{ role: "tool", content: [{ type: "tool-result", toolCallId: "toolu01CB" }] },
|
||||||
|
])
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
describe("ProviderTransform.message - DeepSeek reasoning content", () => {
|
describe("ProviderTransform.message - DeepSeek reasoning content", () => {
|
||||||
test("DeepSeek with tool calls includes reasoning_content in providerOptions", () => {
|
test("DeepSeek with tool calls includes reasoning_content in providerOptions", () => {
|
||||||
const msgs = [
|
const msgs = [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue