This repository was archived by the owner on Jul 22, 2025. It is now read-only.
generated from discourse/discourse-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 41
FEATURE: configure a default LLM model for all features #1496
Closed
Closed
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
2592be6
FEATURE: configure a default LLM model for all features
keegangeorge cad39c1
DEV: client side
keegangeorge 5a590fd
DEV: updates...
keegangeorge 29d4157
fix
keegangeorge 5a29074
DEV: Use default LLM model
keegangeorge 249aab1
DEV: Use a simple validator
keegangeorge b46940f
DEV: hide reset button
keegangeorge c49f1df
DEV: migrate hyde model to content creator persona
keegangeorge 87c4214
DEV: hide hyde model setting
keegangeorge f366ded
DEV: Force default to be set if it was found not to be set!
keegangeorge b6a88ff
spec
keegangeorge 8da4318
DEV: `assign_fake_provider`
keegangeorge 2377b28
DEV: rely on default llm model in spec
keegangeorge 88811f9
fixes
keegangeorge b58f198
FIX: don't `run_test` in testing env
keegangeorge f593ab6
DEV: remove `custom:` prefix
keegangeorge 7ae61ce
DEV: update automation to remove `custom:` prefix
keegangeorge c26d604
FIX: dependency validator should depend on default LLM setting
keegangeorge 0fadf1d
DEV: update enumerator
keegangeorge b675c4c
DEV: Remove custom prefix in specs
keegangeorge 5ae8064
Merge branch 'main' into default-llm-model
keegangeorge 5841543
FIX: validator
keegangeorge 7af3ce8
DEV: Remove references to translation model
keegangeorge 273a1fa
FIX: occurrences of old model setting
keegangeorge 08d2f3d
FIX: spam
keegangeorge f077d58
FIX: automation spec
keegangeorge a927fd2
fix
keegangeorge d9b53b4
FIX: semantic search
keegangeorge 4b03cdc
FIX: LLM controller spec
keegangeorge cc34882
FIX: rest of specs
keegangeorge eb93e17
Final spec fix π€
keegangeorge f420261
DEV: Apply feedback from review
keegangeorge fbbe01e
DEV: Hide seeded LLMs in the enumerator for now
keegangeorge 7dee59c
DEV: Remove no longer needed seeded model check
keegangeorge 822594f
Update db/migrate/20250716005855_copy_ai_image_caption_model_to_persoβ¦
romanrizzi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,7 @@ def to_llm | |
| end | ||
|
|
||
| def identifier | ||
| "custom:#{id}" | ||
| "#{id}" | ||
| end | ||
|
|
||
| def toggle_companion_user | ||
|
|
||
46 changes: 46 additions & 0 deletions
46
assets/javascripts/discourse/components/ai-default-llm-selector.gjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import Component from "@glimmer/component"; | ||
| import { tracked } from "@glimmer/tracking"; | ||
| import { ajax } from "discourse/lib/ajax"; | ||
| import { i18n } from "discourse-i18n"; | ||
| import SiteSettingComponent from "admin/components/site-setting"; | ||
| import SiteSetting from "admin/models/site-setting"; | ||
|
|
||
| export default class AiDefaultLlmSelector extends Component { | ||
| @tracked defaultLlmSetting = null; | ||
|
|
||
| constructor() { | ||
| super(...arguments); | ||
| this.#loadDefaultLlmSetting(); | ||
| } | ||
|
|
||
| async #loadDefaultLlmSetting() { | ||
| const { site_settings } = await ajax("/admin/config/site_settings.json", { | ||
| data: { | ||
| plugin: "discourse-ai", | ||
| category: "discourse_ai", | ||
| }, | ||
| }); | ||
|
|
||
| const defaultLlmSetting = site_settings.find( | ||
| (setting) => setting.setting === "ai_default_llm_model" | ||
| ); | ||
|
|
||
| this.defaultLlmSetting = SiteSetting.create(defaultLlmSetting); | ||
| } | ||
|
|
||
| <template> | ||
| <div class="ai-configure-default-llm"> | ||
| <div class="ai-configure-default-llm__header"> | ||
| <h3>{{i18n "discourse_ai.default_llm.title"}}</h3> | ||
| <p>{{i18n "discourse_ai.default_llm.description"}}</p> | ||
| </div> | ||
|
|
||
| {{#if this.defaultLlmSetting}} | ||
| <SiteSettingComponent | ||
| @setting={{this.defaultLlmSetting}} | ||
| class="ai-configure-default-llm__setting" | ||
| /> | ||
| {{/if}} | ||
| </div> | ||
| </template> | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 = '#{last_model_id}' WHERE name = 'ai_default_llm_model' AND (value IS NULL OR value = '');" | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| raise ActiveRecord::IrreversibleMigration | ||
| end | ||
| end |
23 changes: 23 additions & 0 deletions
23
db/migrate/20250710180401_copy_ai_summarization_model_to_persona_default.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
keegangeorge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| SQL | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| raise ActiveRecord::IrreversibleMigration | ||
| end | ||
| end | ||
23 changes: 23 additions & 0 deletions
23
db/migrate/20250710181656_copy_ai_helper_model_to_persona_default.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) AND default_llm_id IS NULL | ||
keegangeorge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| SQL | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| raise ActiveRecord::IrreversibleMigration | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # frozen_string_literal: true | ||
| class CopyHydeModelToPersona < ActiveRecord::Migration[7.2] | ||
| def up | ||
| hyde_model = | ||
| DB.query_single("SELECT value FROM site_settings WHERE name = 'ai_embeddings_semantic_search_hyde_model'").first | ||
|
|
||
| if hyde_model.present? && hyde_model.start_with?("custom:") | ||
| # Extract the model ID from the setting value (e.g., "custom:1" -> "1") | ||
| model_id = hyde_model.split(":").last | ||
|
|
||
| # Update the hyde persona with the extracted model ID | ||
| execute(<<~SQL) | ||
| UPDATE ai_personas | ||
| SET default_llm_id = #{model_id} | ||
| WHERE id IN (-32) AND default_llm_id IS NULL | ||
keegangeorge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| SQL | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| raise ActiveRecord::IrreversibleMigration | ||
| end | ||
| end | ||
23 changes: 23 additions & 0 deletions
23
db/migrate/20250716005451_copy_translation_model_to_persona.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # frozen_string_literal: true | ||
| class CopyTranslationModelToPersona < ActiveRecord::Migration[7.2] | ||
| def up | ||
| ai_translation_model = | ||
| DB.query_single("SELECT value FROM site_settings WHERE name = 'ai_translation_model'").first | ||
|
|
||
| if ai_translation_model.present? && ai_translation_model.start_with?("custom:") | ||
| # Extract the model ID from the setting value (e.g., "custom:-5" -> "-5") | ||
| model_id = ai_translation_model.split(":").last | ||
|
|
||
| # Update the translation personas (IDs -27, -28, -29, -30) with the extracted model ID | ||
| execute(<<~SQL) | ||
| UPDATE ai_personas | ||
| SET default_llm_id = #{model_id} | ||
| WHERE id IN (-27, -28, -29, -30) AND default_llm_id IS NULL | ||
keegangeorge marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| SQL | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| raise ActiveRecord::IrreversibleMigration | ||
| end | ||
| end | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.