关于 model-registry-maintainer
model-registry-maintainer 指导 MassGen 维护者更新模型能力、发布日期、价格和上下文限制。它区分能力注册表与令牌价格数据,并提供检查、测试和重新生成文档的步骤。
主要功能
- 01维护模型能力和发布日期
- 02检查 LiteLLM 价格数据
- 03更新备用价格和令牌限制
- 04验证注册表与令牌管理器变更
- 05重新生成后端文档
适用场景
- 01登记新发布的模型
- 02调整模型价格或上下文限制
- 03添加模型能力或提供商
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ massgen/ massgen --skill model-registry-maintainer安装后在 Claude Code 中输入/model-registry-maintainer确认已加载。
详细介绍
模型注册表维护者
此技能提供维护 MassGen 模型注册表的指南,涉及两个关键文件:
massgen/backend/capabilities.py—— 模型、能力、发布日期massgen/token_manager/token_manager.py—— 定价、上下文窗口
何时使用此技能
- 提供商发布了新模型
- 模型定价发生变化
- 上下文窗口限制更新
- 模型能力发生变化
- 新增提供商/后端
需要维护的两个文件
文件 1:capabilities.py(模型和功能)
包含内容:
- 各提供商可用模型的列表
- 模型能力(联网搜索、代码执行、视觉等)
- 发布日期
- 默认模型
用途:
- 配置生成器(
--quickstart、--generate-config) - 文档生成
- 后端验证
新增模型时,务必更新此文件。
文件 2:token_manager.py(定价和限制)
包含内容:
- LiteLLM 数据库中没有的模型的硬编码定价/上下文窗口
- 按需从 LiteLLM 数据库加载(500 多个模型)
用途:
- 成本估算
- Token 计数
- 上下文管理
定价解析顺序:
- LiteLLM 数据库(按需获取,缓存 1 小时)
- 硬编码的 PROVIDER_PRICING(仅作回退)
- 模式匹配启发式规则
仅在以下情况下更新 PROVIDER_PRICING:
- LiteLLM 数据库中没有该模型
- LiteLLM 定价不正确或已过时
- 该模型是你所在组织的自定义模型/内部模型
新模型需要收集的信息
1. 发布日期
- 格式:
"YYYY-MM" - 来源:
- OpenAI:https://openai.com/index
- Anthropic:https://www.anthropic.com/news
- Google DeepMind:https://blog.google/technology/google-deepmind/
- xAI:https://x.ai/news
2. 上下文窗口
- 输入上下文大小(tokens)
- 最大输出 tokens 数
- 查找:“context window”“max tokens”“input/output limits”
3. 定价
- 每 1K 个输入 tokens 的费用(美元)
- 每 1K 个输出 tokens 的费用(美元)
- 缓存输入费用(如适用)
- 来源:
- OpenAI:https://openai.com/api/pricing/
- Anthropic:https://www.anthropic.com/pricing
- Google:https://ai.google.dev/pricing
- xAI:https://x.ai/api/pricing
4. 能力
- 联网搜索、代码执行、视觉、推理等
- 查看官方 API 文档
5. 模型名称
- 精确的 API 标识符(区分大小写)
- 查看提供商的模型文档
添加新模型——完整工作流
步骤 1:添加到 capabilities.py
将模型添加到 models 列表和 model_release_dates 中:
# massgen/backend/capabilities.py
"openai": BackendCapabilities(
# ... existing fields ...
models=[
"new-model-name", # Add here (newest first)
"gpt-5.1",
# ... existing models ...
],
model_release_dates={
"new-model-name": "2025-12", # Add here
"gpt-5.1": "2025-11",
# ... existing dates ...
},
)
步骤 2:检查 LiteLLM 中是否已有定价(通常可跳过)
首先,检查该模型是否已在 LiteLLM 数据库中:
import requests
url = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"
pricing_db = requests.get(url).json()
if "new-model-name" in pricing_db:
print("✅ Model found in LiteLLM - no need to update token_manager.py")
print(f"Pricing: ${pricing_db['new-model-name']['input_cost_per_token']*1000}/1K input")
else:
print("❌ Model NOT in LiteLLM - need to add to PROVIDER_PRICING")
仅当 LiteLLM 中没有该模型时,才添加到 PROVIDER_PRICING:
# massgen/token_manager/token_manager.py
PROVIDER_PRICING: Dict[str, Dict[str, ModelPricing]] = {
"OpenAI": {
# Format: ModelPricing(input_per_1k, output_per_1k, context_window, max_output)
"new-model-name": ModelPricing(0.00125, 0.01, 300000, 150000),
# ... existing models ...
},
}
提供商名称映射:
"OpenAI"(而非 "openai")"Anthropic"(而非 "claude")"Google"(而非 "gemini")"xAI"(而非 "grok")
步骤 3:更新能力(如有新功能)
如果模型引入了新能力:
supported_capabilities={
"web_search",
"code_execution",
"new_capability", # Add here
}
步骤 4:更新默认模型(如适用)
仅当新模型应作为推荐的默认模型时才更改:
default_model="new-model-name"
步骤 5:验证和测试
# Run capabilities tests
uv run pytest massgen/tests/test_backend_capabilities.py -v
# Test config generation with new model
massgen --generate-config ./test.yaml --config-backend openai --config-model new-model-name
# Verify the config was created successfully
cat ./test.yaml
步骤 6:重新生成文档
uv run python docs/scripts/generate_backend_tables.py
cd docs && make html
当前模型数据
OpenAI 模型(截至 2025 年 11 月)
在 capabilities.py 中:
models=[
"gpt-5.1", # 2025-11
"gpt-5-codex", # 2025-09
"gpt-5", # 2025-08
"gpt-5-mini", # 2025-08
"gpt-5-nano", # 2025-08
"gpt-4.1", # 2025-04
"gpt-4.1-mini", # 2025-04
"gpt-4.1-nano", # 2025-04
"gpt-4o", # 2024-05
"gpt-4o-mini", # 2024-07
"o4-mini", # 2025-04
]
在 token_manager.py 中(添加缺失的模型):
"OpenAI": {
"gpt-5": ModelPricing(0.00125, 0.01, 400000, 128000),
"gpt-5-mini": ModelPricing(0.00025, 0.002, 400000, 128000),
"gpt-5-nano": ModelPricing(0.00005, 0.0004, 400000, 128000),
"gpt-4o": ModelPricing(0.0025, 0.01, 128000, 16384),
"gpt-4o-mini": ModelPricing(0.00015, 0.0006, 128000, 16384),
# Missing: gpt-5.1, gpt-5-codex, gpt-4.1 family, o4-mini
}
Claude 模型(截至 2025 年 11 月)
在 capabilities.py 中:
models=[
"claude-haiku-4-5-20251001", # 2025-10
"claude-sonnet-4-5-20250929", # 2025-09
"claude-opus-4-1-20250805", # 2025-08
"claude-sonnet-4-20250514", # 2025-05
]
在 token_manager.py 中:
"Anthropic": {
"claude-haiku-4-5": ModelPricing(0.001, 0.005, 200000, 65536),
"claude-sonnet-4-5": ModelPricing(0.003, 0.015, 200000, 65536),
"claude-opus-4.1": ModelPricing(0.015, 0.075, 200000, 32768),
"claude-sonnet-4": ModelPricing(0.003, 0.015, 200000, 8192),
}
Gemini 模型(截至 2025 年 11 月)
在 capabilities.py 中:
models=[
"gemini-3-pro-preview", # 2025-11
"gemini-2.5-flash", # 2025-06
"gemini-2.5-pro", # 2025-06
]
在 token_manager.py 中(缺少 gemini-2.5 和 gemini-3):
"Google": {
"gemini-1.5-pro": ModelPricing(0.00125, 0.005, 2097152, 8192),
"gemini-1.5-flash": ModelPricing(0.000075, 0.0003, 1048576, 8192),
# Missing: gemini-2.5-pro, gemini-2.5-flash, gemini-3-pro-preview
}
Grok 模型(截至 2025 年 11 月)
在 capabilities.py 中:
models=[
"grok-4-1-fast-reasoning", # 2025-11
"grok-4-1-fast-non-reasoning", # 2025-11
"grok-code-fast-1", # 2025-08
"grok-4", # 2025-07
"grok-4-fast", # 2025-09
"grok-3", # 2025-02
"grok-3-mini", # 2025-05
]
在 token_manager.py 中(缺少 grok-3、grok-4 系列):
"xAI": {
"grok-2-latest": ModelPricing(0.005, 0.015, 131072, 131072),
"grok-2": ModelPricing(0.005, 0.015, 131072, 131072),
"grok-2-mini": ModelPricing(0.001, 0.003, 131072, 65536),
# Missing: grok-3, grok-4, grok-4-1 families
}
模型名称匹配
重要: PROVIDER_PRICING 中的名称使用简化模式:
"gpt-5"可匹配gpt-5、gpt-5-preview、gpt-5-*"claude-sonnet-4-5"可匹配claude-sonnet-4-5-*(任何日期后缀)"gemini-2.5-pro"为精确匹配
Token 管理器使用前缀匹配,以提高灵活性。
常见任务
任务:添加全新的 GPT-5.2 模型
- 调研:发布日期、定价、上下文窗口、能力
- 将模型添加到
capabilities.py的模型列表和 release_dates - 将模型添加到
token_manager.py的 PROVIDER_PRICING["OpenAI"] - 运行测试
- 重新生成文档
任务:更新现有模型的定价
- 从官方来源核实新定价
- 仅更新
token_manager.py中的 PROVIDER_PRICING - 无需修改 capabilities.py
- 如果变更重大,请在备注中记录
任务:为模型添加新能力
- 更新 capabilities.py 中的
supported_capabilities - 在
notes中添加说明,解释该能力的工作时机和方式 - 如有需要,更新后端实现
- 运行测试
验证命令
# Test capabilities registry
uv run pytest massgen/tests/test_backend_capabilities.py -v
# Test token manager
uv run pytest massgen/tests/test_token_manager.py -v
# Generate config with new model
massgen --generate-config ./test.yaml --config-backend openai --config-model new-model
# Build docs to verify tables
cd docs && make html
以编程方式更新模型
LiteLLM 定价数据库(推荐)
获取全面的模型定价和上下文窗口数据的最简单方式:
URL:https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json
覆盖范围:涵盖 30 多家提供商的 500 多个模型,包括:
- OpenAI、Anthropic、Google、xAI
- Together AI、Groq、Cerebras、Fireworks
- AWS Bedrock、Azure、Cohere 等
可用数据:
{
"gpt-4o": {
"input_cost_per_token": 0.0000025,
"output_cost_per_token": 0.00001,
"max_input_tokens": 128000,
"max_output_tokens": 16384,
"supports_vision": true,
"supports_function_calling": true,
"supports_prompt_caching": true
}
}
用法:
import requests
# Fetch latest pricing
url = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"
pricing_db = requests.get(url).json()
# Get info for a model
model_info = pricing_db.get("gpt-4o")
input_per_1k = model_info["input_cost_per_token"] * 1000
output_per_1k = model_info["output_cost_per_token"] * 1000
根据 LiteLLM 更新 token_manager.py:
- 将每个 token 的成本转换为每 1K token 的成本
- 提取上下文窗口和最大输出 token 数
- 按时间倒序排列模型
OpenRouter API(实时)
获取最新模型列表和实时定价:
端点:https://openrouter.ai/api/v1/models
可用数据:
- 实时定价(提示词、补全、推理、缓存)
- 上下文窗口和最大补全 token 数
- 模型能力和模态
- 来自多个提供商的 200 多个模型
用法:
import requests
import os
headers = {"Authorization": f"Bearer {os.environ['OPENROUTER_API_KEY']}"}
response = requests.get("https://openrouter.ai/api/v1/models", headers=headers)
models = response.json()["data"]
for model in models:
print(f"{model['id']}: ${model['pricing']['prompt']} input, ${model['pricing']['completion']} output")
特定提供商的 API
| 提供商 | 模型 API | API 中包含定价? | 建议 |
|---|---|---|---|
| OpenAI | https://api.openai.com/v1/models | ❌ 否 | 使用 LiteLLM |
| Claude | 无公开 API | ❌ 否 | 使用 LiteLLM |
| Gemini | https://generativelanguage.googleapis.com/v1beta/models | ❌ 否 | API + LiteLLM |
| Grok (xAI) | https://api.x.ai/v1/models | ❌ 否 | 使用 LiteLLM |
| Together AI | https://api.together.xyz/v1/models | ✅ 是 | 直接使用 API |
| Groq | https://api.groq.com/openai/v1/models | ❌ 否 | 使用 LiteLLM |
| Cerebras | https://api.cerebras.ai/v1/models | ❌ 否 | 使用 LiteLLM |
| Fireworks | https://api.fireworks.ai/v1/accounts/{id}/models | ❌ 否 | 使用 LiteLLM |
| Azure OpenAI | Azure Management API | ❌ 复杂 | 手动处理 |
| Claude Code | 无 API | ❌ 否 | 手动处理 |
自动化脚本
创建 scripts/update_model_pricing.py,以自动执行更新:
#!/usr/bin/env python3
"""Update token_manager.py pricing from LiteLLM database."""
import requests
# Fetch LiteLLM database
url = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"
pricing_db = requests.get(url).json()
# Filter by provider
openai_models = {k: v for k, v in pricing_db.items()
if v.get("litellm_provider") == "openai"}
anthropic_models = {k: v for k, v in pricing_db.items()
if v.get("litellm_provider") == "anthropic"}
# Generate ModelPricing entries
for model_name, info in openai_models.items():
input_per_1k = info["input_cost_per_token"] * 1000
output_per_1k = info["output_cost_per_token"] * 1000
context = info.get("max_input_tokens", 0)
max_output = info.get("max_output_tokens", 0)
print(f' "{model_name}": ModelPricing({input_per_1k}, {output_per_1k}, {context}, {max_output}),')
每周运行一次,确保定价保持最新:
uv run python scripts/update_model_pricing.py
参考文件
- 能力注册表:
massgen/backend/capabilities.py - Token/定价管理器:
massgen/token_manager/token_manager.py - 能力测试:
massgen/tests/test_backend_capabilities.py - 配置构建器:
massgen/config_builder.py - 文档生成器:
docs/scripts/generate_backend_tables.py - LiteLLM 数据库:https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json
- OpenRouter API:https://openrouter.ai/docs/overview/models
重要维护说明
- 按时间倒序排列模型——最新的排在最前
- 使用准确的 API 名称——与提供商文档完全一致
- 核实定价单位——token_manager.py 中始终使用每 1K token 的价格
- 记录不确定之处——如果信息是估算的或非官方的,请注明
- 更新两个文件——添加模型时别忘了更新 token_manager.py
- 使用 LiteLLM 获取定价——数据全面且更新频繁
- 更新后进行测试——运行 pytest,确认没有破坏性变更