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

Commit 6cb7b4d

Browse files
committed
stree
1 parent 2d6f4ea commit 6cb7b4d

File tree

4 files changed

+50
-48
lines changed

4 files changed

+50
-48
lines changed

lib/inferred_concepts/manager.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,10 @@ def match_content_to_concepts(content)
169169
existing_concepts = InferredConcept.all.pluck(:name)
170170
return [] if existing_concepts.empty?
171171

172-
DiscourseAi::InferredConcepts::Applier.new.match_concepts_to_content(content, existing_concepts)
172+
DiscourseAi::InferredConcepts::Applier.new.match_concepts_to_content(
173+
content,
174+
existing_concepts,
175+
)
173176
end
174177

175178
# Find candidate topics that are good for concept generation

spec/lib/inferred_concepts/applier_spec.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@
113113

114114
before do
115115
allow(DiscourseAi::InferredConcepts::Manager).to receive(:new).and_return(manager)
116-
allow(manager).to receive(:list_concepts).and_return(
117-
%w[programming testing ruby],
118-
)
116+
allow(manager).to receive(:list_concepts).and_return(%w[programming testing ruby])
119117
end
120118

121119
it "returns empty array for blank topic" do
@@ -153,9 +151,7 @@
153151

154152
before do
155153
allow(DiscourseAi::InferredConcepts::Manager).to receive(:new).and_return(manager)
156-
allow(manager).to receive(:list_concepts).and_return(
157-
%w[programming testing ruby],
158-
)
154+
allow(manager).to receive(:list_concepts).and_return(%w[programming testing ruby])
159155
end
160156

161157
it "returns empty array for blank post" do
@@ -213,8 +209,14 @@
213209
expect(persona_class_double).to receive(:default_llm_id).and_return(llm_model.id)
214210
expect(LlmModel).to receive(:find).and_return(llm_model)
215211
expect(DiscourseAi::Personas::Bot).to receive(:as).and_return(bot_double)
216-
expect(bot_double).to receive(:reply).and_yield(structured_output_double, nil, :structured_output)
217-
expect(structured_output_double).to receive(:read_buffered_property).with(:matching_concepts).and_return(%w[programming ruby])
212+
expect(bot_double).to receive(:reply).and_yield(
213+
structured_output_double,
214+
nil,
215+
:structured_output,
216+
)
217+
expect(structured_output_double).to receive(:read_buffered_property).with(
218+
:matching_concepts,
219+
).and_return(%w[programming ruby])
218220

219221
result = applier.match_concepts_to_content(content, concept_list)
220222
expect(result).to eq(%w[programming ruby])

spec/lib/inferred_concepts/finder_spec.rb

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@
3434
expect(persona_double).to receive(:default_llm_id).and_return(llm_model.id)
3535
expect(LlmModel).to receive(:find).with(llm_model.id).and_return(llm_model)
3636
expect(DiscourseAi::Personas::Bot).to receive(:as).and_return(bot_double)
37-
expect(bot_double).to receive(:reply).and_yield(structured_output_double, nil, :structured_output)
38-
expect(structured_output_double).to receive(:read_buffered_property).with(:concepts).and_return(%w[ruby programming testing])
37+
expect(bot_double).to receive(:reply).and_yield(
38+
structured_output_double,
39+
nil,
40+
:structured_output,
41+
)
42+
expect(structured_output_double).to receive(:read_buffered_property).with(
43+
:concepts,
44+
).and_return(%w[ruby programming testing])
3945

4046
result = finder.identify_concepts(content)
4147
expect(result).to eq(%w[ruby programming testing])
@@ -101,8 +107,7 @@
101107
end
102108

103109
it "finds topics meeting minimum criteria" do
104-
candidates =
105-
finder.find_candidate_topics(min_posts: 5, min_views: 100, min_likes: 10)
110+
candidates = finder.find_candidate_topics(min_posts: 5, min_views: 100, min_likes: 10)
106111

107112
expect(candidates).to include(good_topic)
108113
expect(candidates).not_to include(bad_topic)
@@ -223,8 +228,14 @@
223228
expect(persona_double).to receive(:default_llm_id).and_return(llm_model.id)
224229
expect(LlmModel).to receive(:find).with(llm_model.id).and_return(llm_model)
225230
expect(DiscourseAi::Personas::Bot).to receive(:as).and_return(bot_double)
226-
expect(bot_double).to receive(:reply).and_yield(structured_output_double, nil, :structured_output)
227-
expect(structured_output_double).to receive(:read_buffered_property).with(:streamlined_tags).and_return(%w[ruby testing])
231+
expect(bot_double).to receive(:reply).and_yield(
232+
structured_output_double,
233+
nil,
234+
:structured_output,
235+
)
236+
expect(structured_output_double).to receive(:read_buffered_property).with(
237+
:streamlined_tags,
238+
).and_return(%w[ruby testing])
228239

229240
result = finder.deduplicate_concepts(concept_names)
230241
expect(result).to eq(%w[ruby testing])

spec/lib/inferred_concepts/manager_spec.rb

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@
4343
finder = instance_double(DiscourseAi::InferredConcepts::Finder)
4444
allow(DiscourseAi::InferredConcepts::Finder).to receive(:new).and_return(finder)
4545

46-
allow(finder).to receive(:identify_concepts).with(
47-
content,
48-
).and_return(%w[ruby programming])
46+
allow(finder).to receive(:identify_concepts).with(content).and_return(%w[ruby programming])
4947

50-
allow(finder).to receive(:create_or_find_concepts).with(
51-
%w[ruby programming],
52-
).and_return([concept1])
48+
allow(finder).to receive(:create_or_find_concepts).with(%w[ruby programming]).and_return(
49+
[concept1],
50+
)
5351

5452
result = manager.generate_concepts_from_content(content)
5553
expect(result).to eq([concept1])
@@ -65,13 +63,11 @@
6563
applier = instance_double(DiscourseAi::InferredConcepts::Applier)
6664
allow(DiscourseAi::InferredConcepts::Applier).to receive(:new).and_return(applier)
6765

68-
allow(applier).to receive(:topic_content_for_analysis).with(
69-
topic,
70-
).and_return("topic content")
66+
allow(applier).to receive(:topic_content_for_analysis).with(topic).and_return("topic content")
7167

72-
allow(manager).to receive(:generate_concepts_from_content).with(
73-
"topic content",
74-
).and_return([concept1])
68+
allow(manager).to receive(:generate_concepts_from_content).with("topic content").and_return(
69+
[concept1],
70+
)
7571

7672
result = manager.generate_concepts_from_topic(topic)
7773
expect(result).to eq([concept1])
@@ -87,13 +83,11 @@
8783
applier = instance_double(DiscourseAi::InferredConcepts::Applier)
8884
allow(DiscourseAi::InferredConcepts::Applier).to receive(:new).and_return(applier)
8985

90-
allow(applier).to receive(:post_content_for_analysis).with(
91-
post,
92-
).and_return("post content")
86+
allow(applier).to receive(:post_content_for_analysis).with(post).and_return("post content")
9387

94-
allow(manager).to receive(:generate_concepts_from_content).with(
95-
"post content",
96-
).and_return([concept1])
88+
allow(manager).to receive(:generate_concepts_from_content).with("post content").and_return(
89+
[concept1],
90+
)
9791

9892
result = manager.generate_concepts_from_post(post)
9993
expect(result).to eq([concept1])
@@ -109,9 +103,7 @@
109103
applier = instance_double(DiscourseAi::InferredConcepts::Applier)
110104
allow(DiscourseAi::InferredConcepts::Applier).to receive(:new).and_return(applier)
111105

112-
allow(applier).to receive(:match_existing_concepts).with(
113-
topic,
114-
).and_return([concept1])
106+
allow(applier).to receive(:match_existing_concepts).with(topic).and_return([concept1])
115107

116108
result = manager.match_topic_to_concepts(topic)
117109
expect(result).to eq([concept1])
@@ -127,9 +119,7 @@
127119
applier = instance_double(DiscourseAi::InferredConcepts::Applier)
128120
allow(DiscourseAi::InferredConcepts::Applier).to receive(:new).and_return(applier)
129121

130-
allow(applier).to receive(
131-
:match_existing_concepts_for_post,
132-
).with(post).and_return([concept1])
122+
allow(applier).to receive(:match_existing_concepts_for_post).with(post).and_return([concept1])
133123

134124
result = manager.match_post_to_concepts(post)
135125
expect(result).to eq([concept1])
@@ -195,9 +185,7 @@
195185
finder = instance_double(DiscourseAi::InferredConcepts::Finder)
196186
allow(DiscourseAi::InferredConcepts::Finder).to receive(:new).and_return(finder)
197187

198-
allow(finder).to receive(:find_candidate_topics).with(
199-
**opts,
200-
).and_return([topic])
188+
allow(finder).to receive(:find_candidate_topics).with(**opts).and_return([topic])
201189

202190
result = manager.find_candidate_topics(opts)
203191
expect(result).to eq([topic])
@@ -210,9 +198,7 @@
210198
finder = instance_double(DiscourseAi::InferredConcepts::Finder)
211199
allow(DiscourseAi::InferredConcepts::Finder).to receive(:new).and_return(finder)
212200

213-
allow(finder).to receive(:find_candidate_posts).with(
214-
**opts,
215-
).and_return([post])
201+
allow(finder).to receive(:find_candidate_posts).with(**opts).and_return([post])
216202

217203
result = manager.find_candidate_posts(opts)
218204
expect(result).to eq([post])
@@ -231,9 +217,9 @@
231217
finder = instance_double(DiscourseAi::InferredConcepts::Finder)
232218
allow(DiscourseAi::InferredConcepts::Finder).to receive(:new).and_return(finder)
233219

234-
allow(finder).to receive(:deduplicate_concepts).at_least(
235-
:once,
236-
).and_return(%w[apple banana cat dog])
220+
allow(finder).to receive(:deduplicate_concepts).at_least(:once).and_return(
221+
%w[apple banana cat dog],
222+
)
237223

238224
allow(InferredConcept).to receive(:where).and_call_original
239225
allow(InferredConcept).to receive(:insert_all).and_call_original

0 commit comments

Comments
 (0)