Class: ActionAgent::Api::ProviderModelsController

Inherits:
BaseController show all
Defined in:
app/controllers/action_agent/api/provider_models_controller.rb

Overview

Model catalogs for the agent builder/editor dropdowns.

Hosted providers get a curated list of current models (kept here, server side, so the UI can't drift stale). Ollama is queried live from the account's configured host (Settings -> Provider API Keys, falling back to the platform config) so locally pulled models appear; OpenRouter is queried from its public catalog. Live lookups fall back to the curated list on any failure.

Constant Summary collapse

FETCH_TIMEOUT_SECONDS =
4
CURATED =

Fallbacks when a live lookup isn't possible (reviewed 2026-07). First entry is the default the builder preselects.

{
  "openai" => %w[gpt-5.1 gpt-5 gpt-5-mini gpt-5-nano],
  "anthropic" => %w[claude-opus-5 claude-fable-5 claude-sonnet-5 claude-opus-4-8 claude-haiku-4-5],
  "openrouter" => %w[anthropic/claude-sonnet-4.5 openai/gpt-5.1 meta-llama/llama-3.3-70b-instruct qwen/qwen3-32b],
  "ollama" => %w[qwen3:8b llama3.2 mistral gemma3]
}.freeze

Instance Method Summary collapse

Methods inherited from ActionAgent::ApplicationController

allow_unauthenticated_access

Instance Method Details

#indexObject

GET /api/provider_models?provider=ollama



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/action_agent/api/provider_models_controller.rb', line 28

def index
  provider = params[:provider].to_s
  unless Agent::PROVIDERS.include?(provider)
    return render json: { error: "Unknown provider: #{provider}" }, status: :unprocessable_entity
  end

  models, source = case provider
  when "ollama" then live_ollama_models
  when "openrouter" then live_openrouter_models
  when "anthropic" then live_anthropic_models
  end

  if models.blank?
    models = CURATED.fetch(provider)
    source = "curated"
  end

  render json: { provider: provider, models: models, source: source }
end