discourse-ai/spec/requests/ai_bot/topic_serialization_spec.rb
Sam 7dc3c30fa4
FEATURE: correctly decorate AI bots (#1300)
AI bots come in 2 flavors

1. An LLM and LLM user, in this case we should decorate posts with persona name
2. A Persona user, in this case, in PMs we decorate with LLM name

(2) is a significant improvement, cause previously when creating a conversation
you could not tell which LLM you were talking to by simply looking at the post, you would
have to scroll to the top of the page.

* lint

* translation missing
2025-04-30 16:36:38 +10:00

38 lines
1015 B
Ruby

# frozen_string_literal: true
RSpec.describe "AI Bot Post Serializer" do
fab!(:current_user) { Fabricate(:user) }
fab!(:bot_user) { Fabricate(:user) }
before do
SiteSetting.ai_bot_enabled = true
sign_in(current_user)
end
describe "llm_name in post serializer" do
it "includes llm_name when custom field is set in a PM" do
pm_topic = Fabricate(:private_message_topic, user: current_user)
# Create a bot post with the custom field set
bot_post =
Fabricate(
:post,
topic: pm_topic,
user: bot_user,
custom_fields: {
DiscourseAi::AiBot::POST_AI_LLM_NAME_FIELD => "bob",
},
)
get "/t/#{pm_topic.id}.json"
expect(response.status).to eq(200)
json = response.parsed_body
bot_post_data = json["post_stream"]["posts"].find { |p| p["id"] == bot_post.id }
expect(bot_post_data).to have_key("llm_name")
expect(bot_post_data["llm_name"]).to eq("bob")
end
end
end