This repository was archived by the owner on Jul 22, 2025. It is now read-only.
generated from discourse/discourse-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 40
FEATURE: Add periodic problem checks for each LLM in use #1020
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fdc8c70
FEATURE: Add periodic problem checks for each LLM in use
keegangeorge 61d84b0
Merge branch 'main' into problem-check-llm
keegangeorge 8f10c3d
DEV: better
keegangeorge 8947a7d
DEV: Add spec
keegangeorge ec20ca5
DEV: Apply suggestions from review
keegangeorge 34f5b15
DEV: update copy
keegangeorge 90fa0eb
WIP: update spec
keegangeorge 33946df
FIX: spec 🙌
keegangeorge 18598a1
FIX: Locale issue
keegangeorge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class ProblemCheck::AiLlmStatus < ProblemCheck | ||
| self.priority = "high" | ||
| self.perform_every = 1.hour | ||
|
|
||
| def call | ||
| [*llm_errors] | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def targets | ||
| [*LlmModel.in_use.pluck(:id)] | ||
keegangeorge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| def llm_errors | ||
| return [] if !SiteSetting.discourse_ai_enabled | ||
|
|
||
| LlmModel.in_use.find_each.filter_map do |model| | ||
| try_validate(model) { validator.run_test(model) } | ||
| end | ||
| end | ||
|
|
||
| def try_validate(model, &blk) | ||
| begin | ||
| raise({ message: "Forced error for testing" }.to_json) if Rails.env.test? | ||
keegangeorge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| blk.call | ||
| nil | ||
| rescue => e | ||
| error_message = JSON.parse(e.message)["message"] | ||
keegangeorge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| message = | ||
| "#{I18n.t("dashboard.problem.ai_llm_status", { model_name: model.display_name, model_id: model.id })}" | ||
|
|
||
| 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, | ||
| }, | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| def validator | ||
| @validator ||= DiscourseAi::Configuration::LlmValidator.new | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "rails_helper" | ||
|
|
||
| RSpec.describe ProblemCheck::AiLlmStatus do | ||
| subject(:check) { described_class.new } | ||
|
|
||
| before do | ||
| assign_fake_provider_to(:ai_summarization_model) | ||
| SiteSetting.ai_summarization_enabled = true | ||
| end | ||
|
|
||
| describe "#call" do | ||
| it "does nothing if discourse-ai plugin disabled" do | ||
| SiteSetting.discourse_ai_enabled = false | ||
| expect(check).to be_chill_about_it | ||
| end | ||
|
|
||
| context "with discourse-ai plugin enabled for the site" do | ||
| let(:llm_model) { LlmModel.in_use.first } | ||
|
|
||
| before { SiteSetting.discourse_ai_enabled = true } | ||
|
|
||
| it "returns a problem with an LLM model" do | ||
| message = | ||
| "#{I18n.t("dashboard.problem.ai_llm_status", { model_name: llm_model.display_name, model_id: llm_model.id })}" | ||
|
|
||
| expect(described_class.new.call).to contain_exactly( | ||
| have_attributes( | ||
| identifier: "ai_llm_status", | ||
| target: llm_model.id, | ||
| priority: "high", | ||
| message: message, | ||
| details: { | ||
| model_id: llm_model.id, | ||
| model_name: llm_model.display_name, | ||
| error: "Forced error for testing", | ||
| }, | ||
| ), | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.