@@ -4,7 +4,7 @@ module DiscourseAi
44 module InferredConcepts
55 class Finder
66 # Identifies potential concepts from provided content
7- # Returns an array of concept names (strings)
7+ # Returns an array of concept names (strings)
88 def self . identify_concepts ( content )
99 return [ ] if content . blank?
1010
@@ -13,28 +13,29 @@ def self.identify_concepts(content)
1313 persona = DiscourseAi ::Personas ::ConceptFinder . new
1414 context = DiscourseAi ::Personas ::BotContext . new (
1515 messages : [ { type : :user , content : content } ] ,
16- user : Discourse . system_user
16+ user : Discourse . system_user .
17+ inferred_concepts : DiscourseAi ::InferredConcepts ::Manager . list_concepts ,
1718 )
18-
19+
1920 prompt = persona . craft_prompt ( context )
2021 response = llm . completion ( prompt , extract_json : true )
21-
22+
2223 return [ ] unless response . success?
23-
24+
2425 concepts = response . parsed_output [ "concepts" ]
2526 concepts || [ ]
2627 end
27-
28+
2829 # Creates or finds concepts in the database from provided names
2930 # Returns an array of InferredConcept instances
3031 def self . create_or_find_concepts ( concept_names )
3132 return [ ] if concept_names . blank?
32-
33+
3334 concept_names . map do |name |
3435 InferredConcept . find_or_create_by ( name : name )
3536 end
3637 end
37-
38+
3839 # Finds candidate topics to use for concept generation
3940 #
4041 # @param limit [Integer] Maximum number of topics to return
@@ -134,4 +135,4 @@ def self.find_candidate_posts(
134135 end
135136 end
136137 end
137- end
138+ end
0 commit comments