mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
Replace the single 3300-line generate-models.ts with declarative provider definitions and ordered rule packs under scripts/model-generation/. Each provider is a defineProvider() call: an upstream source (usually the generic modelsDev() mapper), static models upstream lacks, and rules scoped to that provider. Cross-provider facts live in rule packs applied in a fixed order. Every rule() carries a why, matches models with plain data, and patches them with typed set/replace/apply semantics. Generated model data is unchanged: 1443 models across 41 providers compare equal against a snapshot of the same upstream responses, apart from a now stable key order. Committed models.generated.ts and provider shards are byte-identical. Also: - Bring packages/ai/scripts under tsgo and biome; the old generator had 20+ type errors that nothing checked. - Add --upstream-snapshot <dir> to record and replay upstream catalogs and --explain <provider>:<model> to list the rules applied to a model. - Report rules that matched no model so stale corrections get removed. - Export parseRadiusGatewayConfig so the generator can replay Radius too. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018ExCU9zaZnN8vB5fKpTAjP
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import type { OpenAICompletionsCompat } from "../../../src/types.ts";
|
|
import { type DefinedRule, defineProvider, rule } from "../dsl.ts";
|
|
import { modelsDev } from "../models-dev.ts";
|
|
import { KIMI_K3_COST } from "../shared.ts";
|
|
|
|
const MOONSHOT_COMPAT: OpenAICompletionsCompat = {
|
|
supportsStore: false,
|
|
supportsDeveloperRole: false,
|
|
supportsReasoningEffort: false,
|
|
maxTokensField: "max_tokens",
|
|
supportsStrictMode: false,
|
|
thinkingFormat: "deepseek",
|
|
};
|
|
|
|
const kimiK3Rules: DefinedRule[] = [
|
|
rule({
|
|
why: "Kimi K3 always reasons, takes OpenAI reasoning_effort, and needs reasoning_content replayed on assistant messages.",
|
|
match: { id: "kimi-k3" },
|
|
set: {
|
|
reasoning: true,
|
|
compat: {
|
|
requiresReasoningContentOnAssistantMessages: true,
|
|
thinkingFormat: "openai",
|
|
supportsReasoningEffort: true,
|
|
},
|
|
},
|
|
}),
|
|
rule({
|
|
why: "models.dev has no Kimi K3 prices yet; fill in the published Moonshot rates per missing field.",
|
|
match: { id: "kimi-k3" },
|
|
apply: (model) => {
|
|
model.cost = {
|
|
input: model.cost.input || KIMI_K3_COST.input,
|
|
output: model.cost.output || KIMI_K3_COST.output,
|
|
cacheRead: model.cost.cacheRead || KIMI_K3_COST.cacheRead,
|
|
cacheWrite: model.cost.cacheWrite || KIMI_K3_COST.cacheWrite,
|
|
};
|
|
},
|
|
}),
|
|
];
|
|
|
|
export const moonshotai = defineProvider({
|
|
id: "moonshotai",
|
|
source: modelsDev({
|
|
provider: "moonshotai",
|
|
key: "moonshotai",
|
|
api: "openai-completions",
|
|
baseUrl: "https://api.moonshot.ai/v1",
|
|
compat: MOONSHOT_COMPAT,
|
|
}),
|
|
rules: kimiK3Rules,
|
|
});
|
|
|
|
export const moonshotaiCn = defineProvider({
|
|
id: "moonshotai-cn",
|
|
source: modelsDev({
|
|
provider: "moonshotai-cn",
|
|
key: "moonshotai-cn",
|
|
api: "openai-completions",
|
|
baseUrl: "https://api.moonshot.cn/v1",
|
|
compat: MOONSHOT_COMPAT,
|
|
}),
|
|
rules: kimiK3Rules,
|
|
});
|