2024-06-21 03:32:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe "Admin dashboard", type: :system do
|
|
|
|
fab!(:admin)
|
|
|
|
|
|
|
|
it "correctly sets defaults" do
|
2024-06-23 19:59:42 -04:00
|
|
|
SiteSetting.ai_bot_enabled = true
|
|
|
|
|
2024-06-21 03:32:15 -04:00
|
|
|
sign_in(admin)
|
|
|
|
|
|
|
|
visit "/admin/plugins/discourse-ai/ai-llms"
|
|
|
|
|
|
|
|
find(".ai-llms-list-editor__new").click()
|
|
|
|
|
|
|
|
select_kit = PageObjects::Components::SelectKit.new(".ai-llm-editor__presets")
|
|
|
|
|
|
|
|
select_kit.expand
|
|
|
|
select_kit.select_row_by_value("anthropic-claude-3-haiku")
|
|
|
|
|
|
|
|
find(".ai-llm-editor__next").click()
|
|
|
|
find("input.ai-llm-editor__api-key").fill_in(with: "abcd")
|
|
|
|
|
2024-06-23 19:59:42 -04:00
|
|
|
PageObjects::Components::DToggleSwitch.new(".ai-llm-editor__enabled-chat-bot").toggle
|
|
|
|
|
2024-06-21 03:32:15 -04:00
|
|
|
find(".ai-llm-editor__save").click()
|
|
|
|
|
|
|
|
expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-llms")
|
|
|
|
|
|
|
|
llm = LlmModel.order(:id).last
|
|
|
|
expect(llm.api_key).to eq("abcd")
|
|
|
|
|
|
|
|
preset = DiscourseAi::Completions::Llm.presets.find { |p| p[:id] == "anthropic" }
|
|
|
|
|
|
|
|
model_preset = preset[:models].find { |m| m[:name] == "claude-3-haiku" }
|
|
|
|
|
|
|
|
expect(llm.name).to eq("claude-3-haiku")
|
|
|
|
expect(llm.url).to eq(preset[:endpoint])
|
|
|
|
expect(llm.tokenizer).to eq(preset[:tokenizer].to_s)
|
|
|
|
expect(llm.max_prompt_tokens.to_i).to eq(model_preset[:tokens])
|
|
|
|
expect(llm.provider).to eq("anthropic")
|
|
|
|
expect(llm.display_name).to eq(model_preset[:display_name])
|
2024-06-23 19:59:42 -04:00
|
|
|
expect(llm.user_id).not_to be_nil
|
2024-06-21 03:32:15 -04:00
|
|
|
end
|
|
|
|
end
|