Class: DSPy::LM::AdapterFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/dspy/lm/adapter_factory.rb

Overview

Factory for creating appropriate adapters based on model_id

Constant Summary collapse

ADAPTER_MAP =

Maps provider prefixes to adapter classes

{
  'openai' => 'OpenAIAdapter',
  'anthropic' => 'AnthropicAdapter'
}.freeze

Class Method Summary collapse

Class Method Details

.create(model_id, api_key:) ⇒ DSPy::LM::Adapter

Creates an adapter instance based on model_id

Parameters:

  • model_id (String)

    Full model identifier (e.g., “openai/gpt-4”)

  • api_key (String)

    API key for the provider

Returns:



18
19
20
21
22
23
# File 'lib/dspy/lm/adapter_factory.rb', line 18

def create(model_id, api_key:)
  provider, model = parse_model_id(model_id)
  adapter_class = get_adapter_class(provider)
  
  adapter_class.new(model: model, api_key: api_key)
end