11# frozen_string_literal: true
22
33class AiPersona < ActiveRecord ::Base
4- # TODO remove this line 01-1 -2025
5- self . ignored_columns = %i[ commands allow_chat mentionable ]
4+ # TODO remove this line 01-10 -2025
5+ self . ignored_columns = %i[ default_llm question_consolidator_llm ]
66
77 # places a hard limit, so per site we cache a maximum of 500 classes
88 MAX_PERSONAS_PER_SITE = 500
@@ -12,7 +12,7 @@ class AiPersona < ActiveRecord::Base
1212 validates :system_prompt , presence : true , length : { maximum : 10_000_000 }
1313 validate :system_persona_unchangeable , on : :update , if : :system
1414 validate :chat_preconditions
15- validate :allowed_seeded_model , if : :default_llm
15+ validate :allowed_seeded_model , if : :default_llm_id
1616 validates :max_context_posts , numericality : { greater_than : 0 } , allow_nil : true
1717 # leaves some room for growth but sets a maximum to avoid memory issues
1818 # we may want to revisit this in the future
@@ -27,6 +27,9 @@ class AiPersona < ActiveRecord::Base
2727 belongs_to :created_by , class_name : "User"
2828 belongs_to :user
2929
30+ belongs_to :default_llm , class_name : "LlmModel"
31+ belongs_to :question_consolidator_llm , class_name : "LlmModel"
32+
3033 has_many :upload_references , as : :target , dependent : :destroy
3134 has_many :uploads , through : :upload_references
3235
@@ -59,7 +62,7 @@ def self.persona_users(user: nil)
5962 user_id : persona . user_id ,
6063 username : persona . user . username_lower ,
6164 allowed_group_ids : persona . allowed_group_ids ,
62- default_llm : persona . default_llm ,
65+ default_llm_id : persona . default_llm_id ,
6366 force_default_llm : persona . force_default_llm ,
6467 allow_chat_channel_mentions : persona . allow_chat_channel_mentions ,
6568 allow_chat_direct_messages : persona . allow_chat_direct_messages ,
@@ -113,7 +116,7 @@ def class_instance
113116 user_id
114117 system
115118 mentionable
116- default_llm
119+ default_llm_id
117120 max_context_posts
118121 vision_enabled
119122 vision_max_pixels
@@ -258,7 +261,7 @@ def chat_preconditions
258261 if (
259262 allow_chat_channel_mentions || allow_chat_direct_messages || allow_topic_mentions ||
260263 force_default_llm
261- ) && !default_llm
264+ ) && !default_llm_id
262265 errors . add ( :default_llm , I18n . t ( "discourse_ai.ai_bot.personas.default_llm_required" ) )
263266 end
264267 end
@@ -288,13 +291,12 @@ def ensure_not_system
288291 end
289292
290293 def allowed_seeded_model
291- return if default_llm . blank?
294+ return if default_llm_id . blank?
292295
293- llm = LlmModel . find_by ( id : default_llm . split ( ":" ) . last . to_i )
294- return if llm . nil?
295- return if !llm . seeded?
296+ return if default_llm . nil?
297+ return if !default_llm . seeded?
296298
297- return if SiteSetting . ai_bot_allowed_seeded_models . include? ( llm . id . to_s )
299+ return if SiteSetting . ai_bot_allowed_seeded_models_map . include? ( default_llm . id . to_s )
298300
299301 errors . add ( :default_llm , I18n . t ( "discourse_ai.llm.configuration.invalid_seeded_model" ) )
300302 end
@@ -304,37 +306,39 @@ def allowed_seeded_model
304306#
305307# Table name: ai_personas
306308#
307- # id :bigint not null, primary key
308- # name :string(100) not null
309- # description :string(2000) not null
310- # system_prompt :string(10000000) not null
311- # allowed_group_ids :integer default([]), not null, is an Array
312- # created_by_id :integer
313- # enabled :boolean default(TRUE), not null
314- # created_at :datetime not null
315- # updated_at :datetime not null
316- # system :boolean default(FALSE), not null
317- # priority :boolean default(FALSE), not null
318- # temperature :float
319- # top_p :float
320- # user_id :integer
321- # default_llm :text
322- # max_context_posts :integer
323- # vision_enabled :boolean default(FALSE), not null
324- # vision_max_pixels :integer default(1048576), not null
325- # rag_chunk_tokens :integer default(374), not null
326- # rag_chunk_overlap_tokens :integer default(10), not null
327- # rag_conversation_chunks :integer default(10), not null
328- # question_consolidator_llm :text
329- # tool_details :boolean default(TRUE), not null
330- # tools :json not null
331- # forced_tool_count :integer default(-1), not null
332- # allow_chat_channel_mentions :boolean default(FALSE), not null
333- # allow_chat_direct_messages :boolean default(FALSE), not null
334- # allow_topic_mentions :boolean default(FALSE), not null
335- # allow_personal_messages :boolean default(TRUE), not null
336- # force_default_llm :boolean default(FALSE), not null
337- # rag_llm_model_id :bigint
309+ # id :bigint not null, primary key
310+ # name :string(100) not null
311+ # description :string(2000) not null
312+ # system_prompt :string(10000000) not null
313+ # allowed_group_ids :integer default([]), not null, is an Array
314+ # created_by_id :integer
315+ # enabled :boolean default(TRUE), not null
316+ # created_at :datetime not null
317+ # updated_at :datetime not null
318+ # system :boolean default(FALSE), not null
319+ # priority :boolean default(FALSE), not null
320+ # temperature :float
321+ # top_p :float
322+ # user_id :integer
323+ # max_context_posts :integer
324+ # max_post_context_tokens :integer
325+ # max_context_tokens :integer
326+ # vision_enabled :boolean default(FALSE), not null
327+ # vision_max_pixels :integer default(1048576), not null
328+ # rag_chunk_tokens :integer default(374), not null
329+ # rag_chunk_overlap_tokens :integer default(10), not null
330+ # rag_conversation_chunks :integer default(10), not null
331+ # tool_details :boolean default(TRUE), not null
332+ # tools :json not null
333+ # forced_tool_count :integer default(-1), not null
334+ # allow_chat_channel_mentions :boolean default(FALSE), not null
335+ # allow_chat_direct_messages :boolean default(FALSE), not null
336+ # allow_topic_mentions :boolean default(FALSE), not null
337+ # allow_personal_messages :boolean default(TRUE), not null
338+ # force_default_llm :boolean default(FALSE), not null
339+ # rag_llm_model_id :bigint
340+ # default_llm_id :bigint
341+ # question_consolidator_llm_id :bigint
338342#
339343# Indexes
340344#
0 commit comments