Sam 12869f2146
FIX: testing tool was not showing rag results (#867)
This changeset contains 4 fixes:

1. We were allowing running tests on unsaved tools,
this is problematic cause uploads are not yet associated or indexed
leading to confusing results. We now only show the test button when
tool is saved.


2. We were not properly scoping rag document fragements, this
meant that personas and ai tools could get results from other
unrelated tools, just to be filtered out later


3. index.search showed options as "optional" but implementation
required the second option

4. When testing tools searching through document fragments was
not working at all cause we did not properly load the tool
2024-10-25 16:01:25 +11:00

78 lines
2.2 KiB
Ruby

# frozen_string_literal: true
require "rails_helper"
describe "AI Tool Management", type: :system do
fab!(:admin)
before do
SiteSetting.ai_embeddings_enabled = true
sign_in(admin)
end
def ensure_can_run_test
find(".ai-tool-editor__test-button").click
modal = PageObjects::Modals::AiToolTest.new
modal.base_currency = "USD"
modal.target_currency = "EUR"
modal.amount = "100"
stub_request(:get, %r{https://open\.er-api\.com/v6/latest/USD}).to_return(
status: 200,
body: '{"rates": {"EUR": 0.85}}',
headers: {
"Content-Type" => "application/json",
},
)
modal.run_test
expect(modal).to have_content("exchange_rate")
expect(modal).to have_content("0.85")
modal.close
end
it "allows admin to create a new AI tool from preset" do
visit "/admin/plugins/discourse-ai/ai-tools"
expect(page).to have_content("Tools")
find(".ai-tool-list-editor__new-button").click
select_kit = PageObjects::Components::SelectKit.new(".ai-tool-editor__presets")
select_kit.expand
select_kit.select_row_by_value("exchange_rate")
find(".ai-tool-editor__next").click
expect(page.first(".parameter-row__required-toggle").checked?).to eq(true)
expect(page.first(".parameter-row__enum-toggle").checked?).to eq(false)
# not allowed to test yet
expect(page).not_to have_button(".ai-tool-editor__test-button")
expect(page).not_to have_button(".ai-tool-editor__delete")
find(".ai-tool-editor__save").click
expect(page).to have_content("Tool saved")
last_tool = AiTool.order("id desc").limit(1).first
visit "/admin/plugins/discourse-ai/ai-tools/#{last_tool.id}"
ensure_can_run_test
expect(page.first(".parameter-row__required-toggle").checked?).to eq(true)
expect(page.first(".parameter-row__enum-toggle").checked?).to eq(false)
visit "/admin/plugins/discourse-ai/ai-personas/new"
tool_id = AiTool.order("id desc").limit(1).pluck(:id).first
tool_selector = PageObjects::Components::SelectKit.new(".ai-persona-editor__tools")
tool_selector.expand
tool_selector.select_row_by_value("custom-#{tool_id}")
expect(tool_selector).to have_selected_value("custom-#{tool_id}")
end
end