Class: Legion::Extensions::Llm::Routing::Rejection
- Inherits:
-
Data
- Object
- Data
- Legion::Extensions::Llm::Routing::Rejection
- Defined in:
- lib/legion/extensions/llm/routing/records.rb
Overview
A routing rejection diagnosis. lex-llm validates/holds the value; legion-llm constructs routing diagnoses and HTTP mappings. See 15.5.
Instance Attribute Summary collapse
-
#candidate_counts ⇒ Object
readonly
Returns the value of attribute candidate_counts.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#explicit_pins ⇒ Object
readonly
Returns the value of attribute explicit_pins.
-
#http_status ⇒ Object
readonly
Returns the value of attribute http_status.
-
#inventory_generation ⇒ Object
readonly
Returns the value of attribute inventory_generation.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ Rejection
constructor
A new instance of Rejection.
- #validate_candidate_counts!(candidate_counts) ⇒ Object
- #validate_code!(code) ⇒ Object
- #validate_explicit_pins!(explicit_pins) ⇒ Object
- #validate_http_status!(http_status) ⇒ Object
Constructor Details
#initialize(**kwargs) ⇒ Rejection
Returns a new instance of Rejection.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/legion/extensions/llm/routing/records.rb', line 189 def initialize(**kwargs) kwargs = { explicit_pins: {}, http_status: nil, code: 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 raise errors::ValidationError, 'kind must be a Taxonomies::REJECTION_KINDS value' unless Legion::Extensions::Llm::Taxonomies::REJECTION_KINDS.include?(kwargs[:kind]) super( kind: kwargs[:kind], reason: support.sanitized_reason(value: kwargs[:reason], field: :reason), inventory_generation: support.nonnegative_integer(value: kwargs[:inventory_generation], field: :inventory_generation), candidate_counts: validate_candidate_counts!(kwargs[:candidate_counts]), explicit_pins: validate_explicit_pins!(kwargs[:explicit_pins]), http_status: validate_http_status!(kwargs[:http_status]), code: validate_code!(kwargs[:code]) ) end |
Instance Attribute Details
#candidate_counts ⇒ Object (readonly)
Returns the value of attribute candidate_counts
186 187 188 |
# File 'lib/legion/extensions/llm/routing/records.rb', line 186 def candidate_counts @candidate_counts end |
#code ⇒ Object (readonly)
Returns the value of attribute code
186 187 188 |
# File 'lib/legion/extensions/llm/routing/records.rb', line 186 def code @code end |
#explicit_pins ⇒ Object (readonly)
Returns the value of attribute explicit_pins
186 187 188 |
# File 'lib/legion/extensions/llm/routing/records.rb', line 186 def explicit_pins @explicit_pins end |
#http_status ⇒ Object (readonly)
Returns the value of attribute http_status
186 187 188 |
# File 'lib/legion/extensions/llm/routing/records.rb', line 186 def http_status @http_status end |
#inventory_generation ⇒ Object (readonly)
Returns the value of attribute inventory_generation
186 187 188 |
# File 'lib/legion/extensions/llm/routing/records.rb', line 186 def inventory_generation @inventory_generation end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind
186 187 188 |
# File 'lib/legion/extensions/llm/routing/records.rb', line 186 def kind @kind end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason
186 187 188 |
# File 'lib/legion/extensions/llm/routing/records.rb', line 186 def reason @reason end |
Instance Method Details
#validate_candidate_counts!(candidate_counts) ⇒ Object
207 208 209 210 211 212 213 214 215 216 |
# File 'lib/legion/extensions/llm/routing/records.rb', line 207 def validate_candidate_counts!(candidate_counts) errors = Legion::Extensions::Llm::Inventory::Errors raise errors::ValidationError, 'candidate_counts must be a Hash' unless candidate_counts.is_a?(::Hash) candidate_counts.each do |key, value| raise errors::ValidationError, 'candidate_counts keys must be Symbols' unless key.is_a?(::Symbol) raise errors::ValidationError, 'candidate_counts values must be nonnegative Integers' unless value.is_a?(::Integer) && !value.negative? end candidate_counts.dup.freeze end |
#validate_code!(code) ⇒ Object
235 236 237 238 239 240 241 |
# File 'lib/legion/extensions/llm/routing/records.rb', line 235 def validate_code!(code) return nil if code.nil? return code if code.is_a?(::Symbol) return code.dup.freeze if code.is_a?(::String) && !code.strip.empty? raise Legion::Extensions::Llm::Inventory::Errors::ValidationError, 'code must be nil or a nonempty Symbol/String' end |
#validate_explicit_pins!(explicit_pins) ⇒ Object
218 219 220 221 222 223 224 225 226 |
# File 'lib/legion/extensions/llm/routing/records.rb', line 218 def validate_explicit_pins!(explicit_pins) errors = Legion::Extensions::Llm::Inventory::Errors raise errors::ValidationError, 'explicit_pins must be a Hash' unless explicit_pins.is_a?(::Hash) unless explicit_pins.keys.all? { |key| %i[provider instance model tier].include?(key) } raise errors::ValidationError, 'explicit_pins may contain only provider/instance/model/tier' end Legion::Extensions::Llm::Inventory::ImmutableValue.copy_and_freeze(value: explicit_pins, field: :explicit_pins) end |
#validate_http_status!(http_status) ⇒ Object
228 229 230 231 232 233 |
# File 'lib/legion/extensions/llm/routing/records.rb', line 228 def validate_http_status!(http_status) return nil if http_status.nil? return http_status if http_status.is_a?(::Integer) && (100..599).cover?(http_status) raise Legion::Extensions::Llm::Inventory::Errors::ValidationError, 'http_status must be nil or 100..599' end |