Class: Rubyagents::Model

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

Direct Known Subclasses

Rubyagents::Models::RubyLLMAdapter

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_name) ⇒ Model

Returns a new instance of Model.



91
92
93
# File 'lib/rubyagents/model.rb', line 91

def initialize(model_name)
  @model_name = model_name
end

Class Attribute Details

.registry ⇒ Object (readonly)

Returns the value of attribute registry.



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

def registry
  @registry
end

Instance Attribute Details

#model_name ⇒ Object (readonly)

Returns the value of attribute model_name.



89
90
91
# File 'lib/rubyagents/model.rb', line 89

def model_name
  @model_name
end

Class Method Details

.for(model_id) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rubyagents/model.rb', line 74

def for(model_id)
  if model_id.include?("/")
    prefix, model_name = model_id.split("/", 2)
    adapter_class = @registry[prefix]
    if adapter_class
      adapter_class.new(model_name)
    else
      Models::RubyLLMAdapter.new(model_name, provider: prefix)
    end
  else
    Models::RubyLLMAdapter.new(model_id)
  end
end

.register(prefix, klass) ⇒ Object



70
71
72
# File 'lib/rubyagents/model.rb', line 70

def register(prefix, klass)
  @registry[prefix] = klass
end

Instance Method Details

#generate(messages, tools: nil, &on_stream) ⇒ Object

Raises:

  • (NotImplementedError)


95
96
97
# File 'lib/rubyagents/model.rb', line 95

def generate(messages, tools: nil, &on_stream)
  raise NotImplementedError, "#{self.class} must implement #generate"
end