Class: DSPy::LM::AdapterFactory
- Inherits:
-
Object
- Object
- DSPy::LM::AdapterFactory
- Defined in:
- lib/dspy/lm/adapter_factory.rb
Overview
Factory for creating appropriate adapters based on model_id
Defined Under Namespace
Classes: AdapterData
Constant Summary collapse
- ADAPTER_MAP =
Maps provider prefixes to adapter classes
{ 'openai' => { class_name: 'DSPy::OpenAI::LM::Adapters::OpenAIAdapter', gem_name: 'dspy-openai' }, 'anthropic' => { class_name: 'DSPy::Anthropic::LM::Adapters::AnthropicAdapter', gem_name: 'dspy-anthropic' }, 'ollama' => { class_name: 'DSPy::OpenAI::LM::Adapters::OllamaAdapter', gem_name: 'dspy-openai' }, 'gemini' => { class_name: 'DSPy::Gemini::LM::Adapters::GeminiAdapter', gem_name: 'dspy-gemini' }, 'openrouter' => { class_name: 'DSPy::OpenAI::LM::Adapters::OpenRouterAdapter', gem_name: 'dspy-openai' }, 'ruby_llm' => { class_name: 'DSPy::RubyLLM::LM::Adapters::RubyLLMAdapter', gem_name: 'dspy-ruby_llm' } }.freeze
- PROVIDERS_WITH_EXTRA_OPTIONS =
%w[openai anthropic ollama gemini openrouter ruby_llm].freeze
Class Method Summary collapse
-
.create(model_id, api_key:, **options) ⇒ DSPy::LM::Adapter
Creates an adapter instance based on model_id.
Class Method Details
.create(model_id, api_key:, **options) ⇒ DSPy::LM::Adapter
Creates an adapter instance based on model_id
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dspy/lm/adapter_factory.rb', line 37 def create(model_id, api_key:, **) provider, model = parse_model_id(model_id) adapter_class = get_adapter_class(provider) # Pass provider-specific options = { model: model, api_key: api_key } # Some providers accept additional options .merge!() if PROVIDERS_WITH_EXTRA_OPTIONS.include?(provider) adapter_class.new(**) end |