openpencil/scripts/ab-corpus/clients/minimax.ts
Fini 7d419cffd1 feat(ab-corpus): exponential backoff + bump retries=2 on ark/deepseek
ab-v3 left 36 ark empty + 15 timeout + 4 429 + 6 deepseek empty + 4
minimax timeout AFTER the existing retries=1 fired 88 times. Linear
backoff 250ms*(attempt+1) was too tight when stepping up to
retries=2 (500ms then 750ms isn't a typical Ark recovery window).

Switches to exponential 250ms*4^attempt — 250 / 1000 / 4000ms
spacing — and bumps ark + deepseek to retries=2. minimax opts in to
retries=1 (its 4 errors were wall-clock timeouts, not the model's
<think> truncation that retry can't fix anyway).

10 existing retry tests still pass; the retries=2 case now sleeps
1.25s instead of 0.75s, still well under vitest's default timeout.
2026-04-29 09:49:41 +08:00

45 lines
1.4 KiB
TypeScript

/**
* MiniMax M-series wrapper. Uses the OpenAI-compatible endpoint at
* api.minimaxi.com/v1 (CN) by default; override via `MINIMAX_BASE_URL`.
* Key must be in `MINIMAX_API_KEY`. See builtin-provider-presets.ts
* `minimax` for the canonical endpoint list.
*/
import type { ChatCallResult } from './openai-compat';
import { callOpenAICompat } from './openai-compat';
const MINIMAX_BASE_URL = process.env.MINIMAX_BASE_URL ?? 'https://api.minimax.io/v1';
const MINIMAX_API_KEY_ENV = 'MINIMAX_API_KEY';
export interface CallMinimaxArgs {
model: string;
system: string;
user: string;
temperature?: number;
maxTokens?: number;
}
export async function callMinimax(args: CallMinimaxArgs): Promise<ChatCallResult> {
const apiKey = process.env[MINIMAX_API_KEY_ENV];
if (!apiKey) {
throw new Error(
`${MINIMAX_API_KEY_ENV} not set — export it before running with --live, or pass --dry-run to use fixtures`,
);
}
return callOpenAICompat({
baseURL: MINIMAX_BASE_URL,
apiKey,
model: args.model,
system: args.system,
user: args.user,
temperature: args.temperature,
maxTokens: args.maxTokens,
label: 'minimax',
// ab-v3 saw 4 minimax timeouts on 104 runs — all wall-clock aborts,
// none were content-quality issues. One retry picks up the
// recoverable ones without burning budget on the truncation /
// <think> chatter that characterizes minimax model-side failures.
retries: 1,
});
}