Class: Botiasloop::AutoLabel
- Inherits:
-
Object
- Object
- Botiasloop::AutoLabel
- Defined in:
- lib/botiasloop/auto_label.rb
Overview
Service class for automatically generating conversation labels Triggered after 3rd user message if no label is set
Constant Summary collapse
- MIN_MESSAGES_FOR_AUTO_LABEL =
3 user + 3 assistant messages
6
Class Method Summary collapse
-
.generate(conversation) ⇒ String?
Generate a label for the conversation if conditions are met.
-
.should_generate?(conversation) ⇒ Boolean
Check if auto-labelling should run.
Instance Method Summary collapse
-
#generate_label(conversation) ⇒ String?
Generate a label based on conversation content.
-
#initialize ⇒ AutoLabel
constructor
A new instance of AutoLabel.
Constructor Details
#initialize ⇒ AutoLabel
Returns a new instance of AutoLabel.
38 39 40 |
# File 'lib/botiasloop/auto_label.rb', line 38 def initialize @config = Config.instance end |
Class Method Details
.generate(conversation) ⇒ String?
Generate a label for the conversation if conditions are met
16 17 18 19 20 21 22 23 24 |
# File 'lib/botiasloop/auto_label.rb', line 16 def self.generate(conversation) return nil unless should_generate?(conversation) label = new.generate_label(conversation) Logger.info "[AutoLabel] Generated label '#{label}' for conversation #{conversation.uuid}" if label label end |
.should_generate?(conversation) ⇒ Boolean
Check if auto-labelling should run
30 31 32 33 34 35 36 |
# File 'lib/botiasloop/auto_label.rb', line 30 def self.should_generate?(conversation) return false unless Config.instance.features&.dig("auto_labelling", "enabled") != false return false if conversation.label? return false if conversation. < MIN_MESSAGES_FOR_AUTO_LABEL true end |
Instance Method Details
#generate_label(conversation) ⇒ String?
Generate a label based on conversation content
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/botiasloop/auto_label.rb', line 46 def generate_label(conversation) = conversation.history raw_label = generate_label_text() return nil unless raw_label formatted_label = format_label(raw_label) return nil unless valid_label?(formatted_label) formatted_label end |