Module: Clacky::Providers
- Defined in:
- lib/clacky/providers.rb
Overview
Built-in model provider presets Provides default configurations for supported AI model providers
Constant Summary collapse
- PRESETS =
Provider preset definitions Each preset includes:
-
name: Human-readable provider name
-
base_url: Default API endpoint
-
api: API type (anthropic-messages, openai-responses, openai-completions)
-
default_model: Recommended default model
-
{ "openrouter" => { "name" => "OpenRouter", "base_url" => "https://openrouter.ai/api/v1", "api" => "openai-responses", "default_model" => "anthropic/claude-sonnet-4-6", "lite_model" => "anthropic/claude-haiku-4-5", "models" => [], # Dynamic - fetched from API "website_url" => "https://openrouter.ai/keys" }.freeze, "minimax" => { "name" => "Minimax", "base_url" => "https://api.minimaxi.com/v1", "api" => "openai-completions", "default_model" => "MiniMax-M2.7", "models" => ["MiniMax-M2.5", "MiniMax-M2.7"], "website_url" => "https://www.minimaxi.com/user-center/basic-information/interface-key" }.freeze, "kimi" => { "name" => "Kimi (Moonshot)", "base_url" => "https://api.moonshot.cn/v1", "api" => "openai-completions", "default_model" => "kimi-k2.5", "models" => ["kimi-k2.5"], "website_url" => "https://platform.moonshot.cn/console/api-keys" }.freeze, "anthropic" => { "name" => "Anthropic (Claude)", "base_url" => "https://api.anthropic.com", "api" => "anthropic-messages", "default_model" => "claude-sonnet-4.6", "models" => ["claude-opus-4-6", "claude-sonnet-4.6", "claude-haiku-4.5"], "website_url" => "https://console.anthropic.com/settings/keys" }.freeze, "clackyai" => { "name" => "ClackyAI", "base_url" => "https://api.clacky.ai", "api" => "bedrock", "default_model" => "abs-claude-sonnet-4-6", "lite_model" => "abs-claude-haiku-4-5", "models" => [ "abs-claude-opus-4-6", "abs-claude-sonnet-4-6", "abs-claude-haiku-4-5" ], # Fallback chain: if a model is unavailable, try the next one in order. # Keys are primary model names; values are the fallback model to use instead. "fallback_models" => { "abs-claude-sonnet-4-6" => "abs-claude-sonnet-4-5" }, "website_url" => "https://clacky.ai" }.freeze, "mimo" => { "name" => "MiMo (Xiaomi)", "base_url" => "https://api.xiaomimimo.com/v1", "api" => "openai-completions", "default_model" => "mimo-v2-pro", "models" => ["mimo-v2-pro", "mimo-v2-omni"], "website_url" => "https://platform.xiaomimimo.com/" }.freeze }.freeze
Class Method Summary collapse
-
.api_type(provider_id) ⇒ String?
Get the API type for a provider.
-
.base_url(provider_id) ⇒ String?
Get the base URL for a provider.
-
.default_model(provider_id) ⇒ String?
Get the default model for a provider.
-
.exists?(provider_id) ⇒ Boolean
Check if a provider preset exists.
-
.fallback_model(provider_id, model) ⇒ String?
Get the fallback model for a given model within a provider.
-
.find_by_base_url(base_url) ⇒ String?
Find provider ID by base URL.
-
.get(provider_id) ⇒ Hash?
Get a provider preset by ID.
-
.list ⇒ Array<Array(String, String)>
List all available providers with their names.
-
.lite_model(provider_id) ⇒ String?
Get the lite model for a provider (if any).
-
.models(provider_id) ⇒ Array<String>
Get available models for a provider.
-
.provider_ids ⇒ Array<String>
List all available provider IDs.
Class Method Details
.api_type(provider_id) ⇒ String?
Get the API type for a provider
116 117 118 119 |
# File 'lib/clacky/providers.rb', line 116 def api_type(provider_id) preset = PRESETS[provider_id] preset&.dig("api") end |
.base_url(provider_id) ⇒ String?
Get the base URL for a provider
108 109 110 111 |
# File 'lib/clacky/providers.rb', line 108 def base_url(provider_id) preset = PRESETS[provider_id] preset&.dig("base_url") end |
.default_model(provider_id) ⇒ String?
Get the default model for a provider
100 101 102 103 |
# File 'lib/clacky/providers.rb', line 100 def default_model(provider_id) preset = PRESETS[provider_id] preset&.dig("default_model") end |
.exists?(provider_id) ⇒ Boolean
Check if a provider preset exists
86 87 88 |
# File 'lib/clacky/providers.rb', line 86 def exists?(provider_id) PRESETS.key?(provider_id) end |
.fallback_model(provider_id, model) ⇒ String?
Get the fallback model for a given model within a provider. Returns nil if no fallback is defined for that model.
154 155 156 157 |
# File 'lib/clacky/providers.rb', line 154 def fallback_model(provider_id, model) preset = PRESETS[provider_id] preset&.dig("fallback_models", model) end |
.find_by_base_url(base_url) ⇒ String?
Find provider ID by base URL. Matches if the given URL starts with the provider’s base_url (after normalisation), so both exact matches and sub-path variants (e.g. “/v1”) are recognised.
164 165 166 167 168 169 170 171 |
# File 'lib/clacky/providers.rb', line 164 def find_by_base_url(base_url) return nil if base_url.nil? || base_url.empty? normalized = base_url.to_s.chomp("/") PRESETS.find do |_id, preset| preset_base = preset["base_url"].to_s.chomp("/") normalized == preset_base || normalized.start_with?("#{preset_base}/") end&.first end |
.get(provider_id) ⇒ Hash?
Get a provider preset by ID
93 94 95 |
# File 'lib/clacky/providers.rb', line 93 def get(provider_id) PRESETS[provider_id] end |
.list ⇒ Array<Array(String, String)>
List all available providers with their names
129 130 131 |
# File 'lib/clacky/providers.rb', line 129 def list PRESETS.map { |id, config| [id, config["name"]] } end |
.lite_model(provider_id) ⇒ String?
Get the lite model for a provider (if any)
144 145 146 147 |
# File 'lib/clacky/providers.rb', line 144 def lite_model(provider_id) preset = PRESETS[provider_id] preset&.dig("lite_model") end |
.models(provider_id) ⇒ Array<String>
Get available models for a provider
136 137 138 139 |
# File 'lib/clacky/providers.rb', line 136 def models(provider_id) preset = PRESETS[provider_id] preset&.dig("models") || [] end |
.provider_ids ⇒ Array<String>
List all available provider IDs
123 124 125 |
# File 'lib/clacky/providers.rb', line 123 def provider_ids PRESETS.keys end |