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