DEV: Use default LLM model
This commit is contained in:
@@ -183,7 +183,7 @@ en:
|
||||
|
||||
default_llm:
|
||||
title: "Default LLM model"
|
||||
description: "The default LLM model to use for all AI features. This will be used if no LLM is specified in the feature configuration or persona."
|
||||
description: "The default LLM model to use for all AI features. This will be used if no LLM is specified in the feature configuration or persona. If no default LLM is specified, the last created LLM will be used."
|
||||
|
||||
features:
|
||||
short_title: "Features"
|
||||
|
||||
+4
-4
@@ -109,7 +109,7 @@ discourse_ai:
|
||||
default: false
|
||||
client: true
|
||||
area: "ai-features/ai_helper"
|
||||
ai_helper_model:
|
||||
ai_helper_model: # Deprecated. TODO(keegan): Remove 2025-09-01
|
||||
default: ""
|
||||
allow_any: false
|
||||
type: enum
|
||||
@@ -155,7 +155,7 @@ discourse_ai:
|
||||
- "context_menu"
|
||||
- "image_caption"
|
||||
area: "ai-features/ai_helper"
|
||||
ai_helper_image_caption_model:
|
||||
ai_helper_image_caption_model: # Deprecated. TODO(keegan): Remove 2025-09-01
|
||||
default: ""
|
||||
type: enum
|
||||
enum: "DiscourseAi::Configuration::LlmVisionEnumerator"
|
||||
@@ -266,7 +266,7 @@ discourse_ai:
|
||||
client: true
|
||||
validator: "DiscourseAi::Configuration::LlmDependencyValidator"
|
||||
area: "ai-features/embeddings"
|
||||
ai_embeddings_semantic_search_hyde_model:
|
||||
ai_embeddings_semantic_search_hyde_model: # Deprecated. TODO(keegan): Remove 2025-09-01
|
||||
default: ""
|
||||
type: enum
|
||||
allow_any: false
|
||||
@@ -322,7 +322,7 @@ discourse_ai:
|
||||
client: true
|
||||
validator: "DiscourseAi::Configuration::LlmDependencyValidator"
|
||||
area: "ai-features/summarization"
|
||||
ai_summarization_model:
|
||||
ai_summarization_model: # Deprecated. TODO(keegan): Remove 2025-09-01
|
||||
default: ""
|
||||
allow_any: false
|
||||
type: enum
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
class SeedAiDefaultLlmModel < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
return if DB.query_single("SELECT 1 FROM llm_models LIMIT 1").empty?
|
||||
|
||||
last_model_id = DB.query_single("SELECT id FROM llm_models ORDER BY id DESC LIMIT 1").first
|
||||
|
||||
if last_model_id.present?
|
||||
execute "UPDATE site_settings SET value = 'custom:#{last_model_id}' WHERE name = 'ai_default_llm_model' AND (value IS NULL OR value = '');"
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
class CopyAiSummarizationModelToPersonaDefault < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
ai_summarization_model =
|
||||
DB.query_single("SELECT value FROM site_settings WHERE name = 'ai_summarization_model'").first
|
||||
|
||||
if ai_summarization_model.present? && ai_summarization_model.start_with?("custom:")
|
||||
# Extract the model ID from the setting value (e.g., "custom:-5" -> "-5")
|
||||
model_id = ai_summarization_model.split(":").last
|
||||
|
||||
# Update the summarization personas (IDs -11 and -12) with the extracted model ID
|
||||
execute(<<~SQL)
|
||||
UPDATE ai_personas
|
||||
SET default_llm_id = #{model_id}
|
||||
WHERE id IN (-11, -12) AND default_llm_id IS NULL
|
||||
SQL
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
class CopyAiHelperModelToPersonaDefault < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
ai_helper_model =
|
||||
DB.query_single("SELECT value FROM site_settings WHERE name = 'ai_helper_model'").first
|
||||
|
||||
if ai_helper_model.present? && ai_helper_model.start_with?("custom:")
|
||||
# Extract the model ID from the setting value (e.g., "custom:1" -> "1")
|
||||
model_id = ai_helper_model.split(":").last
|
||||
|
||||
# Update the helper personas with the extracted model ID
|
||||
execute(<<~SQL)
|
||||
UPDATE ai_personas
|
||||
SET default_llm_id = #{model_id}
|
||||
WHERE id IN (-18, -19, -20, -21, -22, -23, -24, -25, -26) AND default_llm_id IS NULL
|
||||
SQL
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -312,18 +312,10 @@ module DiscourseAi
|
||||
|
||||
# Priorities are:
|
||||
# 1. Persona's default LLM
|
||||
# 2. Hidden `ai_helper_model` setting, or `ai_helper_image_caption_model` for image_caption.
|
||||
# 3. Newest LLM config
|
||||
# 2. SiteSetting.ai_default_llm_id (or newest LLM if not set)
|
||||
def self.find_ai_helper_model(helper_mode, persona_klass)
|
||||
model_id = persona_klass.default_llm_id
|
||||
|
||||
if !model_id
|
||||
if helper_mode == IMAGE_CAPTION
|
||||
model_id = SiteSetting.ai_helper_image_caption_model&.split(":")&.last
|
||||
else
|
||||
model_id = SiteSetting.ai_helper_model&.split(":")&.last
|
||||
end
|
||||
end
|
||||
model_id =
|
||||
persona_klass.default_llm_id || SiteSetting.ai_default_llm_model&.split(":")&.last # Remove legacy custom provider.
|
||||
|
||||
if model_id.present?
|
||||
LlmModel.find_by(id: model_id)
|
||||
|
||||
@@ -210,11 +210,10 @@ module DiscourseAi
|
||||
|
||||
# Priorities are:
|
||||
# 1. Persona's default LLM
|
||||
# 2. `ai_embeddings_semantic_search_hyde_model` setting.
|
||||
# 2. SiteSetting.ai_default_llm_id (or newest LLM if not set)
|
||||
def find_ai_hyde_model(persona_klass)
|
||||
model_id =
|
||||
persona_klass.default_llm_id ||
|
||||
SiteSetting.ai_embeddings_semantic_search_hyde_model&.split(":")&.last
|
||||
persona_klass.default_llm_id || SiteSetting.ai_default_llm_model&.split(":")&.last # Remove legacy custom provider.
|
||||
|
||||
return if model_id.blank?
|
||||
|
||||
|
||||
@@ -54,11 +54,10 @@ module DiscourseAi
|
||||
|
||||
# Priorities are:
|
||||
# 1. Persona's default LLM
|
||||
# 2. Hidden `ai_summarization_model` setting
|
||||
# 3. Newest LLM config
|
||||
# 2. SiteSetting.ai_default_llm_id (or newest LLM if not set)
|
||||
def find_summarization_model(persona_klass)
|
||||
model_id =
|
||||
persona_klass.default_llm_id || SiteSetting.ai_summarization_model&.split(":")&.last # Remove legacy custom provider.
|
||||
persona_klass.default_llm_id || SiteSetting.ai_default_llm_model&.split(":")&.last # Remove legacy custom provider.
|
||||
|
||||
if model_id.present?
|
||||
LlmModel.find_by(id: model_id)
|
||||
|
||||
Reference in New Issue
Block a user