A platform for community discussion. Free, open, simple.
DEV: Refresh default LLM presets and pricing (#39673)
Rafael dos Santos Silva78a791852bff
diff --git a/.skills/discourse-ai-llm-presets/SKILL.md b/.skills/discourse-ai-llm-presets/SKILL.mdnew file mode 100644index 00000000000..140bcad54f2--- /dev/null+++ b/.skills/discourse-ai-llm-presets/SKILL.md@@ -0,0 +1,144 @@+---+name: discourse-ai-llm-presets+description: Use when refreshing the default LLM presets shipped with Discourse AI — model versions, pricing, context windows, vision flags, and the matching `model_description` i18n keys.+---++# Updating Discourse AI Default LLM Presets++## Overview++Discourse AI ships a curated set of LLM model presets in `plugins/discourse-ai/lib/completions/llm_presets.rb` so admins can create new LLM configurations with one click. This skill keeps them current — refreshing model IDs, pricing, context windows, and vision flags as providers evolve.++## When to Use++- A user asks to "update", "refresh", or "bump" the default LLM model presets in Discourse AI.+- A new flagship model has been released by a major provider (e.g. new GPT, Claude, or Gemini version).+- Pricing on a provider has changed and the shipped presets are stale.++## Files Involved++| Path | What lives there |+| --- | --- |+| `plugins/discourse-ai/lib/completions/llm_presets.rb` | The four provider preset blocks: `anthropic_preset`, `google_preset`, `open_ai_preset`, `open_router_preset`. |+| `plugins/discourse-ai/config/locales/client.en.yml` | One-line `model_description` strings keyed by `<provider_id>-<model_name>` with `.`/`/`/`:` replaced by `-`. Every preset model needs a matching key. |++**Out of scope for this skill:**+- `plugins/discourse-ai/config/eval-llms.yml` — internal evaluation suite. May reference older models intentionally; do not auto-update.+- Other locale files (`client.de.yml`, `client.es.yml`, …) — translations are managed via Crowdin. Only update `client.en.yml`; stale keys in other locales clean up automatically.+- Existing `LlmModel` DB rows. Preset changes only affect *new* one-click creations; previously-configured models keep working under their original names.++## Data Sources++Two primary sources, cross-reference both:++1. **`https://www.llm-prices.com/current-v1.json`** — curated pricing for first-party APIs (Anthropic, OpenAI, Google, xAI, etc.). Has `input`, `output`, and `input_cached` per 1M tokens.+2. **`https://catwalk.charm.land/v2/providers`** — broader catalog with context windows, max output tokens, vision flags, cached pricing, and provider defaults (`default_large_model_id`, `default_small_model_id`). Use for context windows and vision support that `llm-prices` omits.++For the OpenRouter provider list specifically, also use:++3. **OpenRouter top-weekly** — fetch via the frontend API since the HTML page is JS-rendered:+ ```+ curl -s "https://openrouter.ai/api/frontend/models/find?order=top-weekly&limit=30"+ ```+ The user's reference URL is `https://openrouter.ai/models?fmt=cards&order=top-weekly&output_modalities=text` but `WebFetch` cannot read it — go straight to the API.++## Provider Preset Structure++Each preset block is a hash with `id`, `models` (array), `tokenizer`, `endpoint`, and `provider`. Each model entry uses the `model(...)` helper:++```ruby+model(+ name: "claude-sonnet-4-6", # API model name — also the lookup key+ tokens: 1_000_000, # context window in tokens+ display_name: "Claude Sonnet 4.6",+ max_output_tokens: 64_000,+ input_cost: 3.0, # USD per 1M input tokens+ cached_input_cost: 0.30, # USD per 1M cached input tokens+ cache_write_cost: 3.75, # Anthropic-specific+ output_cost: 15.0,+ vision_enabled: true,+ endpoint: "...", # only when the model needs a different endpoint than the provider default+)+```++Notes:+- `cache_write_cost` is currently only set on Anthropic models (Anthropic has a separate write price).+- `vision_enabled` defaults to `false` and is only added when `true`. Trust catwalk's `supports_attachments` flag — it has been wrong in the file before (e.g. `minimax-m2.7` and `glm-5.1` were marked vision-capable but are text-only).+- Google models override `endpoint` per model because the API path encodes the model name.+- The OpenAI provider-level `endpoint:` is `chat/completions` but every model overrides it with `/responses` — leave the provider-level value alone.++## Selection Rules++### Anthropic, Google, OpenAI++- Ship a small tiered set: flagship / standard / small. Anthropic ships 3 (Opus / Sonnet / Haiku); OpenAI follows the same 3-tier pattern (e.g. GPT-5.5 / GPT-5.4 / GPT-5.4-nano). Google ships 2 (Pro / Flash).+- Avoid mid-tier overlap (e.g. shipping both `gpt-5.4` and `gpt-5.4-mini` is redundant when `gpt-5.4-nano` already covers the cheap end).+- Prefer the catwalk `default_large_model_id` and `default_small_model_id` as a hint for what the provider currently considers canonical.++### OpenRouter++- Pick the **top ~5–6 paid models by weekly usage** from the OpenRouter top-weekly list.+- **Skip `:free` variants** — they rotate out of OpenRouter within weeks and break presets.+- **Skip router/`~latest` aliases** (slug starts with `~`, e.g. `~anthropic/claude-sonnet-latest`) — those redirect and the underlying model can change.+- **Skip first-party Anthropic, Google, and OpenAI models** — they belong in their own provider blocks. The OpenRouter preset is for everything else (DeepSeek, Moonshot, MiniMax, Z.AI, xAI, Qwen, Arcee, etc.).+- Prefer models with vision and a sane cached-input price when ranking is close.++## i18n Keys++Every preset model needs a one-line description in `config/locales/client.en.yml` under `discourse_ai.llms.model_description`. The key format is:++```+<provider_id>-<model_name>+```++…with `.`, `/`, and `:` all replaced by `-` (handled in JS by `llm.id.replace(/[.:\/]/g, "-")` in `ai-llms-list-editor.gjs`).++Examples:+| Provider | Model `name` | i18n key |+| --- | --- | --- |+| `anthropic` | `claude-opus-4-7` | `anthropic-claude-opus-4-7` |+| `open_ai` | `gpt-5.4` | `open_ai-gpt-5-4` |+| `open_router` | `deepseek/deepseek-v4-flash` | `open_router-deepseek-deepseek-v4-flash` |+| `open_router` | `moonshotai/kimi-k2.6` | `open_router-moonshotai-kimi-k2-6` |++Whenever a model is added, renamed, or removed in `llm_presets.rb`, the matching key must be added/renamed/removed in `client.en.yml`. Missing keys silently fall through to an empty description (`I18n.lookup(..., { ignoreMissing: true })`).++## Steps++1. **Fetch source data** in parallel:+ ```bash+ curl -s https://www.llm-prices.com/current-v1.json -o /tmp/llm_prices.json+ curl -s https://catwalk.charm.land/v2/providers -o /tmp/catwalk.json+ curl -s "https://openrouter.ai/api/frontend/models/find?order=top-weekly&limit=30" -o /tmp/or_top.json+ ```++2. **Read the current presets file** at `plugins/discourse-ai/lib/completions/llm_presets.rb`.++3. **For each first-party provider block (Anthropic / Google / OpenAI)**: cross-reference each model's `tokens`, `max_output_tokens`, all `*_cost` fields, and `vision_enabled` against catwalk + llm-prices. Catwalk wins on context windows and vision flags; llm-prices wins on first-party API pricing.++4. **For the OpenRouter block**: parse `/tmp/or_top.json`, filter out `:free`, slugs starting with `~`, and first-party Anthropic/Google/OpenAI models. Take the top 5–6 remaining as the new list. Pricing comes from each entry's `endpoint.pricing` (multiply by 1_000_000 for per-1M tokens).++5. **Apply edits to `llm_presets.rb`** — prefer targeted `Edit` calls per model rather than rewriting whole blocks.++6. **Update `client.en.yml`** — add/rename/remove `model_description` keys to exactly match the new model set. Diff the model `name` list before/after to make sure no key is left orphaned.++7. **Validate**:+ ```bash+ bundle exec rubocop --force-exclusion plugins/discourse-ai/lib/completions/llm_presets.rb+ ruby -ryaml -e "YAML.load_file('plugins/discourse-ai/config/locales/client.en.yml'); puts 'YAML OK'"+ ```+ Also grep for orphaned references to any removed model names elsewhere in the plugin:+ ```bash+ grep -rn "<old-model-name>" plugins/discourse-ai --include="*.rb" --include="*.js" --include="*.gjs" --include="*.yml" \+ | grep -v lib/completions/llm_presets.rb+ ```++8. **Summarise the diff** to the user grouped by provider, calling out any pricing corrections (these are usually the most consequential — e.g. a model whose price had drifted vs. the provider's current price).++## Common Pitfalls++- **Forgetting the i18n keys.** Easy to miss because nothing breaks at runtime — the descriptions just go blank in the admin UI. Always update `client.en.yml` in the same commit.+- **Trusting OpenRouter pricing for first-party models.** OpenRouter aggregates many backends; for Anthropic / OpenAI / Google, prefer `llm-prices` or catwalk's first-party listing.+- **Inheriting wrong vision flags.** `vision_enabled` has been incorrect in the past — verify against catwalk every refresh.+- **Renaming a model without checking specs.** `spec/system/llms/ai_llm_spec.rb` and `lib/completions/endpoints/aws_bedrock.rb` reference Anthropic model names by string. Grep before renaming.+- **Picking unstable OpenRouter slugs.** `:free` and `~latest` alias slugs both churn faster than the release cycle of this file. Always skip them.diff --git a/plugins/discourse-ai/config/locales/client.en.yml b/plugins/discourse-ai/config/locales/client.en.ymlindex 39b4441063e..015a9bde1ac 100644--- a/plugins/discourse-ai/config/locales/client.en.yml+++ b/plugins/discourse-ai/config/locales/client.en.yml@@ -922,17 +922,17 @@ en:anthropic-claude-opus-4-7: "Anthropic's most intelligent model"anthropic-claude-sonnet-4-6: "Optimal balance of speed and cost"anthropic-claude-haiku-4-5: "Fast and cost-effective"- google-gemini-3-pro: "Google's most intelligent model"+ google-gemini-3-1-pro: "Google's most intelligent model"google-gemini-3-flash: "Fast and cost-efficient with multimodal reasoning"+ open_ai-gpt-5-5: "OpenAI's most capable model with extended context"open_ai-gpt-5-4: "OpenAI's flagship model, well suited for problem solving across domains"- open_ai-gpt-5-4-mini: "Provides a balance between intelligence, speed, and cost"- open_ai-gpt-5-nano: "Fastest, most cost-effective GPT-5 model"- open_router-deepseek-deepseek-v3-2: "DeepSeek's latest high-performance model"- open_router-moonshotai-kimi-k2-5: "Moonshot's multimodal model with vision capabilities"- open_router-x-ai-grok-4-fast: "xAI's flagship model with vision"- open_router-minimax-minimax-m2-7: "MiniMax's multimodal model with large context"- open_router-z-ai-glm-5-1: "Z-AI's multimodal model with vision"- open_router-arcee-ai-trinity-large-preview-free: "Free open-source model from Arcee AI"+ open_ai-gpt-5-4-nano: "Fastest, most cost-effective GPT-5 model"+ open_router-moonshotai-kimi-k2-6: "Moonshot's multimodal model with vision capabilities"+ open_router-deepseek-deepseek-v4-flash: "DeepSeek's latest high-performance model with 1M context"+ open_router-minimax-minimax-m2-7: "MiniMax's model with large context"+ open_router-x-ai-grok-4-1-fast: "xAI's fast multimodal model with very large context"+ open_router-z-ai-glm-5-1: "Z-AI's reasoning-focused model"+ open_router-qwen-qwen3-6-plus: "Qwen's multimodal model with 1M context"preseeded_model_description: "Pre-configured open-source model utilizing %{model}"diff --git a/plugins/discourse-ai/lib/completions/llm_presets.rb b/plugins/discourse-ai/lib/completions/llm_presets.rbindex 114b0856253..6808327d749 100644--- a/plugins/discourse-ai/lib/completions/llm_presets.rb+++ b/plugins/discourse-ai/lib/completions/llm_presets.rb@@ -34,7 +34,7 @@ module DiscourseAimodels: [model(name: "claude-opus-4-7",- tokens: 200_000,+ tokens: 1_000_000,display_name: "Claude Opus 4.7",max_output_tokens: 128_000,input_cost: 5.0,@@ -45,7 +45,7 @@ module DiscourseAi),model(name: "claude-sonnet-4-6",- tokens: 200_000,+ tokens: 1_000_000,display_name: "Claude Sonnet 4.6",max_output_tokens: 64_000,input_cost: 3.0,@@ -77,16 +77,16 @@ module DiscourseAiid: "google",models: [model(- name: "gemini-3-pro",+ name: "gemini-3.1-pro",tokens: 1_000_000,- display_name: "Gemini 3 Pro",+ display_name: "Gemini 3.1 Pro",max_output_tokens: 65_000,input_cost: 2.0,cached_input_cost: 0.20,output_cost: 12.0,vision_enabled: true,endpoint:- "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-preview",+ "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-pro-preview",),model(name: "gemini-3-flash",@@ -111,35 +111,36 @@ module DiscourseAiid: "open_ai",models: [model(- name: "gpt-5.4",- tokens: 400_000,- display_name: "GPT-5.4",+ name: "gpt-5.5",+ tokens: 1_050_000,+ display_name: "GPT-5.5",max_output_tokens: 128_000,- input_cost: 1.25,- cached_input_cost: 0.125,- output_cost: 10.0,+ input_cost: 5.0,+ cached_input_cost: 0.50,+ output_cost: 30.0,vision_enabled: true,endpoint: "https://api.openai.com/v1/responses",),model(- name: "gpt-5.4-mini",+ name: "gpt-5.4",tokens: 400_000,- display_name: "GPT-5.4 Mini",+ display_name: "GPT-5.4",max_output_tokens: 128_000,- input_cost: 0.75,- cached_input_cost: 0.075,- output_cost: 4.50,+ input_cost: 2.50,+ cached_input_cost: 0.25,+ output_cost: 15.0,vision_enabled: true,endpoint: "https://api.openai.com/v1/responses",),model(- name: "gpt-5-nano",+ name: "gpt-5.4-nano",tokens: 400_000,- display_name: "GPT-5 Nano",+ display_name: "GPT-5.4 Nano",max_output_tokens: 128_000,- input_cost: 0.05,- cached_input_cost: 0.005,- output_cost: 0.40,+ input_cost: 0.20,+ cached_input_cost: 0.02,+ output_cost: 1.25,+ vision_enabled: true,endpoint: "https://api.openai.com/v1/responses",),],@@ -154,56 +155,60 @@ module DiscourseAiid: "open_router",models: [model(- name: "deepseek/deepseek-v3.2",- tokens: 163_000,- display_name: "DeepSeek V3.2",- max_output_tokens: 32_000,- input_cost: 0.27,- output_cost: 1.10,- ),- model(- name: "moonshotai/kimi-k2.5",+ name: "moonshotai/kimi-k2.6",tokens: 262_144,- display_name: "Moonshot Kimi K2.5",- max_output_tokens: 262_144,- input_cost: 0.60,- output_cost: 3.0,+ display_name: "Moonshot Kimi K2.6",+ max_output_tokens: 131_072,+ input_cost: 0.74,+ cached_input_cost: 0.14,+ output_cost: 3.49,vision_enabled: true,),model(- name: "x-ai/grok-4-fast",- tokens: 131_000,- display_name: "xAI Grok 4 Fast",- max_output_tokens: 32_000,- input_cost: 3.0,- output_cost: 15.0,- vision_enabled: true,+ name: "deepseek/deepseek-v4-flash",+ tokens: 1_048_576,+ display_name: "DeepSeek V4 Flash",+ max_output_tokens: 192_000,+ input_cost: 0.14,+ cached_input_cost: 0.0028,+ output_cost: 0.28,),model(name: "minimax/minimax-m2.7",- tokens: 205_000,+ tokens: 196_608,display_name: "MiniMax M2.7",- max_output_tokens: 131_000,+ max_output_tokens: 65_536,input_cost: 0.30,+ cached_input_cost: 0.06,output_cost: 1.20,+ ),+ model(+ name: "x-ai/grok-4.1-fast",+ tokens: 2_000_000,+ display_name: "xAI Grok 4.1 Fast",+ max_output_tokens: 30_000,+ input_cost: 0.20,+ cached_input_cost: 0.05,+ output_cost: 0.50,vision_enabled: true,),model(name: "z-ai/glm-5.1",- tokens: 203_000,+ tokens: 202_752,display_name: "Z-AI GLM-5.1",- max_output_tokens: 131_072,- input_cost: 0.95,- output_cost: 3.15,- vision_enabled: true,+ max_output_tokens: 65_536,+ input_cost: 1.05,+ cached_input_cost: 0.525,+ output_cost: 3.50,),model(- name: "arcee-ai/trinity-large-preview:free",- tokens: 128_000,- display_name: "Arcee Trinity Large (Free)",- max_output_tokens: 32_000,- input_cost: 0.0,- output_cost: 0.0,+ name: "qwen/qwen3.6-plus",+ tokens: 1_000_000,+ display_name: "Qwen3.6 Plus",+ max_output_tokens: 65_536,+ input_cost: 0.325,+ output_cost: 1.95,+ vision_enabled: true,),],tokenizer: DiscourseAi::Tokenizer::OpenAiTokenizer,