discourse-ai/spec/lib/modules/ai_helper/chat_thread_titler_spec.rb
Roman Rizzi 8849caf136
DEV: Transition "Select model" settings to only use LlmModels (#675)
We no longer support the "provider:model" format in the "ai_helper_model" and
"ai_embeddings_semantic_search_hyde_model" settings. We'll migrate existing
values and work with our new data-driven LLM configs from now on.
2024-06-19 18:01:35 -03:00

74 lines
1.9 KiB
Ruby

# frozen_string_literal: true
RSpec.describe DiscourseAi::AiHelper::ChatThreadTitler do
subject(:titler) { described_class.new(thread) }
before { assign_fake_provider_to(:ai_helper_model) }
fab!(:thread) { Fabricate(:chat_thread) }
fab!(:chat_message) { Fabricate(:chat_message, thread: thread) }
fab!(:user)
describe "#cleanup" do
it "picks the first when there are multiple" do
titles = "The solitary horse\nThe horse etched in gold"
expected_title = "The solitary horse"
result = titler.cleanup(titles)
expect(result).to eq(expected_title)
end
it "cleans up double quotes enclosing the whole title" do
titles = '"The solitary horse"'
expected_title = "The solitary horse"
result = titler.cleanup(titles)
expect(result).to eq(expected_title)
end
it "cleans up single quotes enclosing the whole title" do
titles = "'The solitary horse'"
expected_title = "The solitary horse"
result = titler.cleanup(titles)
expect(result).to eq(expected_title)
end
it "leaves quotes in the middle of title" do
titles = "The 'solitary' horse"
expected_title = "The 'solitary' horse"
result = titler.cleanup(titles)
expect(result).to eq(expected_title)
end
it "parses the XML" do
titles = "Here is your title <title>The solitary horse</title> my friend"
expected_title = "The solitary horse"
result = titler.cleanup(titles)
expect(result).to eq(expected_title)
end
it "truncates long titles" do
titles = "O cavalo trota pelo campo" + " Pocotó" * 100
result = titler.cleanup(titles)
expect(result.size).to be <= 100
end
end
describe "#thread_content" do
it "returns the chat message and user" do
expect(titler.thread_content(thread)).to include(chat_message.message)
expect(titler.thread_content(thread)).to include(chat_message.user.username)
end
end
end