Class: LlmClassifier::Result
- Inherits:
-
Object
- Object
- LlmClassifier::Result
- Defined in:
- lib/llm_classifier/result.rb
Overview
Result object returned from classification operations
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#confidence ⇒ Object
readonly
Returns the value of attribute confidence.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#input_tokens ⇒ Object
readonly
Returns the value of attribute input_tokens.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#output_tokens ⇒ Object
readonly
Returns the value of attribute output_tokens.
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
-
#reasoning ⇒ Object
readonly
Returns the value of attribute reasoning.
Class Method Summary collapse
- .failure(error:, raw_response: nil, metadata: {}) ⇒ Object
- .success(categories:, confidence: nil, reasoning: nil, raw_response: nil, metadata: {}, model: nil, input_tokens: nil, output_tokens: nil) ⇒ Object
Instance Method Summary collapse
- #category ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(categories: [], confidence: nil, reasoning: nil, raw_response: nil, error: nil, metadata: {}, model: nil, input_tokens: nil, output_tokens: nil) ⇒ Result
constructor
A new instance of Result.
- #multi_label? ⇒ Boolean
- #success? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(categories: [], confidence: nil, reasoning: nil, raw_response: nil, error: nil, metadata: {}, model: nil, input_tokens: nil, output_tokens: nil) ⇒ Result
Returns a new instance of Result.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/llm_classifier/result.rb', line 9 def initialize(categories: [], confidence: nil, reasoning: nil, raw_response: nil, error: nil, metadata: {}, model: nil, input_tokens: nil, output_tokens: nil) @categories = Array(categories) @confidence = confidence @reasoning = reasoning @raw_response = raw_response @metadata = @error = error @model = model @input_tokens = input_tokens @output_tokens = output_tokens end |
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
6 7 8 |
# File 'lib/llm_classifier/result.rb', line 6 def categories @categories end |
#confidence ⇒ Object (readonly)
Returns the value of attribute confidence.
6 7 8 |
# File 'lib/llm_classifier/result.rb', line 6 def confidence @confidence end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/llm_classifier/result.rb', line 6 def error @error end |
#input_tokens ⇒ Object (readonly)
Returns the value of attribute input_tokens.
6 7 8 |
# File 'lib/llm_classifier/result.rb', line 6 def input_tokens @input_tokens end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/llm_classifier/result.rb', line 6 def @metadata end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/llm_classifier/result.rb', line 6 def model @model end |
#output_tokens ⇒ Object (readonly)
Returns the value of attribute output_tokens.
6 7 8 |
# File 'lib/llm_classifier/result.rb', line 6 def output_tokens @output_tokens end |
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
6 7 8 |
# File 'lib/llm_classifier/result.rb', line 6 def raw_response @raw_response end |
#reasoning ⇒ Object (readonly)
Returns the value of attribute reasoning.
6 7 8 |
# File 'lib/llm_classifier/result.rb', line 6 def reasoning @reasoning end |
Class Method Details
.failure(error:, raw_response: nil, metadata: {}) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/llm_classifier/result.rb', line 70 def failure(error:, raw_response: nil, metadata: {}) new( error: error, raw_response: raw_response, metadata: ) end |
.success(categories:, confidence: nil, reasoning: nil, raw_response: nil, metadata: {}, model: nil, input_tokens: nil, output_tokens: nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/llm_classifier/result.rb', line 55 def success(categories:, confidence: nil, reasoning: nil, raw_response: nil, metadata: {}, model: nil, input_tokens: nil, output_tokens: nil) new( categories: categories, confidence: confidence, reasoning: reasoning, raw_response: raw_response, metadata: , model: model, input_tokens: input_tokens, output_tokens: output_tokens ) end |
Instance Method Details
#category ⇒ Object
31 32 33 |
# File 'lib/llm_classifier/result.rb', line 31 def category @categories.first end |
#failure? ⇒ Boolean
27 28 29 |
# File 'lib/llm_classifier/result.rb', line 27 def failure? !success? end |
#multi_label? ⇒ Boolean
35 36 37 |
# File 'lib/llm_classifier/result.rb', line 35 def multi_label? @categories.size > 1 end |
#success? ⇒ Boolean
23 24 25 |
# File 'lib/llm_classifier/result.rb', line 23 def success? @error.nil? end |
#to_h ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/llm_classifier/result.rb', line 39 def to_h { success: success?, categories: @categories, category: category, confidence: @confidence, reasoning: @reasoning, metadata: @metadata, error: @error, model: @model, input_tokens: @input_tokens, output_tokens: @output_tokens } end |