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
-
{ "openclacky" => { "name" => "OpenClacky", "base_url" => "https://api.openclacky.com", "api" => "bedrock", "default_model" => "abs-claude-sonnet-4-5", "lite_model" => "abs-claude-haiku-4-5", "models" => [ "abs-claude-opus-4-6", "abs-claude-sonnet-4-6", "abs-claude-sonnet-4-5", "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://www.openclacky.com/ai-keys" }.freeze, "openrouter" => { "name" => "OpenRouter", "base_url" => "https://openrouter.ai/api/v1", "api" => "openai-responses", "default_model" => "anthropic/claude-sonnet-4-6", "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-sea" => { "name" => "ClackyAI( Sea )", "base_url" => "https://api.clacky.ai", "api" => "bedrock", "default_model" => "abs-claude-sonnet-4-5", "lite_model" => "abs-claude-haiku-4-5", "models" => [ "abs-claude-opus-4-6", "abs-claude-sonnet-4-6", "abs-claude-sonnet-4-5", "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
135 136 137 138 |
# File 'lib/clacky/providers.rb', line 135 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
127 128 129 130 |
# File 'lib/clacky/providers.rb', line 127 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
119 120 121 122 |
# File 'lib/clacky/providers.rb', line 119 def default_model(provider_id) preset = PRESETS[provider_id] preset&.dig("default_model") end |
.exists?(provider_id) ⇒ Boolean
Check if a provider preset exists
105 106 107 |
# File 'lib/clacky/providers.rb', line 105 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.
173 174 175 176 |
# File 'lib/clacky/providers.rb', line 173 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.
183 184 185 186 187 188 189 190 |
# File 'lib/clacky/providers.rb', line 183 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
112 113 114 |
# File 'lib/clacky/providers.rb', line 112 def get(provider_id) PRESETS[provider_id] end |
.list ⇒ Array<Array(String, String)>
List all available providers with their names
148 149 150 |
# File 'lib/clacky/providers.rb', line 148 def list PRESETS.map { |id, config| [id, config["name"]] } end |
.lite_model(provider_id) ⇒ String?
Get the lite model for a provider (if any)
163 164 165 166 |
# File 'lib/clacky/providers.rb', line 163 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
155 156 157 158 |
# File 'lib/clacky/providers.rb', line 155 def models(provider_id) preset = PRESETS[provider_id] preset&.dig("models") || [] end |
.provider_ids ⇒ Array<String>
List all available provider IDs
142 143 144 |
# File 'lib/clacky/providers.rb', line 142 def provider_ids PRESETS.keys end |