Module: Durable::Llm::Providers
- Defined in:
- lib/durable/llm/providers.rb,
lib/durable/llm/providers/xai.rb,
lib/durable/llm/providers/base.rb,
lib/durable/llm/providers/groq.rb,
lib/durable/llm/providers/cohere.rb,
lib/durable/llm/providers/google.rb,
lib/durable/llm/providers/openai.rb,
lib/durable/llm/providers/mistral.rb,
lib/durable/llm/providers/deepseek.rb,
lib/durable/llm/providers/opencode.rb,
lib/durable/llm/providers/together.rb,
lib/durable/llm/providers/anthropic.rb,
lib/durable/llm/providers/fireworks.rb,
lib/durable/llm/providers/openrouter.rb,
lib/durable/llm/providers/perplexity.rb,
lib/durable/llm/providers/huggingface.rb,
lib/durable/llm/providers/azure_openai.rb
Overview
Main module for LLM providers, providing registry and utility methods
Defined Under Namespace
Classes: Anthropic, AzureOpenai, Base, Cohere, DeepSeek, Fireworks, Google, Groq, Huggingface, Mistral, OpenAI, OpenRouter, Opencode, Perplexity, Together, Xai
Constant Summary collapse
- Openai =
OpenAI- Claude =
Anthropic- Claude3 =
Anthropic- AzureOpenAI =
AzureOpenai
Class Method Summary collapse
-
.load_all ⇒ void
Loads all provider files in the providers directory.
-
.model_id_to_provider(model_id) ⇒ Class?
Finds the provider class that supports a given model ID.
-
.model_ids ⇒ Array<String>
Returns a flat list of all model IDs across all providers.
-
.provider_class_for(provider_sym) ⇒ Class
Returns the provider class for a given provider symbol.
-
.providers ⇒ Array<Symbol>
Returns a list of all available provider symbols.
Class Method Details
.load_all ⇒ void
This method returns an undefined value.
Loads all provider files in the providers directory.
This method dynamically requires all Ruby files in the providers subdirectory, ensuring that all provider classes are loaded and available for use.
35 36 37 |
# File 'lib/durable/llm/providers.rb', line 35 def self.load_all Dir[File.join(__dir__, 'providers', '*.rb')].sort.each { |file| require file } end |
.model_id_to_provider(model_id) ⇒ Class?
Finds the provider class that supports a given model ID.
This method searches through all providers to find which one supports the specified model ID. Returns nil if no provider supports the model.
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/durable/llm/providers.rb', line 111 def self.model_id_to_provider(model_id) providers.each do |provider_sym| provider_class = provider_class_for(provider_sym) begin return provider_class if provider_class.models.include?(model_id) rescue StandardError next end end nil end |
.model_ids ⇒ Array<String>
Returns a flat list of all model IDs across all providers.
This method aggregates model IDs from all available providers by calling their models method. If a provider fails to return models (e.g., due to missing API keys), it gracefully handles the error and continues.
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/durable/llm/providers.rb', line 93 def self.model_ids providers.flat_map do |provider_sym| provider_class = provider_class_for(provider_sym) begin provider_class.models rescue StandardError [] end end end |
.provider_class_for(provider_sym) ⇒ Class
Returns the provider class for a given provider symbol.
This method handles the mapping from provider symbols to their corresponding class constants, including special cases where the symbol doesn’t directly map to a capitalized class name.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/durable/llm/providers.rb', line 48 def self.provider_class_for(provider_sym) # Handle special cases where capitalize doesn't match case provider_sym when :deepseek DeepSeek when :openrouter OpenRouter when :azureopenai AzureOpenai when :opencode Opencode else const_get(provider_sym.to_s.capitalize) end end |
.providers ⇒ Array<Symbol>
Returns a list of all available provider symbols.
This method dynamically discovers all provider classes by inspecting the module’s constants and filtering for classes that inherit from Base, excluding the Base class itself.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/durable/llm/providers.rb', line 71 def self.providers @providers ||= begin provider_classes = constants.select do |const_name| const = const_get(const_name) next if const.name.split('::').last == 'Base' const.is_a?(Class) && const < Durable::Llm::Providers::Base end provider_classes.map do |const_name| const_get(const_name).name.split('::').last.downcase.to_sym end.uniq end end |