2023-05-16 13:38:21 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-01-04 08:44:07 -05:00
|
|
|
RSpec.describe DiscourseAi::AiBot::Bot do
|
|
|
|
subject(:bot) { described_class.as(bot_user) }
|
2023-09-14 17:02:37 -04:00
|
|
|
|
2023-10-23 02:00:58 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.ai_bot_enabled_chat_bots = "gpt-4"
|
|
|
|
SiteSetting.ai_bot_enabled = true
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:bot_user) { User.find(DiscourseAi::AiBot::EntryPoint::GPT4_ID) }
|
2023-05-16 13:38:21 -04:00
|
|
|
|
2024-01-04 08:44:07 -05:00
|
|
|
let!(:user) { Fabricate(:user) }
|
2023-10-23 02:00:58 -04:00
|
|
|
let!(:pm) do
|
2023-05-20 03:45:54 -04:00
|
|
|
Fabricate(
|
|
|
|
:private_message_topic,
|
|
|
|
title: "This is my special PM",
|
|
|
|
user: user,
|
|
|
|
topic_allowed_users: [
|
|
|
|
Fabricate.build(:topic_allowed_user, user: user),
|
|
|
|
Fabricate.build(:topic_allowed_user, user: bot_user),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
end
|
2024-01-04 08:44:07 -05:00
|
|
|
let!(:pm_post) { Fabricate(:post, topic: pm, user: user, raw: "Does my site has tags?") }
|
|
|
|
|
|
|
|
let(:function_call) { <<~TEXT }
|
|
|
|
Let me try using a function to get more info:<function_calls>
|
|
|
|
<invoke>
|
|
|
|
<tool_name>categories</tool_name>
|
|
|
|
</invoke>
|
|
|
|
</function_calls>
|
|
|
|
TEXT
|
|
|
|
|
|
|
|
let(:response) { "As expected, your forum has multiple tags" }
|
|
|
|
|
|
|
|
let(:llm_responses) { [function_call, response] }
|
|
|
|
|
|
|
|
describe "#reply" do
|
|
|
|
context "when using function chaining" do
|
|
|
|
it "yields a loading placeholder while proceeds to invoke the command" do
|
|
|
|
tool = DiscourseAi::AiBot::Tools::ListCategories.new({})
|
|
|
|
partial_placeholder = +(<<~HTML)
|
|
|
|
<details>
|
|
|
|
<summary>#{tool.summary}</summary>
|
|
|
|
<p></p>
|
|
|
|
</details>
|
2024-01-04 16:15:34 -05:00
|
|
|
|
2024-01-04 08:44:07 -05:00
|
|
|
HTML
|
|
|
|
|
|
|
|
context = {}
|
|
|
|
|
|
|
|
DiscourseAi::Completions::Llm.with_prepared_responses(llm_responses) do
|
|
|
|
bot.reply(context) do |_bot_reply_post, cancel, placeholder|
|
|
|
|
expect(placeholder).to eq(partial_placeholder) if placeholder
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-05-16 13:38:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|