Skip to content

Commit

Permalink
Fixed up categories to replace and limit to 5
Browse files Browse the repository at this point in the history
  • Loading branch information
cguess committed Sep 23, 2024
1 parent 41f9e80 commit 7331023
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions app/models/concerns/categorizable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module Categorizable

# AVAILABLE_CATEGORIES = %w[Politics Sports Entertainment Technology]
CATEGORIZE_PROMPT = "Using this list of categories: #{@@archive_categories.join(",")}\ categorize the\
following statment into at most five of the\
categories. Return only the category names separated by commas and nothing else: "
following statment into the\
categories, ordering them by most relevant. Return only the category names separated by commas and nothing else: "

class_methods do
def property_to_categorize(property = nil, &block)
Expand All @@ -31,15 +31,22 @@ def categorize
stream: false }
)

categories = result.first["response"].strip.split(",").map(&:strip)
categories.each do |category|
self.category_list.add(category) if @@archive_categories.include?(category)
new_categories = result.first["response"].strip.split(",").map(&:strip)
new_categories = categories[0..4] if categories.length > 5

new_categories.each do |category|
self.category_list.add(category) # if @@archive_categories.include?(category)
end
end

def categorize!
# First we remove all the categories on the ArchiveItem
self.categories.each { |category| self.category_list.remove(category.name) }
self.save!
self.reload

self.categorize
self.save
self.save!
self.reload
end
end
Expand Down

0 comments on commit 7331023

Please sign in to comment.