Skip to content

Commit beeabe2

Browse files
fix(mistral): pass through reasoning effort (anomalyco#42164)
Co-authored-by: Aiden Cline <[email protected]>
1 parent 502310f commit beeabe2

2 files changed

Lines changed: 42 additions & 11 deletions

File tree

‎packages/core/test/provider-mistral.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@ test("Mistral sends promptCacheKey as prompt_cache_key", async () => {
2727
expect(body?.prompt_cache_key).toBe("session-123")
2828
})
2929

30+
test("Mistral passes through unknown reasoning effort", async () => {
31+
let body: Record<string, unknown> | undefined
32+
const mockFetch = Object.assign(
33+
async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => {
34+
body = JSON.parse(String(init?.body))
35+
return Response.json({
36+
id: "response-1",
37+
created: 0,
38+
model: "mistral-large-latest",
39+
object: "chat.completion",
40+
choices: [{ index: 0, message: { role: "assistant", content: "Hello" }, finish_reason: "stop" }],
41+
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
42+
})
43+
},
44+
{ preconnect: fetch.preconnect },
45+
)
46+
const model = createMistral({ apiKey: "test", fetch: mockFetch })("mistral-large-latest")
47+
48+
await model.doGenerate({
49+
prompt: [{ role: "user", content: [{ type: "text", text: "Hello" }] }],
50+
providerOptions: { mistral: { reasoningEffort: "custom" } },
51+
})
52+
53+
expect(body?.reasoning_effort).toBe("custom")
54+
})
55+
3056
test("Mistral round-trips native reasoning in assistant history", async () => {
3157
let body: { messages?: unknown[] } | undefined
3258
const mockFetch = Object.assign(

‎patches/@ai-sdk%[email protected]‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ diff --git a/dist/index.d.mts b/dist/index.d.mts
22
index 1bde0b9f8cbe6771a52c1041095c9dddfe8e5b6c..0ca2ffb2a0c9327aed5ddcf0004500dc8b42569f 100644
33
--- a/dist/index.d.mts
44
+++ b/dist/index.d.mts
5-
@@ -14,6 +14,7 @@ declare const mistralLanguageModelOptions: z.ZodObject<{
6-
none: "none";
7-
high: "high";
8-
}>>;
5+
@@ -13,7 +13,5 @@ declare const mistralLanguageModelOptions: z.ZodObject<{
6+
- reasoningEffort: z.ZodOptional<z.ZodEnum<{
7+
- none: "none";
8+
- high: "high";
9+
- }>>;
10+
+ reasoningEffort: z.ZodOptional<z.ZodString>;
911
+ promptCacheKey: z.ZodOptional<z.ZodString>;
1012
}, z.core.$strip>;
1113
type MistralLanguageModelOptions = z.infer<typeof mistralLanguageModelOptions>;
@@ -14,10 +16,12 @@ diff --git a/dist/index.d.ts b/dist/index.d.ts
1416
index 1bde0b9f8cbe6771a52c1041095c9dddfe8e5b6c..0ca2ffb2a0c9327aed5ddcf0004500dc8b42569f 100644
1517
--- a/dist/index.d.ts
1618
+++ b/dist/index.d.ts
17-
@@ -14,6 +14,7 @@ declare const mistralLanguageModelOptions: z.ZodObject<{
18-
none: "none";
19-
high: "high";
20-
}>>;
19+
@@ -13,7 +13,5 @@ declare const mistralLanguageModelOptions: z.ZodObject<{
20+
- reasoningEffort: z.ZodOptional<z.ZodEnum<{
21+
- none: "none";
22+
- high: "high";
23+
- }>>;
24+
+ reasoningEffort: z.ZodOptional<z.ZodString>;
2125
+ promptCacheKey: z.ZodOptional<z.ZodString>;
2226
}, z.core.$strip>;
2327
type MistralLanguageModelOptions = z.infer<typeof mistralLanguageModelOptions>;
@@ -69,7 +73,7 @@ index d3f904c12a1d582cc7b9e9a2d30273e1a8505b28..267f34e20ea392b7a85ad5259d72d506
6973
* - `'none'`: Disable reasoning
7074
*/
7175
- reasoningEffort: import_v4.z.enum(["high", "none"]).optional()
72-
+ reasoningEffort: import_v4.z.enum(["high", "none"]).optional(),
76+
+ reasoningEffort: import_v4.z.string().optional(),
7377
+ promptCacheKey: import_v4.z.string().optional()
7478
});
7579

@@ -268,7 +272,7 @@ index d2eff622c1b84a96bdeb4012cb0206a33012a04d..3bff11ddd6136ada45809568828cbc8f
268272
* - `'none'`: Disable reasoning
269273
*/
270274
- reasoningEffort: z.enum(["high", "none"]).optional()
271-
+ reasoningEffort: z.enum(["high", "none"]).optional(),
275+
+ reasoningEffort: z.string().optional(),
272276
+ promptCacheKey: z.string().optional()
273277
});
274278

@@ -655,7 +659,8 @@ index 54b29c08517d348995b6ca093b11160e453d5c8b..de30c3e7d924889339e38b1067cb26e9
655659
@@ -64,6 +64,11 @@ export const mistralLanguageModelOptions = z.object({
656660
* - `'none'`: Disable reasoning
657661
*/
658-
reasoningEffort: z.enum(['high', 'none']).optional(),
662+
- reasoningEffort: z.enum(['high', 'none']).optional(),
663+
+ reasoningEffort: z.string().optional(),
659664
+
660665
+ /**
661666
+ * A stable identifier used to route requests with shared prompt prefixes.

0 commit comments

Comments
 (0)