Class: Observ::Moderation
- Inherits:
-
Observation
- Object
- ActiveRecord::Base
- ApplicationRecord
- Observation
- Observ::Moderation
- Defined in:
- app/models/observ/moderation.rb
Instance Method Summary collapse
- #categories ⇒ Object
- #category_scores ⇒ Object
- #finalize(output:, usage: {}, cost_usd: 0.0, status_message: nil) ⇒ Object
-
#flagged? ⇒ Boolean
Moderation-specific helpers.
- #flagged_categories ⇒ Object
- #highest_score_category ⇒ Object
Methods inherited from Observation
Instance Method Details
#categories ⇒ Object
22 23 24 |
# File 'app/models/observ/moderation.rb', line 22 def categories &.dig("categories") || {} end |
#category_scores ⇒ Object
26 27 28 |
# File 'app/models/observ/moderation.rb', line 26 def category_scores &.dig("category_scores") || {} end |
#finalize(output:, usage: {}, cost_usd: 0.0, status_message: nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/models/observ/moderation.rb', line 5 def finalize(output:, usage: {}, cost_usd: 0.0, status_message: nil) merged_usage = (self.usage || {}).merge(usage.stringify_keys) update!( output: output.is_a?(String) ? output : output.to_json, usage: merged_usage, cost_usd: cost_usd, end_time: Time.current, status_message: ) end |
#flagged? ⇒ Boolean
Moderation-specific helpers
18 19 20 |
# File 'app/models/observ/moderation.rb', line 18 def flagged? &.dig("flagged") || false end |
#flagged_categories ⇒ Object
30 31 32 |
# File 'app/models/observ/moderation.rb', line 30 def flagged_categories &.dig("flagged_categories") || [] end |
#highest_score_category ⇒ Object
34 35 36 37 38 |
# File 'app/models/observ/moderation.rb', line 34 def highest_score_category return nil if category_scores.empty? category_scores.max_by { |_, score| score }&.first end |