This repository was archived by the owner on Jul 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +46
-7
lines changed
controllers/discourse_ai/admin Expand file tree Collapse file tree 4 files changed +46
-7
lines changed Original file line number Diff line number Diff line change @@ -27,9 +27,9 @@ def index
2727 }
2828 end
2929 llms =
30- DiscourseAi ::Configuration ::LlmEnumerator . values . map do | hash |
31- { id : hash [ :value ] , name : hash [ :name ] }
32- end
30+ DiscourseAi ::Configuration ::LlmEnumerator
31+ . values ( allowed_seeded_llms : SiteSetting . ai_bot_allowed_seeded_models )
32+ . map { | hash | { id : hash [ :value ] , name : hash [ :name ] } }
3333 render json : { ai_personas : ai_personas , meta : { tools : tools , llms : llms } }
3434 end
3535
Original file line number Diff line number Diff line change @@ -12,6 +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
1516 validates :max_context_posts , numericality : { greater_than : 0 } , allow_nil : true
1617 # leaves some room for growth but sets a maximum to avoid memory issues
1718 # we may want to revisit this in the future
@@ -275,6 +276,17 @@ def ensure_not_system
275276 throw :abort
276277 end
277278 end
279+
280+ def allowed_seeded_model
281+ return if default_llm . blank?
282+
283+ llm = LlmModel . find_by ( id : default_llm . split ( ":" ) . last . to_i )
284+ return if !llm . seeded?
285+
286+ return if SiteSetting . ai_bot_allowed_seeded_models . include? ( llm . id . to_s )
287+
288+ errors . add ( :default_llm , I18n . t ( "discourse_ai.llm.configuration.invalid_seeded_model" ) )
289+ end
278290end
279291
280292# == Schema Information
Original file line number Diff line number Diff line change @@ -26,9 +26,8 @@ discourse_ai:
2626 default : 60
2727 hidden : true
2828
29-
3029 ai_openai_dall_e_3_url : " https://api.openai.com/v1/images/generations"
31- ai_openai_embeddings_url :
30+ ai_openai_embeddings_url :
3231 hidden : true
3332 default : " https://api.openai.com/v1/embeddings"
3433 ai_openai_organization :
@@ -57,7 +56,7 @@ discourse_ai:
5756 ai_hugging_face_tei_endpoint_srv :
5857 default : " "
5958 hidden : true
60- ai_hugging_face_tei_api_key :
59+ ai_hugging_face_tei_api_key :
6160 default : " "
6261 hidden : true
6362 ai_hugging_face_tei_reranker_endpoint :
@@ -203,7 +202,7 @@ discourse_ai:
203202 client : true
204203 hidden : true
205204
206- ai_embeddings_discourse_service_api_endpoint :
205+ ai_embeddings_discourse_service_api_endpoint :
207206 default : " "
208207 hidden : true
209208 ai_embeddings_discourse_service_api_endpoint_srv :
@@ -307,6 +306,11 @@ discourse_ai:
307306 ai_bot_github_access_token :
308307 default : " "
309308 secret : true
309+ ai_bot_allowed_seeded_models :
310+ default : " "
311+ hidden : true
312+ type : list
313+ list_type : compact
310314 ai_automation_max_triage_per_minute :
311315 default : 60
312316 hidden : true
Original file line number Diff line number Diff line change 172172 )
173173 end
174174
175+ it "validates allowed seeded model" do
176+ persona =
177+ AiPersona . new (
178+ name : "test" ,
179+ description : "test" ,
180+ system_prompt : "test" ,
181+ tools : [ ] ,
182+ allowed_group_ids : [ ] ,
183+ default_llm : "seeded_model:-1" ,
184+ )
185+
186+ llm_model = Fabricate ( :llm_model , id : -1 )
187+ SiteSetting . ai_bot_allowed_seeded_models = ""
188+
189+ expect ( persona . valid? ) . to eq ( false )
190+ expect ( persona . errors [ :default_llm ] ) . to include (
191+ I18n . t ( "discourse_ai.llm.configuration.invalid_seeded_model" ) ,
192+ )
193+
194+ SiteSetting . ai_bot_allowed_seeded_models = "-1"
195+ expect ( persona . valid? ) . to eq ( true )
196+ end
197+
175198 it "does not leak caches between sites" do
176199 AiPersona . create! (
177200 name : "pun_bot" ,
You can’t perform that action at this time.
0 commit comments