mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 07:10:23 +00:00
Mistral: enable reasoning_effort for mistral-small-latest
Made-with: Cursor
This commit is contained in:
committed by
Ayaan Zaidi
parent
de2182877a
commit
68bfc6fcf5
@@ -12,32 +12,97 @@ export {
|
||||
|
||||
const MISTRAL_MAX_TOKENS_FIELD = "max_tokens";
|
||||
|
||||
export const MISTRAL_MODEL_COMPAT_PATCH = {
|
||||
/** Transport-only flags merged for hinted Mistral routes; omits reasoning so `mistral-small-latest` is not clobbered after normalization. */
|
||||
export const MISTRAL_MODEL_TRANSPORT_PATCH = {
|
||||
supportsStore: false,
|
||||
supportsReasoningEffort: false,
|
||||
maxTokensField: MISTRAL_MAX_TOKENS_FIELD,
|
||||
} as const satisfies {
|
||||
supportsStore: boolean;
|
||||
supportsReasoningEffort: boolean;
|
||||
maxTokensField: "max_tokens";
|
||||
};
|
||||
|
||||
export function applyMistralModelCompat<T extends { compat?: unknown }>(model: T): T {
|
||||
/** Resolves to Mistral Chat Completions `reasoning_effort` (`none` | `high`). */
|
||||
export const MISTRAL_SMALL_LATEST_REASONING_EFFORT_MAP: Record<string, string> = {
|
||||
off: "none",
|
||||
minimal: "none",
|
||||
low: "high",
|
||||
medium: "high",
|
||||
high: "high",
|
||||
xhigh: "high",
|
||||
adaptive: "high",
|
||||
};
|
||||
|
||||
export const MISTRAL_SMALL_LATEST_ID = "mistral-small-latest";
|
||||
|
||||
function mistralReasoningCompatForModelId(modelId: string | undefined): {
|
||||
supportsReasoningEffort: boolean;
|
||||
reasoningEffortMap?: Record<string, string>;
|
||||
} {
|
||||
if (modelId === MISTRAL_SMALL_LATEST_ID) {
|
||||
return {
|
||||
supportsReasoningEffort: true,
|
||||
reasoningEffortMap: MISTRAL_SMALL_LATEST_REASONING_EFFORT_MAP,
|
||||
};
|
||||
}
|
||||
return { supportsReasoningEffort: false };
|
||||
}
|
||||
|
||||
export function resolveMistralCompatPatch(model: { id?: string }): {
|
||||
supportsStore: boolean;
|
||||
supportsReasoningEffort: boolean;
|
||||
maxTokensField: "max_tokens";
|
||||
reasoningEffortMap?: Record<string, string>;
|
||||
} {
|
||||
return {
|
||||
...MISTRAL_MODEL_TRANSPORT_PATCH,
|
||||
...mistralReasoningCompatForModelId(model.id),
|
||||
};
|
||||
}
|
||||
|
||||
function compatMatchesResolved(
|
||||
compat: Record<string, unknown> | undefined,
|
||||
modelId: string | undefined,
|
||||
): boolean {
|
||||
const expected = resolveMistralCompatPatch({ id: modelId });
|
||||
for (const [key, value] of Object.entries(expected)) {
|
||||
if (key === "reasoningEffortMap") {
|
||||
const a = compat?.[key];
|
||||
const b = value;
|
||||
if (a === b) {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
a &&
|
||||
b &&
|
||||
typeof a === "object" &&
|
||||
typeof b === "object" &&
|
||||
JSON.stringify(a) === JSON.stringify(b)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (compat?.[key] !== value) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function applyMistralModelCompat<T extends { compat?: unknown; id?: string }>(model: T): T {
|
||||
const compat =
|
||||
model.compat && typeof model.compat === "object"
|
||||
? (model.compat as Record<string, unknown>)
|
||||
: undefined;
|
||||
if (
|
||||
compat &&
|
||||
Object.entries(MISTRAL_MODEL_COMPAT_PATCH).every(([key, value]) => compat[key] === value)
|
||||
) {
|
||||
if (compatMatchesResolved(compat, model.id)) {
|
||||
return model;
|
||||
}
|
||||
const patch = resolveMistralCompatPatch(model);
|
||||
return {
|
||||
...model,
|
||||
compat: {
|
||||
...compat,
|
||||
...MISTRAL_MODEL_COMPAT_PATCH,
|
||||
...patch,
|
||||
} as T extends { compat?: infer TCompat } ? TCompat : never,
|
||||
} as T;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user