Class: LlmClassifier::Classifier
- Inherits:
-
Object
- Object
- LlmClassifier::Classifier
- Defined in:
- lib/llm_classifier/classifier.rb
Overview
Base classifier class that provides a DSL for defining LLM-powered classifiers
Class Attribute Summary collapse
-
.after_classify_callbacks ⇒ Object
readonly
Returns the value of attribute after_classify_callbacks.
-
.before_classify_callbacks ⇒ Object
readonly
Returns the value of attribute before_classify_callbacks.
-
.defined_adapter ⇒ Object
readonly
Returns the value of attribute defined_adapter.
-
.defined_categories ⇒ Object
readonly
Returns the value of attribute defined_categories.
-
.defined_knowledge ⇒ Object
readonly
Returns the value of attribute defined_knowledge.
-
.defined_model ⇒ Object
readonly
Returns the value of attribute defined_model.
-
.defined_multi_label ⇒ Object
readonly
Returns the value of attribute defined_multi_label.
-
.defined_system_prompt ⇒ Object
readonly
Returns the value of attribute defined_system_prompt.
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .adapter(adapter_name = nil) ⇒ Object
- .after_classify(&block) ⇒ Object
- .before_classify(&block) ⇒ Object
- .categories(*cats) ⇒ Object
- .classify(input, **options) ⇒ Object
- .knowledge ⇒ Object
- .model(model_name = nil) ⇒ Object
- .multi_label(value = nil) ⇒ Object
- .system_prompt(prompt = nil) ⇒ Object
Instance Method Summary collapse
- #classify ⇒ Object
-
#initialize(input, **options) ⇒ Classifier
constructor
A new instance of Classifier.
Constructor Details
#initialize(input, **options) ⇒ Classifier
Returns a new instance of Classifier.
78 79 80 81 |
# File 'lib/llm_classifier/classifier.rb', line 78 def initialize(input, **) @input = input @options = end |
Class Attribute Details
.after_classify_callbacks ⇒ Object (readonly)
Returns the value of attribute after_classify_callbacks.
9 10 11 |
# File 'lib/llm_classifier/classifier.rb', line 9 def after_classify_callbacks @after_classify_callbacks end |
.before_classify_callbacks ⇒ Object (readonly)
Returns the value of attribute before_classify_callbacks.
9 10 11 |
# File 'lib/llm_classifier/classifier.rb', line 9 def before_classify_callbacks @before_classify_callbacks end |
.defined_adapter ⇒ Object (readonly)
Returns the value of attribute defined_adapter.
9 10 11 |
# File 'lib/llm_classifier/classifier.rb', line 9 def defined_adapter @defined_adapter end |
.defined_categories ⇒ Object (readonly)
Returns the value of attribute defined_categories.
9 10 11 |
# File 'lib/llm_classifier/classifier.rb', line 9 def defined_categories @defined_categories end |
.defined_knowledge ⇒ Object (readonly)
Returns the value of attribute defined_knowledge.
9 10 11 |
# File 'lib/llm_classifier/classifier.rb', line 9 def defined_knowledge @defined_knowledge end |
.defined_model ⇒ Object (readonly)
Returns the value of attribute defined_model.
9 10 11 |
# File 'lib/llm_classifier/classifier.rb', line 9 def defined_model @defined_model end |
.defined_multi_label ⇒ Object (readonly)
Returns the value of attribute defined_multi_label.
9 10 11 |
# File 'lib/llm_classifier/classifier.rb', line 9 def defined_multi_label @defined_multi_label end |
.defined_system_prompt ⇒ Object (readonly)
Returns the value of attribute defined_system_prompt.
9 10 11 |
# File 'lib/llm_classifier/classifier.rb', line 9 def defined_system_prompt @defined_system_prompt end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
76 77 78 |
# File 'lib/llm_classifier/classifier.rb', line 76 def input @input end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
76 77 78 |
# File 'lib/llm_classifier/classifier.rb', line 76 def @options end |
Class Method Details
.adapter(adapter_name = nil) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/llm_classifier/classifier.rb', line 37 def adapter(adapter_name = nil) if adapter_name.nil? @defined_adapter || LlmClassifier.configuration.adapter else @defined_adapter = adapter_name end end |
.after_classify(&block) ⇒ Object
66 67 68 69 |
# File 'lib/llm_classifier/classifier.rb', line 66 def after_classify(&block) @after_classify_callbacks ||= [] @after_classify_callbacks << block end |
.before_classify(&block) ⇒ Object
61 62 63 64 |
# File 'lib/llm_classifier/classifier.rb', line 61 def before_classify(&block) @before_classify_callbacks ||= [] @before_classify_callbacks << block end |
.categories(*cats) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/llm_classifier/classifier.rb', line 13 def categories(*cats) if cats.empty? @defined_categories || [] else @defined_categories = cats.map(&:to_s) end end |
.classify(input, **options) ⇒ Object
71 72 73 |
# File 'lib/llm_classifier/classifier.rb', line 71 def classify(input, **) new(input, **).classify end |
.knowledge ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/llm_classifier/classifier.rb', line 53 def knowledge(&) if block_given? @defined_knowledge = Knowledge.new @defined_knowledge.instance_eval(&) end @defined_knowledge end |
.model(model_name = nil) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/llm_classifier/classifier.rb', line 29 def model(model_name = nil) if model_name.nil? @defined_model || LlmClassifier.configuration.default_model else @defined_model = model_name end end |
.multi_label(value = nil) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/llm_classifier/classifier.rb', line 45 def multi_label(value = nil) if value.nil? @defined_multi_label || false else @defined_multi_label = value end end |
.system_prompt(prompt = nil) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/llm_classifier/classifier.rb', line 21 def system_prompt(prompt = nil) if prompt.nil? @defined_system_prompt else @defined_system_prompt = prompt end end |