Repository navigation
fix(chat): strip replayed reasoning_content from message history for Mistral Chat #8432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2b16693
0818fa8
0059435
a63682b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ import type { OcxProviderConfig } from "../../types"; | |
| const MISTRAL_CHAT_POLICY = { | ||
| rename: { max_completion_tokens: "max_tokens" }, | ||
| omit: ["user", "store", "thinking", "include_reasoning", "reasoning", "top_k"], | ||
| /** Replayed inside message history by reasoning-capable Chat clients; Mistral's schema rejects them. */ | ||
| omitMessageFields: ["reasoning_content"], | ||
| } as const; | ||
|
|
||
| /** Final wire projection shared by native and translated Chat; caller objects are not mutated. */ | ||
|
|
@@ -15,6 +17,20 @@ export function applyChatDestinationPolicy(body: Record<string, unknown>, provid | |
| delete body[source]; | ||
| } | ||
| for (const field of MISTRAL_CHAT_POLICY.omit) delete body[field]; | ||
| const messages = body.messages; | ||
| if (Array.isArray(messages)) { | ||
| let sanitized: unknown[] | undefined; | ||
| for (let index = 0; index < messages.length; index++) { | ||
| const message = messages[index]; | ||
| if (message === null || typeof message !== "object" || Array.isArray(message)) continue; | ||
| const record = message as Record<string, unknown>; | ||
| if (!MISTRAL_CHAT_POLICY.omitMessageFields.some((field) => field in record)) continue; | ||
| const copy = { ...record }; | ||
| for (const field of MISTRAL_CHAT_POLICY.omitMessageFields) delete copy[field]; | ||
| (sanitized ??= [...messages])[index] = copy; | ||
| } | ||
| if (sanitized) body.messages = sanitized; | ||
|
Comment on lines
+30
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
|
|
||
| /** Native Chat normally preserves effort spelling; Mistral requires its declared model ladder. */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
rg -n -i 'native chat thinking replay|reasoning_content|mistral' docs-site/src/content/docs/reference/configuration/providers.mdRepository: lidge-jun/opencodex
Length of output: 8797
Script executed:
Repository: lidge-jun/opencodex
Length of output: 16007
Script executed:
Repository: lidge-jun/opencodex
Length of output: 6140
Script executed:
Repository: lidge-jun/opencodex
Length of output: 13051
Add the Mistral exception to the native Chat replay section.
The section at
docs-site/src/content/docs/reference/configuration/providers.md:1939says supplied reasoning is preserved and omitted reasoning is restored. This contradicts the updated row and can mislead operators configuring Mistral-hosted DeepSeek models.Suggested fix