| 1 | import type { LocalizedText } from "./vocabulary"; |
| 2 | import type { ModelFact, ProviderFact } from "../facts"; |
| 3 | |
| 4 | export const MODELS_COPY = { |
| 5 | metaTitle: { en: "Models and providers · Codewhale", zh: "模型与提供商 · Codewhale" }, |
| 6 | metaDescription: { en: "Connect DeepSeek, Anthropic, OpenAI, Google, xAI or any OpenAI-compatible endpoint, then switch provider and model whenever the work changes.", zh: "连接 DeepSeek、Anthropic、OpenAI、Google、xAI 或任何兼容 OpenAI 的端点,工作变化时随时切换提供商和模型。" }, |
| 7 | title: { en: "Models and providers", zh: "模型与提供商" }, |
| 8 | lead: { en: "Codewhale works with the model providers you already pay for, and you can change the provider or model at any point in a session.", zh: "Codewhale 使用你已有的模型提供商,会话中随时可以更换提供商或模型。" }, |
| 9 | latestTitle: { en: "Recently added", zh: "最近加入" }, |
| 10 | latestLead: { en: "The latest addition to the catalog from each first-party provider. Dates are when Codewhale added the model, not the maker's release date.", zh: "每家一方提供商最近加入目录的模型。日期为 Codewhale 加入该模型的时间,不是厂商的发布日期。" }, |
| 11 | latestSince: { en: "In Codewhale since {date}", zh: "{date} 起已加入 Codewhale" }, |
| 12 | pickerTitle: { en: "Pick a model by name", zh: "按名称挑选模型" }, |
| 13 | pickerLead: { |
| 14 | en: "Search the model picker, and the same model appears under every provider that offers it. These views are from real sessions on development builds.", |
| 15 | zh: "在模型选择器中搜索,同一个模型会出现在每个提供它的提供商下。这些画面来自开发版本上的真实会话。", |
| 16 | }, |
| 17 | pickerTerminalLabel: { |
| 18 | en: "Codewhale in a terminal. The model picker, searched for deepseek-flash, lists deepseek-flash from DeepSeek, Fireworks AI and OpenRouter, with DeepSeek selected.", |
| 19 | zh: "终端中的 Codewhale。在模型选择器中搜索 deepseek-flash,列出 DeepSeek、Fireworks AI 和 OpenRouter 提供的 deepseek-flash,并选中了 DeepSeek。", |
| 20 | }, |
| 21 | pickerTerminalCaption: { en: "The terminal model picker.", zh: "终端中的模型选择器。" }, |
| 22 | pickerDesktopAlt: { |
| 23 | en: "The desktop app's Models settings with DeepSeek connected and ready, deepseek-flash as the model for new sessions and the thinking level on Auto.", |
| 24 | zh: "桌面应用的 Models 设置:DeepSeek 已连接并就绪,新会话使用 deepseek-flash,思考级别为 Auto。", |
| 25 | }, |
| 26 | pickerDesktopCaption: { |
| 27 | en: "The desktop app reads the model list from each connected provider.", |
| 28 | zh: "桌面应用会从每个已连接的提供商读取模型列表。", |
| 29 | }, |
| 30 | setupTitle: { en: "Connect a model in three steps", zh: "三步连接模型" }, |
| 31 | setupLead: { en: "The same steps work for every provider on this page.", zh: "本页的所有提供商都适用同样的步骤。" }, |
| 32 | steps: [ |
| 33 | { |
| 34 | title: { en: "Save a key", zh: "保存密钥" }, |
| 35 | detail: { en: "Run `codewhale auth set --provider deepseek`, or the id of another provider from the table below, and paste the key.", zh: "运行 `codewhale auth set --provider deepseek`(或下表中其他提供商的 ID)并粘贴密钥。" }, |
| 36 | }, |
| 37 | { |
| 38 | title: { en: "Pick a provider and model", zh: "选择提供商和模型" }, |
| 39 | detail: { en: "In a session, choose the provider with `/provider` and the model with `/model`.", zh: "在会话中,用 `/provider` 选择提供商,用 `/model` 选择模型。" }, |
| 40 | }, |
| 41 | { |
| 42 | title: { en: "Switch any time", zh: "随时切换" }, |
| 43 | detail: { en: "Run `/provider` or `/model` again when the task changes. Your session stays open.", zh: "任务变化时再次运行 `/provider` 或 `/model`,会话保持不变。" }, |
| 44 | }, |
| 45 | ], |
| 46 | routeDeepseekTitle: { en: "DeepSeek (default)", zh: "DeepSeek(默认)" }, |
| 47 | routeDeepseekBody: { en: "Save a DeepSeek key and start working. The default model is {model}.", zh: "保存 DeepSeek 密钥即可开始工作,默认模型为 {model}。" }, |
| 48 | routeFirstPartyTitle: { en: "Anthropic, OpenAI, Google and more", zh: "Anthropic、OpenAI、Google 等" }, |
| 49 | routeFirstPartyBody: { en: "Each provider reads its own credential setting.", zh: "每家提供商读取各自的凭据设置。" }, |
| 50 | routeCompatTitle: { en: "Any OpenAI-compatible endpoint", zh: "任何兼容 OpenAI 的端点" }, |
| 51 | routeCompatBody: { en: "Point Codewhale at any gateway or self-hosted server that speaks the OpenAI Chat Completions API, such as OrcaRouter or llama.cpp.", zh: "让 Codewhale 指向任何支持 OpenAI Chat Completions API 的网关或自托管服务,例如 OrcaRouter 或 llama.cpp。" }, |
| 52 | routeCompatConfig: { en: "Add a `[providers.<name>]` table to config.toml with `kind = \"openai-compatible\"` and its `base_url`, then select it with `provider = \"<name>\"`.", zh: "在 config.toml 中添加 `[providers.<name>]` 表,设置 `kind = \"openai-compatible\"` 与 `base_url`,再用 `provider = \"<name>\"` 选中它。" }, |
| 53 | providerDocs: { en: "Provider setup guides", zh: "提供商配置指南" }, |
| 54 | modelsTitle: { en: "Full model catalog", zh: "完整模型目录" }, |
| 55 | modelsLead: { en: "{count} models in the catalog of the published release, grouped by maker. A model reached through several providers is listed once.", zh: "已发布版本目录中的 {count} 个模型,按厂商分组。经多家提供商提供的同一模型只列一次。" }, |
| 56 | models: { en: "{count} models", zh: "{count} 个模型" }, |
| 57 | providerCount: { en: "Show all {count} provider routes", zh: "显示全部 {count} 条提供商路由" }, |
| 58 | colModel: { en: "Model", zh: "模型" }, |
| 59 | colContext: { en: "Context", zh: "上下文" }, |
| 60 | colAdded: { en: "In Codewhale since", zh: "加入 Codewhale 时间" }, |
| 61 | colKind: { en: "Type", zh: "类型" }, |
| 62 | reasoning: { en: "reasoning", zh: "推理" }, |
| 63 | listTitle: { en: "Providers and credential settings", zh: "提供商与凭据设置" }, |
| 64 | provider: { en: "Provider", zh: "提供商" }, |
| 65 | id: { en: "Provider ID", zh: "提供商 ID" }, |
| 66 | credential: { en: "Credential setting", zh: "凭据设置" }, |
| 67 | missing: { en: "Missing your provider?", zh: "没有找到你的提供商?" }, |
| 68 | request: { en: "Request support", zh: "申请支持" }, |
| 69 | otherMakers: { en: "Other makers", zh: "其他厂商" }, |
| 70 | } satisfies Record<string, LocalizedText | { title: LocalizedText; detail: LocalizedText }[]>; |
| 71 | |
| 72 | export const FIRST_PARTY_PROVIDER_IDS = [ |
| 73 | "deepseek", "anthropic", "openai", "openai-codex", "google", "xai", |
| 74 | "mistral", "moonshot", "zai", "minimax", "meta", "xiaomi-mimo", "stepfun", |
| 75 | ]; |
| 76 | |
| 77 | export const ROUTE_PROVIDERS = [ |
| 78 | { id: "anthropic", label: "Anthropic" }, |
| 79 | { id: "openai", label: "OpenAI" }, |
| 80 | { id: "google", label: "Google" }, |
| 81 | { id: "xai", label: "xAI" }, |
| 82 | ]; |
| 83 | |
| 84 | export const MODEL_MAKERS: { key: string; label: string; providers: string[] }[] = [ |
| 85 | { key: "anthropic", label: "Anthropic", providers: ["Anthropic"] }, |
| 86 | { key: "openai", label: "OpenAI", providers: ["OpenAI", "OpenAI Codex"] }, |
| 87 | { key: "google", label: "Google", providers: ["Google"] }, |
| 88 | { key: "deepseek", label: "DeepSeek", providers: ["DeepSeek"] }, |
| 89 | { key: "xai", label: "xAI", providers: ["xAI"] }, |
| 90 | { key: "moonshot", label: "Moonshot/Kimi", providers: ["Moonshot/Kimi"] }, |
| 91 | { key: "qwen", label: "Qwen", providers: ["Qwen"] }, |
| 92 | { key: "zai", label: "Z.ai", providers: ["Z.ai"] }, |
| 93 | { key: "minimax", label: "MiniMax", providers: ["MiniMax"] }, |
| 94 | { key: "mistral", label: "Mistral", providers: ["Mistral"] }, |
| 95 | { key: "meta", label: "Meta", providers: ["Meta"] }, |
| 96 | { key: "xiaomi", label: "Xiaomi", providers: ["Xiaomi MiMo"] }, |
| 97 | { key: "stepfun", label: "StepFun", providers: ["StepFun"] }, |
| 98 | ]; |
| 99 | |
| 100 | const FIRST_PARTY_MAKERS = ["anthropic", "openai", "google", "deepseek", "xai"]; |
| 101 | const PREVIEW_ID = /(?:^|[-/])(exp|preview)(?:-|$)/; |
| 102 | const SMALL_TIER_ID = /(?:^|[-/])(mini|nano|lite|flash|haiku|small|fast)(?:-|$)/; |
| 103 | |
| 104 | const byNewest = (a: ModelFact, b: ModelFact) => |
| 105 | (b.addedAt ?? "").localeCompare(a.addedAt ?? "") || |
| 106 | b.id.localeCompare(a.id, "en", { numeric: true }); |
| 107 | |
| 108 | const byNewestFlagship = (a: ModelFact, b: ModelFact) => |
| 109 | (b.addedAt ?? "").localeCompare(a.addedAt ?? "") || |
| 110 | Number(SMALL_TIER_ID.test(a.id)) - Number(SMALL_TIER_ID.test(b.id)) || |
| 111 | b.id.localeCompare(a.id, "en", { numeric: true }); |
| 112 | |
| 113 | export function makerKeyOf(model: ModelFact): string { |
| 114 | const maker = MODEL_MAKERS.find((m) => model.provider !== null && m.providers.includes(model.provider)); |
| 115 | return maker?.key ?? "other"; |
| 116 | } |
| 117 | |
| 118 | export function groupModelsByMaker(models: ModelFact[]) { |
| 119 | const groups = [...MODEL_MAKERS.map((m) => ({ key: m.key, label: m.label })), { key: "other", label: "" }] |
| 120 | .map((g) => ({ ...g, models: models.filter((m) => makerKeyOf(m) === g.key).sort(byNewest) })); |
| 121 | return groups.filter((g) => g.models.length > 0); |
| 122 | } |
| 123 | |
| 124 | export function latestFirstPartyModels(models: ModelFact[]) { |
| 125 | return FIRST_PARTY_MAKERS |
| 126 | .map((key) => ({ |
| 127 | key, |
| 128 | label: MODEL_MAKERS.find((m) => m.key === key)?.label ?? key, |
| 129 | model: models |
| 130 | .filter((m) => makerKeyOf(m) === key && m.addedAt !== null && !PREVIEW_ID.test(m.id)) |
| 131 | .sort(byNewestFlagship)[0], |
| 132 | })) |
| 133 | .flatMap((entry) => (entry.model ? [{ ...entry, model: entry.model }] : [])); |
| 134 | } |
| 135 | |
| 136 | export function splitCode(text: string): { code: boolean; text: string }[] { |
| 137 | return text.split("`").map((part, i) => ({ code: i % 2 === 1, text: part })).filter((p) => p.text); |
| 138 | } |
| 139 | |
| 140 | export function sortProvidersFirstPartyFirst(providers: ProviderFact[]): ProviderFact[] { |
| 141 | const rank = (p: ProviderFact) => { |
| 142 | const i = FIRST_PARTY_PROVIDER_IDS.indexOf(p.id); |
| 143 | return i === -1 ? FIRST_PARTY_PROVIDER_IDS.length : i; |
| 144 | }; |
| 145 | return [...providers].sort((a, b) => rank(a) - rank(b) || a.label.localeCompare(b.label)); |
| 146 | } |
| 147 | |
| 148 | export function formatModelTokens(n: number | null): string { |
| 149 | if (n === null) return "—"; |
| 150 | if (n >= 1_000_000) { |
| 151 | const m = n / 1_000_000; |
| 152 | return `${Number.isInteger(m) ? m : m.toFixed(2)}M`; |
| 153 | } |
| 154 | if (n >= 1_000) return `${Math.round(n / 1_000)}K`; |
| 155 | return String(n); |
| 156 | } |
| 157 | |
| 158 | export function formatModelDate(iso: string | null, dateLocale: string): string { |
| 159 | if (!iso) return "—"; |
| 160 | const d = new Date(`${iso}T00:00:00Z`); |
| 161 | if (!Number.isFinite(d.getTime())) return "—"; |
| 162 | return new Intl.DateTimeFormat(dateLocale, { |
| 163 | dateStyle: "medium", |
| 164 | timeZone: "UTC", |
| 165 | }).format(d); |
| 166 | } |
| 167 |