discourse-ai/spec/lib/modules/ai_bot/tools/setting_context_spec.rb
Roman Rizzi f9d7d7f5f0
DEV: AI bot migration to the Llm pattern. (#343)
* DEV: AI bot migration to the Llm pattern.

We added tool and conversation context support to the Llm service in discourse-ai#366, meaning we met all the conditions to migrate this module.

This PR migrates to the new pattern, meaning adding a new bot now requires minimal effort as long as the service supports it. On top of this, we introduce the concept of a "Playground" to separate the PM-specific bits from the completion, allowing us to use the bot in other contexts like chat in the future. Commands are called tools, and we simplified all the placeholder logic to perform updates in a single place, making the flow more one-wayish.

* Followup fixes based on testing

* Cleanup unused inference code

* FIX: text-based tools could be in the middle of a sentence

* GPT-4-turbo support

* Use new LLM API
2024-01-04 10:44:07 -03:00

47 lines
1.4 KiB
Ruby

# frozen_string_literal: true
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
let(:bot_user) { User.find(DiscourseAi::AiBot::EntryPoint::GPT3_5_TURBO_ID) }
let(:llm) { DiscourseAi::Completions::Llm.proxy("gpt-3.5-turbo") }
before { SiteSetting.ai_bot_enabled = true }
def setting_context(setting_name)
described_class.new({ setting_name: setting_name })
end
describe "#execute" do
it "returns the context for core setting" do
result = setting_context("moderators_view_emails").invoke(bot_user, llm)
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
result = setting_context("ai_bot_enabled").invoke(bot_user, llm)
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
result = setting_context("this_setting_does_not_exist").invoke(bot_user, llm)
expect(result[:context]).to eq("This setting does not exist")
end
end
end
end