From f366ded03b69347710abbc09434015e53a1dee80 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Fri, 11 Jul 2025 08:19:30 -0700 Subject: [PATCH] DEV: Force default to be set if it was found not to be set! --- lib/ai_helper/assistant.rb | 7 +++++++ lib/embeddings/semantic_search.rb | 14 ++++++++++++-- lib/summarization.rb | 7 +++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/ai_helper/assistant.rb b/lib/ai_helper/assistant.rb index 8081e9cd..550a3362 100644 --- a/lib/ai_helper/assistant.rb +++ b/lib/ai_helper/assistant.rb @@ -320,6 +320,13 @@ module DiscourseAi if model_id.present? LlmModel.find_by(id: model_id) else + last_model_id = LlmModel.last&.id + + # SiteSetting.ai_default_llm_model shouldn't be empty, but if it is, we set it to the last model. + if last_model_id.present? && SiteSetting.ai_default_llm_model.empty? + SiteSetting.set_and_log("ai_default_llm_model", "custom:#{last_model_id}", Discourse.system_user) # Remove legacy custom provider. + end + LlmModel.last end end diff --git a/lib/embeddings/semantic_search.rb b/lib/embeddings/semantic_search.rb index 3ed27920..a1c0b01e 100644 --- a/lib/embeddings/semantic_search.rb +++ b/lib/embeddings/semantic_search.rb @@ -215,9 +215,19 @@ module DiscourseAi model_id = persona_klass.default_llm_id || SiteSetting.ai_default_llm_model&.split(":")&.last # Remove legacy custom provider. - return if model_id.blank? + if model_id.present? + LlmModel.find_by(id: model_id) + else + last_model_id = LlmModel.last&.id + + # SiteSetting.ai_default_llm_model shouldn't be empty, but if it is, we set it to the last model. + if last_model_id.present? && SiteSetting.ai_default_llm_model.empty? + SiteSetting.set_and_log("ai_default_llm_model", "custom:#{last_model_id}", Discourse.system_user) # Remove legacy custom provider. + end + + LlmModel.last + end - LlmModel.find_by(id: model_id) end private diff --git a/lib/summarization.rb b/lib/summarization.rb index f530b89b..e4706cbd 100644 --- a/lib/summarization.rb +++ b/lib/summarization.rb @@ -62,6 +62,13 @@ module DiscourseAi if model_id.present? LlmModel.find_by(id: model_id) else + last_model_id = LlmModel.last&.id + + # SiteSetting.ai_default_llm_model shouldn't be empty, but if it is, we set it to the last model. + if last_model_id.present? && SiteSetting.ai_default_llm_model.empty? + SiteSetting.set_and_log("ai_default_llm_model", "custom:#{last_model_id}", Discourse.system_user) # Remove legacy custom provider. + end + LlmModel.last end end