Class: LLM

Inherits:
Object
  • Object
show all
Defined in:
lib/llm.rb,
lib/llm/info.rb,
lib/llm/config.rb,
lib/llm/schema.rb,
lib/llm/stop_reason.rb,
lib/llm/clients/gemini.rb,
lib/llm/clients/open_ai.rb,
lib/llm/clients/anthropic.rb,
lib/llm/clients/gemini/request.rb,
lib/llm/clients/gemini/response.rb,
lib/llm/clients/open_ai/response.rb,
lib/llm/clients/anthropic/response.rb

Defined Under Namespace

Modules: Clients, Info, StopReason Classes: Config, Schema

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ LLM

Returns a new instance of LLM.



14
15
16
17
18
19
20
21
# File 'lib/llm.rb', line 14

def initialize(model)
  @canonical_name = model[:canonical_name]
  @display_name = model[:display_name]
  @provider = model[:provider]
  @client_class = model[:client_class]
  @default_params = model[:additional_default_required_parameters] || {}
  @supports_structured_outputs = model[:supports_structured_outputs] || false
end

Instance Attribute Details

#canonical_nameObject (readonly)

Returns the value of attribute canonical_name.



27
28
29
# File 'lib/llm.rb', line 27

def canonical_name
  @canonical_name
end

#default_paramsObject (readonly)

Returns the value of attribute default_params.



27
28
29
# File 'lib/llm.rb', line 27

def default_params
  @default_params
end

#display_nameObject (readonly)

Returns the value of attribute display_name.



27
28
29
# File 'lib/llm.rb', line 27

def display_name
  @display_name
end

#providerObject (readonly)

Returns the value of attribute provider.



27
28
29
# File 'lib/llm.rb', line 27

def provider
  @provider
end

Class Method Details

.all!Object



45
46
47
# File 'lib/llm.rb', line 45

def all!
  known_models
end

.configObject



36
37
38
# File 'lib/llm.rb', line 36

def self.config
  @config ||= LLM::Config.new
end

.from_string!(model_string) ⇒ Object

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
# File 'lib/llm.rb', line 49

def from_string!(model_string)
  model = known_models.find { |model| model.canonical_name == model_string }

  raise ArgumentError, "Unknown model: #{model_string}" unless model

  model
end

Instance Method Details

#clientObject



23
24
25
# File 'lib/llm.rb', line 23

def client
  client_class.new(llm: self)
end

#supports_structured_outputs?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/llm.rb', line 32

def supports_structured_outputs?
  @supports_structured_outputs
end