mirror of
https://github.com/we-promise/sure.git
synced 2026-05-29 23:39:03 +00:00
feat(ai): self-host settings UI for Anthropic provider (5/5)
Adds the Anthropic panel and the install-wide LLM provider selector to the self-hosting settings page, plus a shared data-retention disclosure that covers both OpenAI and Anthropic. - New _llm_provider_selector partial: select for Setting.llm_provider (openai | anthropic), respects the LLM_PROVIDER env var (disables the control + shows the "configured through environment variables" hint when set, mirroring the existing OpenAI panel behaviour), and renders a compact data-handling block with one-line retention statements for each provider. - New _anthropic_settings partial mirrors _openai_settings exactly: password-field for the API key with **** redaction, optional base_url (for AWS Bedrock / GCP Vertex), optional default model. All three fields disable when their ENV var is set. - show.html.erb renders provider selector + OpenAI panel + Anthropic panel under the same "General" section so users can configure either (or both) without switching pages. - Settings::HostingsController#update now permits and persists anthropic_access_token (ignoring the **** placeholder, same pattern as OpenAI), anthropic_base_url, anthropic_model, and llm_provider (validated against %w[openai anthropic]). On Setting::ValidationError the rescue branch preserves anthropic_base_url / anthropic_model input so the form re-renders with the user's typed values intact — parity with the issue #1824 fix for OpenAI. - Locale keys added under settings.hostings.{llm_provider_selector, anthropic_settings}. Tests cover token update + placeholder redaction, base_url + model update, llm_provider switch to anthropic, and rejection of unknown provider values. The existing GET render test still passes, exercising all three new partials. Closes the 5/5 Anthropic series stacked on #1986.
This commit is contained in:
@@ -74,6 +74,51 @@ class Settings::HostingsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
test "can update anthropic access token when self hosting is enabled" do
|
||||
with_self_hosting do
|
||||
patch settings_hosting_url, params: { setting: { anthropic_access_token: "sk-ant-test" } }
|
||||
|
||||
assert_equal "sk-ant-test", Setting.anthropic_access_token
|
||||
end
|
||||
end
|
||||
|
||||
test "ignores redacted anthropic token placeholder" do
|
||||
with_self_hosting do
|
||||
Setting.anthropic_access_token = "previous-token"
|
||||
|
||||
patch settings_hosting_url, params: { setting: { anthropic_access_token: "********" } }
|
||||
|
||||
assert_equal "previous-token", Setting.anthropic_access_token
|
||||
end
|
||||
end
|
||||
|
||||
test "can update anthropic base_url and model" do
|
||||
with_self_hosting do
|
||||
patch settings_hosting_url, params: { setting: { anthropic_base_url: "https://bedrock.example.com", anthropic_model: "claude-opus-4-7" } }
|
||||
|
||||
assert_equal "https://bedrock.example.com", Setting.anthropic_base_url
|
||||
assert_equal "claude-opus-4-7", Setting.anthropic_model
|
||||
end
|
||||
end
|
||||
|
||||
test "can update llm_provider to anthropic" do
|
||||
with_self_hosting do
|
||||
patch settings_hosting_url, params: { setting: { llm_provider: "anthropic" } }
|
||||
|
||||
assert_equal "anthropic", Setting.llm_provider
|
||||
end
|
||||
end
|
||||
|
||||
test "rejects unknown llm_provider values" do
|
||||
with_self_hosting do
|
||||
Setting.llm_provider = "openai"
|
||||
|
||||
patch settings_hosting_url, params: { setting: { llm_provider: "bogus" } }
|
||||
|
||||
assert_equal "openai", Setting.llm_provider
|
||||
end
|
||||
end
|
||||
|
||||
test "can update openai uri base and model together when self hosting is enabled" do
|
||||
with_self_hosting do
|
||||
patch settings_hosting_url, params: { setting: { openai_uri_base: "https://api.example.com/v1", openai_model: "gpt-4" } }
|
||||
|
||||
Reference in New Issue
Block a user