Class: Legion::Extensions::Llm::Routing::BodyModelHintDecision

Inherits:
Data
  • Object
show all
Defined in:
lib/legion/extensions/llm/routing/records.rb

Overview

The disposition of a body-supplied model hint. The record performs no matching and cannot dispatch. See section 15.6.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ BodyModelHintDecision

Returns a new instance of BodyModelHintDecision.

Raises:

  • (errors::ValidationError)


249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/legion/extensions/llm/routing/records.rb', line 249

def initialize(**kwargs)
  kwargs = { model_constraint: nil, matched_whitelist: nil, matched_blacklist: nil }.merge(kwargs)
  Legion::Extensions::Llm::Inventory::RecordSupport.check_unknown_kwargs!(kwargs: kwargs, members: self.class.members)
  support = Legion::Extensions::Llm::Inventory::RecordSupport
  errors = Legion::Extensions::Llm::Inventory::Errors
  disposition = kwargs[:disposition]
  raise errors::ValidationError, 'invalid disposition' unless Legion::Extensions::Llm::Taxonomies::BODY_MODEL_HINT_DISPOSITIONS.include?(disposition)

  normalized_requested = optional_text(kwargs[:requested_model], :requested_model)
  normalized_constraint = optional_text(kwargs[:model_constraint], :model_constraint)
  validate_disposition_rules!(disposition, normalized_requested, normalized_constraint)

  super(
    requested_model: normalized_requested,
    disposition: disposition,
    model_constraint: normalized_constraint,
    matched_whitelist: optional_text(kwargs[:matched_whitelist], :matched_whitelist),
    matched_blacklist: optional_text(kwargs[:matched_blacklist], :matched_blacklist),
    settings_generation: support.nonnegative_integer(value: kwargs[:settings_generation], field: :settings_generation)
  )
end

Instance Attribute Details

#dispositionObject (readonly)

Returns the value of attribute disposition

Returns:

  • (Object)

    the current value of disposition



246
247
248
# File 'lib/legion/extensions/llm/routing/records.rb', line 246

def disposition
  @disposition
end

#matched_blacklistObject (readonly)

Returns the value of attribute matched_blacklist

Returns:

  • (Object)

    the current value of matched_blacklist



246
247
248
# File 'lib/legion/extensions/llm/routing/records.rb', line 246

def matched_blacklist
  @matched_blacklist
end

#matched_whitelistObject (readonly)

Returns the value of attribute matched_whitelist

Returns:

  • (Object)

    the current value of matched_whitelist



246
247
248
# File 'lib/legion/extensions/llm/routing/records.rb', line 246

def matched_whitelist
  @matched_whitelist
end

#model_constraintObject (readonly)

Returns the value of attribute model_constraint

Returns:

  • (Object)

    the current value of model_constraint



246
247
248
# File 'lib/legion/extensions/llm/routing/records.rb', line 246

def model_constraint
  @model_constraint
end

#requested_modelObject (readonly)

Returns the value of attribute requested_model

Returns:

  • (Object)

    the current value of requested_model



246
247
248
# File 'lib/legion/extensions/llm/routing/records.rb', line 246

def requested_model
  @requested_model
end

#settings_generationObject (readonly)

Returns the value of attribute settings_generation

Returns:

  • (Object)

    the current value of settings_generation



246
247
248
# File 'lib/legion/extensions/llm/routing/records.rb', line 246

def settings_generation
  @settings_generation
end

Instance Method Details

#optional_text(value, field) ⇒ Object



271
272
273
274
275
# File 'lib/legion/extensions/llm/routing/records.rb', line 271

def optional_text(value, field)
  return nil if value.nil?

  Legion::Extensions::Llm::Inventory::Identity.normalize_text(value: value, field: field)
end

#validate_disposition_rules!(disposition, requested_model, model_constraint) ⇒ Object

Raises:

  • (errors::ValidationError)


277
278
279
280
281
282
283
# File 'lib/legion/extensions/llm/routing/records.rb', line 277

def validate_disposition_rules!(disposition, requested_model, model_constraint)
  errors = Legion::Extensions::Llm::Inventory::Errors
  raise errors::ValidationError, 'only honored may carry a model_constraint' if disposition != :honored && !model_constraint.nil?
  return unless disposition == :absent && !requested_model.nil?

  raise errors::ValidationError, 'absent must carry a nil requested_model'
end