Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: add application inference profile support for AWS Bedrock (#38904)

Rafael dos Santos Silva99edc6f0e149
diff --git a/plugins/discourse-ai/app/models/llm_model.rb b/plugins/discourse-ai/app/models/llm_model.rb
index cf2eabe9cd1..64d92218c69 100644
--- a/plugins/discourse-ai/app/models/llm_model.rb
+++ b/plugins/discourse-ai/app/models/llm_model.rb
@@ -61,6 +61,7 @@ class LlmModel < ActiveRecord::Base
access_key_id: :secret,
role_arn: :text,
region: :text,
+ inference_profile_arn: :text,
enable_reasoning: :checkbox,
adaptive_thinking: {
type: :checkbox,
diff --git a/plugins/discourse-ai/config/locales/client.en.yml b/plugins/discourse-ai/config/locales/client.en.yml
index 6cfe0dc9fc0..58ac0c510cb 100644
--- a/plugins/discourse-ai/config/locales/client.en.yml
+++ b/plugins/discourse-ai/config/locales/client.en.yml
@@ -969,6 +969,7 @@ en:
provider_fields:
access_key_id: "AWS Bedrock access key ID"
role_arn: "AWS Bedrock Role ARN"
+ inference_profile_arn: "AWS Bedrock application inference profile ARN"
region: "AWS Bedrock region"
organization: "Optional OpenAI organization ID"
disable_system_prompt: "Disable system message in prompts"
diff --git a/plugins/discourse-ai/lib/completions/endpoints/aws_bedrock.rb b/plugins/discourse-ai/lib/completions/endpoints/aws_bedrock.rb
index 0416895d9ed..6a597b4e806 100644
--- a/plugins/discourse-ai/lib/completions/endpoints/aws_bedrock.rb
+++ b/plugins/discourse-ai/lib/completions/endpoints/aws_bedrock.rb
@@ -95,13 +95,20 @@ module DiscourseAi
def model_uri
region = llm_model.lookup_custom_param("region")
+ inference_profile_arn = llm_model.lookup_custom_param("inference_profile_arn")
- if region.blank? || bedrock_model_id.blank?
+ model_id =
+ if inference_profile_arn.present?
+ URI.encode_www_form_component(inference_profile_arn)
+ else
+ bedrock_model_id
+ end
+
+ if region.blank? || model_id.blank?
raise CompletionFailed.new(I18n.t("discourse_ai.llm_models.bedrock_invalid_url"))
end
- api_url =
- "https://bedrock-runtime.#{region}.amazonaws.com/model/#{bedrock_model_id}/invoke"
+ api_url = "https://bedrock-runtime.#{region}.amazonaws.com/model/#{model_id}/invoke"
api_url = @streaming_mode ? (api_url + "-with-response-stream") : api_url