Class: Vangrail::OptionalReader
- Inherits:
-
Object
- Object
- Vangrail::OptionalReader
- Defined in:
- lib/vangrail/score.rb
Overview
Stable adapter around an optional local process, endpoint, or model runtime.
Instance Attribute Summary collapse
-
#feature_schema ⇒ Object
readonly
Returns the value of attribute feature_schema.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#model_id ⇒ Object
readonly
Returns the value of attribute model_id.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
-
#initialize(id:, model_id:, feature_schema:, provider: nil) ⇒ OptionalReader
constructor
A new instance of OptionalReader.
- #score(text, side:, **context) ⇒ Object
Constructor Details
#initialize(id:, model_id:, feature_schema:, provider: nil) ⇒ OptionalReader
Returns a new instance of OptionalReader.
118 119 120 121 122 123 |
# File 'lib/vangrail/score.rb', line 118 def initialize(id:, model_id:, feature_schema:, provider: nil) @id = id.to_s.freeze @model_id = model_id.to_s.freeze @feature_schema = Array(feature_schema).map(&:to_s).freeze @provider = provider end |
Instance Attribute Details
#feature_schema ⇒ Object (readonly)
Returns the value of attribute feature_schema.
116 117 118 |
# File 'lib/vangrail/score.rb', line 116 def feature_schema @feature_schema end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
116 117 118 |
# File 'lib/vangrail/score.rb', line 116 def id @id end |
#model_id ⇒ Object (readonly)
Returns the value of attribute model_id.
116 117 118 |
# File 'lib/vangrail/score.rb', line 116 def model_id @model_id end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
116 117 118 |
# File 'lib/vangrail/score.rb', line 116 def provider @provider end |
Instance Method Details
#score(text, side:, **context) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/vangrail/score.rb', line 125 def score(text, side:, **context) return missing(side) unless provider raw = if provider.respond_to?(:score) provider.score(text, side: side, **context) else provider.call(text, side: side, **context) end result = raw.is_a?(ScoreResult) ? raw : result_from(raw, side) identity_error(result, side) || result rescue StandardError => e ScoreResult.abstained( reader_id: id, model_id: model_id, feature_schema: feature_schema, side: side, reason: "#{e.class}: #{e.}", ) end |