Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 627fcaa

Browse files
committed
pass context
1 parent 67b0cfd commit 627fcaa

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

lib/inferred_concepts/applier.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,7 @@ def self.match_concepts_to_content(content, concept_list)
154154
return [] if content.blank? || concept_list.blank?
155155

156156
# Prepare user message with only the content
157-
user_message = <<~MESSAGE
158-
Content to analyze:
159-
#{content}
160-
MESSAGE
157+
user_message = content
161158

162159
# Use the ConceptMatcher persona to match concepts
163160
llm = DiscourseAi::Completions::Llm.default_llm
@@ -166,6 +163,7 @@ def self.match_concepts_to_content(content, concept_list)
166163
DiscourseAi::Personas::BotContext.new(
167164
messages: [{ type: :user, content: user_message }],
168165
user: Discourse.system_user,
166+
inferred_concepts: DiscourseAi::InferredConcepts::Manager.list_concepts,
169167
)
170168

171169
prompt = persona.craft_prompt(context)

lib/inferred_concepts/finder.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)