discourse-ai/spec/lib/modules/ai_bot/tools/random_picker_spec.rb
Sam 3a8d95f6b2
FEATURE: mentionable personas and random picker tool, context limits (#466)
1. Personas are now optionally mentionable, meaning that you can mention them either from public topics or PMs
       - Mentioning from PMs helps "switch" persona mid conversation, meaning if you want to look up sites setting you can invoke the site setting bot, or if you want to generate an image you can invoke dall e
        - Mentioning outside of PMs allows you to inject a bot reply in a topic trivially
     - We also add the support for max_context_posts this allow you to limit the amount of context you feed in, which can help control costs

2. Add support for a "random picker" tool that can be used to pick random numbers 

3. Clean up routing ai_personas -> ai-personas

4. Add Max Context Posts so users can control how much history a persona can consume (this is important for mentionable personas) 

Co-authored-by: Martin Brennan <martin@discourse.org>
2024-02-15 16:37:59 +11:00

58 lines
1.7 KiB
Ruby

# frozen_string_literal: true
require "rails_helper"
RSpec.describe DiscourseAi::AiBot::Tools::RandomPicker do
describe "#invoke" do
subject { described_class.new({ options: options }).invoke(nil, nil) }
context "with options as simple list of strings" do
let(:options) { %w[apple banana cherry] }
it "returns one of the options" do
expect(options).to include(subject[:result])
end
end
context "with options as ranges" do
let(:options) { %w[1-3 10-20] }
it "returns a number within one of the provided ranges" do
results = subject[:result]
expect(results).to all(
satisfy { |result| (1..3).include?(result) || (10..20).include?(result) },
)
end
end
context "with options as comma-separated values" do
let(:options) { %w[red,green,blue mon,tue,wed] }
it "returns one value from each comma-separated list" do
results = subject[:result]
expect(results).to include(a_kind_of(String))
results.each { |result| expect(result.split(",")).to include(result) }
end
end
context "with mixed options (list, range, and comma-separated)" do
let(:options) { %w[apple 1-3 mon,tue,wed] }
it "handles each option appropriately" do
results = subject[:result]
expect(results.size).to eq(options.size)
# Verifying each type of option is respected needs a more elaborate setup,
# potentially mocking or specific expectations for each type.
end
end
context "with an invalid format in options" do
let(:options) { ["invalid_format"] }
it "returns an error message for invalid formats" do
expect(subject[:result]).to include("invalid_format")
end
end
end
end