Class: DSPy::LM::Adapter

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

Overview

Base adapter interface for all LM providers

Direct Known Subclasses

AnthropicAdapter, OpenAIAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, api_key:) ⇒ Adapter

Returns a new instance of Adapter.



9
10
11
12
13
# File 'lib/dspy/lm/adapter.rb', line 9

def initialize(model:, api_key:)
  @model = model
  @api_key = api_key
  validate_configuration!
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/dspy/lm/adapter.rb', line 7

def api_key
  @api_key
end

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/dspy/lm/adapter.rb', line 7

def model
  @model
end

Instance Method Details

#chat(messages:, signature: nil, &block) ⇒ DSPy::LM::Response

Chat interface that all adapters must implement

Parameters:

  • messages (Array<Hash>)

    Array of message hashes with :role and :content

  • signature (DSPy::Signature, nil) (defaults to: nil)

    Optional signature for structured outputs

  • block (Proc)

    Optional streaming block

Returns:

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/dspy/lm/adapter.rb', line 20

def chat(messages:, signature: nil, &block)
  raise NotImplementedError, "Subclasses must implement #chat method"
end