Class: Kernai::Model
- Inherits:
-
Object
- Object
- Kernai::Model
- Defined in:
- lib/kernai/model.rb
Overview
Declarative description of an LLM: its vendor id and the set of media modalities it can accept as input or emit as output. Capabilities drive two things in the kernel:
1. Instruction builder sections (don't advertise vision to a text-only
model, don't describe image generation to a chat-only model).
2. Skill filtering — skills declaring `requires :vision` are hidden
from agents whose model can't satisfy them.
Providers receive the Model instance on every call and use it to decide how to encode multimodal parts (or fall back to text).
Constant Summary collapse
- INPUT_CAPABILITIES =
%i[text vision audio_in video_in document_in].freeze
- OUTPUT_CAPABILITIES =
%i[text image_gen audio_out].freeze
- CAPABILITIES =
(INPUT_CAPABILITIES + OUTPUT_CAPABILITIES).uniq.freeze
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(id:, capabilities: %i[text])) ⇒ Model
constructor
A new instance of Model.
-
#supported_media_inputs ⇒ Object
Which Media.kind values this model can accept in inbound messages.
- #supports?(*caps) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(id:, capabilities: %i[text])) ⇒ Model
Returns a new instance of Model.
22 23 24 25 26 27 28 |
# File 'lib/kernai/model.rb', line 22 def initialize(id:, capabilities: %i[text]) raise ArgumentError, 'id is required' if id.nil? || id.to_s.empty? @id = id.to_s @capabilities = capabilities.map(&:to_sym).freeze freeze end |
Instance Attribute Details
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
20 21 22 |
# File 'lib/kernai/model.rb', line 20 def capabilities @capabilities end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
20 21 22 |
# File 'lib/kernai/model.rb', line 20 def id @id end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
49 50 51 |
# File 'lib/kernai/model.rb', line 49 def ==(other) other.is_a?(Model) && other.id == @id && other.capabilities == @capabilities end |
#hash ⇒ Object
54 55 56 |
# File 'lib/kernai/model.rb', line 54 def hash [@id, @capabilities].hash end |
#supported_media_inputs ⇒ Object
Which Media.kind values this model can accept in inbound messages.
35 36 37 38 39 40 41 42 43 |
# File 'lib/kernai/model.rb', line 35 def supported_media_inputs mapping = { vision: :image, audio_in: :audio, video_in: :video, document_in: :document } @capabilities.filter_map { |c| mapping[c] } end |
#supports?(*caps) ⇒ Boolean
30 31 32 |
# File 'lib/kernai/model.rb', line 30 def supports?(*caps) caps.flatten.all? { |c| @capabilities.include?(c.to_sym) } end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/kernai/model.rb', line 45 def to_s @id end |