stree
This commit is contained in:
parent
2d6f4eab0b
commit
6cb7b4dd04
|
@ -169,7 +169,10 @@ module DiscourseAi
|
|||
existing_concepts = InferredConcept.all.pluck(:name)
|
||||
return [] if existing_concepts.empty?
|
||||
|
||||
DiscourseAi::InferredConcepts::Applier.new.match_concepts_to_content(content, existing_concepts)
|
||||
DiscourseAi::InferredConcepts::Applier.new.match_concepts_to_content(
|
||||
content,
|
||||
existing_concepts,
|
||||
)
|
||||
end
|
||||
|
||||
# Find candidate topics that are good for concept generation
|
||||
|
|
|
@ -113,9 +113,7 @@ RSpec.describe DiscourseAi::InferredConcepts::Applier do
|
|||
|
||||
before do
|
||||
allow(DiscourseAi::InferredConcepts::Manager).to receive(:new).and_return(manager)
|
||||
allow(manager).to receive(:list_concepts).and_return(
|
||||
%w[programming testing ruby],
|
||||
)
|
||||
allow(manager).to receive(:list_concepts).and_return(%w[programming testing ruby])
|
||||
end
|
||||
|
||||
it "returns empty array for blank topic" do
|
||||
|
@ -153,9 +151,7 @@ RSpec.describe DiscourseAi::InferredConcepts::Applier do
|
|||
|
||||
before do
|
||||
allow(DiscourseAi::InferredConcepts::Manager).to receive(:new).and_return(manager)
|
||||
allow(manager).to receive(:list_concepts).and_return(
|
||||
%w[programming testing ruby],
|
||||
)
|
||||
allow(manager).to receive(:list_concepts).and_return(%w[programming testing ruby])
|
||||
end
|
||||
|
||||
it "returns empty array for blank post" do
|
||||
|
@ -213,8 +209,14 @@ RSpec.describe DiscourseAi::InferredConcepts::Applier do
|
|||
expect(persona_class_double).to receive(:default_llm_id).and_return(llm_model.id)
|
||||
expect(LlmModel).to receive(:find).and_return(llm_model)
|
||||
expect(DiscourseAi::Personas::Bot).to receive(:as).and_return(bot_double)
|
||||
expect(bot_double).to receive(:reply).and_yield(structured_output_double, nil, :structured_output)
|
||||
expect(structured_output_double).to receive(:read_buffered_property).with(:matching_concepts).and_return(%w[programming ruby])
|
||||
expect(bot_double).to receive(:reply).and_yield(
|
||||
structured_output_double,
|
||||
nil,
|
||||
:structured_output,
|
||||
)
|
||||
expect(structured_output_double).to receive(:read_buffered_property).with(
|
||||
:matching_concepts,
|
||||
).and_return(%w[programming ruby])
|
||||
|
||||
result = applier.match_concepts_to_content(content, concept_list)
|
||||
expect(result).to eq(%w[programming ruby])
|
||||
|
|
|
@ -34,8 +34,14 @@ RSpec.describe DiscourseAi::InferredConcepts::Finder do
|
|||
expect(persona_double).to receive(:default_llm_id).and_return(llm_model.id)
|
||||
expect(LlmModel).to receive(:find).with(llm_model.id).and_return(llm_model)
|
||||
expect(DiscourseAi::Personas::Bot).to receive(:as).and_return(bot_double)
|
||||
expect(bot_double).to receive(:reply).and_yield(structured_output_double, nil, :structured_output)
|
||||
expect(structured_output_double).to receive(:read_buffered_property).with(:concepts).and_return(%w[ruby programming testing])
|
||||
expect(bot_double).to receive(:reply).and_yield(
|
||||
structured_output_double,
|
||||
nil,
|
||||
:structured_output,
|
||||
)
|
||||
expect(structured_output_double).to receive(:read_buffered_property).with(
|
||||
:concepts,
|
||||
).and_return(%w[ruby programming testing])
|
||||
|
||||
result = finder.identify_concepts(content)
|
||||
expect(result).to eq(%w[ruby programming testing])
|
||||
|
@ -101,8 +107,7 @@ RSpec.describe DiscourseAi::InferredConcepts::Finder do
|
|||
end
|
||||
|
||||
it "finds topics meeting minimum criteria" do
|
||||
candidates =
|
||||
finder.find_candidate_topics(min_posts: 5, min_views: 100, min_likes: 10)
|
||||
candidates = finder.find_candidate_topics(min_posts: 5, min_views: 100, min_likes: 10)
|
||||
|
||||
expect(candidates).to include(good_topic)
|
||||
expect(candidates).not_to include(bad_topic)
|
||||
|
@ -223,8 +228,14 @@ RSpec.describe DiscourseAi::InferredConcepts::Finder do
|
|||
expect(persona_double).to receive(:default_llm_id).and_return(llm_model.id)
|
||||
expect(LlmModel).to receive(:find).with(llm_model.id).and_return(llm_model)
|
||||
expect(DiscourseAi::Personas::Bot).to receive(:as).and_return(bot_double)
|
||||
expect(bot_double).to receive(:reply).and_yield(structured_output_double, nil, :structured_output)
|
||||
expect(structured_output_double).to receive(:read_buffered_property).with(:streamlined_tags).and_return(%w[ruby testing])
|
||||
expect(bot_double).to receive(:reply).and_yield(
|
||||
structured_output_double,
|
||||
nil,
|
||||
:structured_output,
|
||||
)
|
||||
expect(structured_output_double).to receive(:read_buffered_property).with(
|
||||
:streamlined_tags,
|
||||
).and_return(%w[ruby testing])
|
||||
|
||||
result = finder.deduplicate_concepts(concept_names)
|
||||
expect(result).to eq(%w[ruby testing])
|
||||
|
|
|
@ -43,13 +43,11 @@ RSpec.describe DiscourseAi::InferredConcepts::Manager do
|
|||
finder = instance_double(DiscourseAi::InferredConcepts::Finder)
|
||||
allow(DiscourseAi::InferredConcepts::Finder).to receive(:new).and_return(finder)
|
||||
|
||||
allow(finder).to receive(:identify_concepts).with(
|
||||
content,
|
||||
).and_return(%w[ruby programming])
|
||||
allow(finder).to receive(:identify_concepts).with(content).and_return(%w[ruby programming])
|
||||
|
||||
allow(finder).to receive(:create_or_find_concepts).with(
|
||||
%w[ruby programming],
|
||||
).and_return([concept1])
|
||||
allow(finder).to receive(:create_or_find_concepts).with(%w[ruby programming]).and_return(
|
||||
[concept1],
|
||||
)
|
||||
|
||||
result = manager.generate_concepts_from_content(content)
|
||||
expect(result).to eq([concept1])
|
||||
|
@ -65,13 +63,11 @@ RSpec.describe DiscourseAi::InferredConcepts::Manager do
|
|||
applier = instance_double(DiscourseAi::InferredConcepts::Applier)
|
||||
allow(DiscourseAi::InferredConcepts::Applier).to receive(:new).and_return(applier)
|
||||
|
||||
allow(applier).to receive(:topic_content_for_analysis).with(
|
||||
topic,
|
||||
).and_return("topic content")
|
||||
allow(applier).to receive(:topic_content_for_analysis).with(topic).and_return("topic content")
|
||||
|
||||
allow(manager).to receive(:generate_concepts_from_content).with(
|
||||
"topic content",
|
||||
).and_return([concept1])
|
||||
allow(manager).to receive(:generate_concepts_from_content).with("topic content").and_return(
|
||||
[concept1],
|
||||
)
|
||||
|
||||
result = manager.generate_concepts_from_topic(topic)
|
||||
expect(result).to eq([concept1])
|
||||
|
@ -87,13 +83,11 @@ RSpec.describe DiscourseAi::InferredConcepts::Manager do
|
|||
applier = instance_double(DiscourseAi::InferredConcepts::Applier)
|
||||
allow(DiscourseAi::InferredConcepts::Applier).to receive(:new).and_return(applier)
|
||||
|
||||
allow(applier).to receive(:post_content_for_analysis).with(
|
||||
post,
|
||||
).and_return("post content")
|
||||
allow(applier).to receive(:post_content_for_analysis).with(post).and_return("post content")
|
||||
|
||||
allow(manager).to receive(:generate_concepts_from_content).with(
|
||||
"post content",
|
||||
).and_return([concept1])
|
||||
allow(manager).to receive(:generate_concepts_from_content).with("post content").and_return(
|
||||
[concept1],
|
||||
)
|
||||
|
||||
result = manager.generate_concepts_from_post(post)
|
||||
expect(result).to eq([concept1])
|
||||
|
@ -109,9 +103,7 @@ RSpec.describe DiscourseAi::InferredConcepts::Manager do
|
|||
applier = instance_double(DiscourseAi::InferredConcepts::Applier)
|
||||
allow(DiscourseAi::InferredConcepts::Applier).to receive(:new).and_return(applier)
|
||||
|
||||
allow(applier).to receive(:match_existing_concepts).with(
|
||||
topic,
|
||||
).and_return([concept1])
|
||||
allow(applier).to receive(:match_existing_concepts).with(topic).and_return([concept1])
|
||||
|
||||
result = manager.match_topic_to_concepts(topic)
|
||||
expect(result).to eq([concept1])
|
||||
|
@ -127,9 +119,7 @@ RSpec.describe DiscourseAi::InferredConcepts::Manager do
|
|||
applier = instance_double(DiscourseAi::InferredConcepts::Applier)
|
||||
allow(DiscourseAi::InferredConcepts::Applier).to receive(:new).and_return(applier)
|
||||
|
||||
allow(applier).to receive(
|
||||
:match_existing_concepts_for_post,
|
||||
).with(post).and_return([concept1])
|
||||
allow(applier).to receive(:match_existing_concepts_for_post).with(post).and_return([concept1])
|
||||
|
||||
result = manager.match_post_to_concepts(post)
|
||||
expect(result).to eq([concept1])
|
||||
|
@ -195,9 +185,7 @@ RSpec.describe DiscourseAi::InferredConcepts::Manager do
|
|||
finder = instance_double(DiscourseAi::InferredConcepts::Finder)
|
||||
allow(DiscourseAi::InferredConcepts::Finder).to receive(:new).and_return(finder)
|
||||
|
||||
allow(finder).to receive(:find_candidate_topics).with(
|
||||
**opts,
|
||||
).and_return([topic])
|
||||
allow(finder).to receive(:find_candidate_topics).with(**opts).and_return([topic])
|
||||
|
||||
result = manager.find_candidate_topics(opts)
|
||||
expect(result).to eq([topic])
|
||||
|
@ -210,9 +198,7 @@ RSpec.describe DiscourseAi::InferredConcepts::Manager do
|
|||
finder = instance_double(DiscourseAi::InferredConcepts::Finder)
|
||||
allow(DiscourseAi::InferredConcepts::Finder).to receive(:new).and_return(finder)
|
||||
|
||||
allow(finder).to receive(:find_candidate_posts).with(
|
||||
**opts,
|
||||
).and_return([post])
|
||||
allow(finder).to receive(:find_candidate_posts).with(**opts).and_return([post])
|
||||
|
||||
result = manager.find_candidate_posts(opts)
|
||||
expect(result).to eq([post])
|
||||
|
@ -231,9 +217,9 @@ RSpec.describe DiscourseAi::InferredConcepts::Manager do
|
|||
finder = instance_double(DiscourseAi::InferredConcepts::Finder)
|
||||
allow(DiscourseAi::InferredConcepts::Finder).to receive(:new).and_return(finder)
|
||||
|
||||
allow(finder).to receive(:deduplicate_concepts).at_least(
|
||||
:once,
|
||||
).and_return(%w[apple banana cat dog])
|
||||
allow(finder).to receive(:deduplicate_concepts).at_least(:once).and_return(
|
||||
%w[apple banana cat dog],
|
||||
)
|
||||
|
||||
allow(InferredConcept).to receive(:where).and_call_original
|
||||
allow(InferredConcept).to receive(:insert_all).and_call_original
|
||||
|
|
Loading…
Reference in New Issue