Class: RubyPi::LLM::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_pi/llm/model.rb

Overview

A model descriptor that pairs a provider identifier with a specific model name. Use the factory method RubyPi::LLM.model to create provider instances directly, or instantiate a Model object for deferred construction.

Examples:

Creating a model descriptor

model = RubyPi::LLM::Model.new(provider: :gemini, name: "gemini-2.0-flash")
model.provider  # => :gemini
model.name       # => "gemini-2.0-flash"
provider = model.build  # => RubyPi::LLM::Gemini instance

Using the factory shortcut

provider = RubyPi::LLM.model(:openai, "gpt-4o")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider:, name:) ⇒ Model

Creates a new Model descriptor.

Parameters:

  • provider (Symbol, String)

    provider identifier

  • name (String)

    model name



34
35
36
37
# File 'lib/ruby_pi/llm/model.rb', line 34

def initialize(provider:, name:)
  @provider = provider.to_sym
  @name = name.to_s
end

Instance Attribute Details

#nameString (readonly)

Returns the model name within the provider.

Returns:

  • (String)

    the model name within the provider



28
29
30
# File 'lib/ruby_pi/llm/model.rb', line 28

def name
  @name
end

#providerSymbol (readonly)

Returns the provider identifier (:gemini, :anthropic, :openai).

Returns:

  • (Symbol)

    the provider identifier (:gemini, :anthropic, :openai)



25
26
27
# File 'lib/ruby_pi/llm/model.rb', line 25

def provider
  @provider
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Equality comparison based on provider and name.

Parameters:

Returns:

  • (Boolean)


68
69
70
# File 'lib/ruby_pi/llm/model.rb', line 68

def ==(other)
  other.is_a?(Model) && @provider == other.provider && @name == other.name
end

#build(**options) ⇒ RubyPi::LLM::BaseProvider

Builds a configured provider instance from this model descriptor. Delegates to RubyPi::LLM.model for provider construction.

Parameters:

  • options (Hash)

    additional options passed to the provider constructor

Returns:



44
45
46
# File 'lib/ruby_pi/llm/model.rb', line 44

def build(**options)
  RubyPi::LLM.model(@provider, @name, **options)
end

#hashInteger

Hash code for use in hash keys and sets.

Returns:

  • (Integer)


77
78
79
# File 'lib/ruby_pi/llm/model.rb', line 77

def hash
  [@provider, @name].hash
end

#to_hHash

Returns a hash representation of the model descriptor.

Returns:

  • (Hash)


51
52
53
# File 'lib/ruby_pi/llm/model.rb', line 51

def to_h
  { provider: @provider, name: @name }
end

#to_sString Also known as: inspect

Returns a human-readable string representation.

Returns:

  • (String)


58
59
60
# File 'lib/ruby_pi/llm/model.rb', line 58

def to_s
  "#<RubyPi::LLM::Model provider=#{@provider.inspect} name=#{@name.inspect}>"
end