2023-08-28 20:43:58 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-01-04 08:44:07 -05:00
|
|
|
def has_rg?
|
|
|
|
if defined?(@has_rg)
|
|
|
|
@has_rg
|
|
|
|
else
|
|
|
|
@has_rg |= system("which rg")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.describe DiscourseAi::AiBot::Tools::SettingContext, if: has_rg? do
|
2024-07-30 12:44:57 -04:00
|
|
|
fab!(:llm_model)
|
|
|
|
|
|
|
|
let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }
|
|
|
|
let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }
|
2023-08-28 20:43:58 -04:00
|
|
|
|
2024-01-04 08:44:07 -05:00
|
|
|
before { SiteSetting.ai_bot_enabled = true }
|
|
|
|
|
|
|
|
def setting_context(setting_name)
|
2024-05-07 07:55:46 -04:00
|
|
|
described_class.new({ setting_name: setting_name }, bot_user: bot_user, llm: llm)
|
2023-08-28 20:43:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#execute" do
|
|
|
|
it "returns the context for core setting" do
|
2024-05-07 07:55:46 -04:00
|
|
|
result = setting_context("moderators_view_emails").invoke
|
2023-08-28 20:43:58 -04:00
|
|
|
|
|
|
|
expect(result[:setting_name]).to eq("moderators_view_emails")
|
|
|
|
|
|
|
|
expect(result[:context]).to include("site_settings.yml")
|
|
|
|
expect(result[:context]).to include("moderators_view_emails")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the context for plugin setting" do
|
2024-05-07 07:55:46 -04:00
|
|
|
result = setting_context("ai_bot_enabled").invoke
|
2023-08-28 20:43:58 -04:00
|
|
|
|
|
|
|
expect(result[:setting_name]).to eq("ai_bot_enabled")
|
|
|
|
expect(result[:context]).to include("ai_bot_enabled:")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the setting does not exist" do
|
|
|
|
it "returns an error message" do
|
2024-05-07 07:55:46 -04:00
|
|
|
result = setting_context("this_setting_does_not_exist").invoke
|
2024-01-04 08:44:07 -05:00
|
|
|
|
2023-08-28 20:43:58 -04:00
|
|
|
expect(result[:context]).to eq("This setting does not exist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|