mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-03 10:06:05 +08:00
This PR modifies Discourse AI to provide an option for role-based auth into Bedrock instances. It creates a new provider_param in within aws_bedrock, called :role_arn. If this provider_param is set, the AWSBedrock endpoint will use a different calling pattern (sts.assume_role, etc.) to provide keyless authentication. <img width="455" height="311" alt="image" src="https://github.com/user-attachments/assets/a9baa636-6768-4291-b759-d96bb77d71ef" /> --------- Co-authored-by: Rafael Silva <xfalcox@gmail.com>
59 lines
1.7 KiB
Ruby
59 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe LlmModel do
|
|
before { enable_current_plugin }
|
|
|
|
describe "api_key" do
|
|
fab!(:llm_model, :seeded_model)
|
|
|
|
before { ENV["DISCOURSE_AI_SEEDED_LLM_API_KEY_2"] = "blabla" }
|
|
|
|
it "should use environment variable over database value if seeded LLM" do
|
|
expect(llm_model.api_key).to eq("blabla")
|
|
end
|
|
end
|
|
|
|
describe "#credit_system_enabled?" do
|
|
fab!(:seeded_model)
|
|
fab!(:regular_model, :llm_model)
|
|
|
|
it "returns false for non-seeded models" do
|
|
expect(regular_model.credit_system_enabled?).to be false
|
|
end
|
|
|
|
it "returns false for seeded models without credit allocation" do
|
|
expect(seeded_model.credit_system_enabled?).to be false
|
|
end
|
|
|
|
it "returns true for seeded models with credit allocation" do
|
|
Fabricate(:llm_credit_allocation, llm_model: seeded_model)
|
|
expect(seeded_model.credit_system_enabled?).to be true
|
|
end
|
|
end
|
|
|
|
describe "AWS Bedrock provider validation" do
|
|
fab!(:bedrock_model, :bedrock_model)
|
|
|
|
it "requires either access_key_id or role_arn" do
|
|
# Should fail with neither
|
|
bedrock_model.provider_params = { region: "us-east-1" }
|
|
expect(bedrock_model.valid?).to be false
|
|
expect(bedrock_model.errors[:base]).to include(
|
|
I18n.t("discourse_ai.llm_models.bedrock_missing_auth"),
|
|
)
|
|
end
|
|
|
|
it "is valid with access_key_id only" do
|
|
bedrock_model.provider_params = { region: "us-east-1", access_key_id: "test_key" }
|
|
expect(bedrock_model.valid?).to be true
|
|
end
|
|
|
|
it "is valid with role_arn only" do
|
|
bedrock_model.provider_params = {
|
|
region: "us-east-1",
|
|
role_arn: "arn:aws:iam::123:role/test",
|
|
}
|
|
expect(bedrock_model.valid?).to be true
|
|
end
|
|
end
|
|
end
|