Skip to content

Commit

Permalink
DEV: Use full URL for problem check message (#1165)
Browse files Browse the repository at this point in the history
Better to construct the URL in Ruby and pass it to I18n, so we don't have to mess with the translations if the URL changes.
  • Loading branch information
Drenmi authored Mar 5, 2025
1 parent fff0bc0 commit 584f5f2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
21 changes: 9 additions & 12 deletions app/services/problem_check/ai_llm_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ def call
llm_errors
end

def base_path
Discourse.base_path
end

private

def llm_errors
Expand All @@ -26,20 +22,21 @@ def try_validate(model, &blk)
blk.call
nil
rescue => e
error_message = parse_error_message(e.message)
message =
"#{I18n.t("dashboard.problem.ai_llm_status", { base_path: base_path, model_name: model.display_name, model_id: model.id })}"
details = {
model_id: model.id,
model_name: model.display_name,
error: parse_error_message(e.message),
url: "#{Discourse.base_path}/admin/plugins/discourse-ai/ai-llms/#{model.id}/edit",
}

message = I18n.t("dashboard.problem.ai_llm_status", details)

Problem.new(
message,
priority: "high",
identifier: "ai_llm_status",
target: model.id,
details: {
model_id: model.id,
model_name: model.display_name,
error: error_message,
},
details:,
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,4 @@ en:
prompt_message_length: The message %{idx} is over the 1000 character limit.
dashboard:
problem:
ai_llm_status: "The LLM model: %{model_name} is encountering issues. Please check the <a href='%{base_path}/admin/plugins/discourse-ai/ai-llms/%{model_id}/edit'>model's configuration page</a>."
ai_llm_status: "The LLM model: %{model_name} is encountering issues. Please check the <a href='%{url}'>model's configuration page</a>."
9 changes: 8 additions & 1 deletion spec/services/problem_check/ai_llm_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@
it "returns a problem with an LLM model" do
stub_request(:post, post_url).to_return(status: 403, body: error_response, headers: {})
message =
"#{I18n.t("dashboard.problem.ai_llm_status", { base_path: Discourse.base_path, model_name: llm_model.display_name, model_id: llm_model.id })}"
I18n.t(
"dashboard.problem.ai_llm_status",
{
model_name: llm_model.display_name,
url: "/admin/plugins/discourse-ai/ai-llms/#{llm_model.id}/edit",
},
)

expect(described_class.new.call).to contain_exactly(
have_attributes(
Expand All @@ -53,6 +59,7 @@
details: {
model_id: llm_model.id,
model_name: llm_model.display_name,
url: "/admin/plugins/discourse-ai/ai-llms/#{llm_model.id}/edit",
error: JSON.parse(error_response)["message"],
},
),
Expand Down

0 comments on commit 584f5f2

Please sign in to comment.