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:, **options) ⇒ 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

  • options (Hash)

    Additional adapter-specific options

Returns:



19
20
21
22
23
24
25
26
27
28
# File 'lib/dspy/lm/adapter_factory.rb', line 19

def create(model_id, api_key:, **options)
  provider, model = parse_model_id(model_id)
  adapter_class = get_adapter_class(provider)
  
  # Pass provider-specific options
  adapter_options = { model: model, api_key: api_key }
  adapter_options.merge!(options) if provider == 'openai' # Only OpenAI accepts structured_outputs for now
  
  adapter_class.new(**adapter_options)
end