Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit ed311de

Browse files
SamSaffrontgxworld
andauthored
FIX: various bugs in AI interface (#1430)
* FIX: improve transition logic in forms previously back button would take you back to the /new route * FIX: enum selection not working for persona tools * seed information correctly in the DB * fix broken spec * Update assets/javascripts/discourse/components/ai-tool-editor-form.gjs Co-authored-by: Alan Guo Xiang Tan <[email protected]> --------- Co-authored-by: Alan Guo Xiang Tan <[email protected]>
1 parent 8c8fd96 commit ed311de

File tree

7 files changed

+65
-29
lines changed

7 files changed

+65
-29
lines changed

assets/javascripts/discourse/components/ai-llm-editor-form.gjs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,15 @@ export default class AiLlmEditorForm extends Component {
202202

203203
if (isNew) {
204204
this.args.llms.addObject(this.args.model);
205-
this.router.transitionTo("adminPlugins.show.discourse-ai-llms.index");
206-
} else {
207-
this.toasts.success({
208-
data: { message: i18n("discourse_ai.llms.saved") },
209-
duration: 2000,
210-
});
205+
await this.router.replaceWith(
206+
"adminPlugins.show.discourse-ai-llms.edit",
207+
this.args.model.id
208+
);
211209
}
210+
this.toasts.success({
211+
data: { message: i18n("discourse_ai.llms.saved") },
212+
duration: 2000,
213+
});
212214
} catch (e) {
213215
popupAjaxError(e);
214216
} finally {
@@ -340,7 +342,7 @@ export default class AiLlmEditorForm extends Component {
340342
@format="large"
341343
as |field|
342344
>
343-
<field.Password />
345+
<field.Password autocomplete="off" data-1p-ignore />
344346
</form.Field>
345347

346348
<form.Object @name="provider_params" as |object providerParamsData|>

assets/javascripts/discourse/components/ai-persona-editor.gjs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,15 @@ export default class PersonaEditor extends Component {
122122

123123
if (isNew && this.args.model.rag_uploads.length === 0) {
124124
this.args.personas.addObject(personaToSave);
125-
this.router.transitionTo(
125+
await this.router.replaceWith(
126126
"adminPlugins.show.discourse-ai-personas.edit",
127127
personaToSave
128128
);
129-
} else {
130-
this.toasts.success({
131-
data: { message: i18n("discourse_ai.ai_persona.saved") },
132-
duration: 2000,
133-
});
134129
}
130+
this.toasts.success({
131+
data: { message: i18n("discourse_ai.ai_persona.saved") },
132+
duration: 2000,
133+
});
135134
} catch (e) {
136135
popupAjaxError(e);
137136
} finally {

assets/javascripts/discourse/components/ai-persona-tool-options.gjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ export default class AiPersonaToolOptions extends Component {
1616
}
1717

1818
get toolsMetadata() {
19-
const metatada = {};
19+
const metadata = {};
2020

2121
this.args.allTools.map((t) => {
22-
metatada[t.id] = {
22+
metadata[t.id] = {
2323
name: t.name,
2424
...t?.options,
2525
};
2626
});
2727

28-
return metatada;
28+
return metadata;
2929
}
3030

3131
@action
@@ -76,7 +76,7 @@ export default class AiPersonaToolOptions extends Component {
7676
>
7777
{{#if (eq optionMeta.type "enum")}}
7878
<field.Select @includeNone={{false}} as |select|>
79-
{{#each optionsObj.values as |v|}}
79+
{{#each optionMeta.values as |v|}}
8080
<select.Option @value={{v}}>{{v}}</select.Option>
8181
{{/each}}
8282
</field.Select>

assets/javascripts/discourse/components/ai-tool-editor-form.gjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default class AiToolEditorForm extends Component {
9191
this.args.tools.pushObject(this.args.model);
9292
}
9393

94-
this.router.transitionTo(
94+
await this.router.replaceWith(
9595
"adminPlugins.show.discourse-ai-tools.edit",
9696
this.args.model
9797
);

db/fixtures/personas/603_ai_personas.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,8 @@ def from_setting(setting_name)
7979

8080
persona.tools = tools.map { |name, value| [name, value] }
8181

82-
# Only set response_format if it's not defined as a method in the persona class
83-
if !instance.class.instance_methods.include?(:response_format)
84-
persona.response_format = instance.response_format
85-
end
86-
87-
# Only set examples if it's not defined as a method in the persona class
88-
persona.examples = instance.examples if !instance.class.instance_methods.include?(:examples)
82+
persona.response_format = instance.response_format
83+
persona.examples = instance.examples
8984

9085
persona.system_prompt = instance.system_prompt
9186
persona.top_p = instance.top_p

spec/system/ai_bot/persona_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@
1010
sign_in(admin)
1111
end
1212

13+
it "can select and save persona tool options" do
14+
visit "/admin/plugins/discourse-ai/ai-personas"
15+
find(".ai-persona-list-editor__new-button").click
16+
17+
expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-personas/new")
18+
19+
form = PageObjects::Components::FormKit.new("form")
20+
form.field("name").fill_in("Test Persona")
21+
form.field("description").fill_in("This is a test persona.")
22+
form.field("system_prompt").fill_in("You are a helpful assistant.")
23+
form.field("tools").select("Update Artifact")
24+
form.field("toolOptions.UpdateArtifact.update_algorithm").select("full")
25+
form.submit
26+
27+
expect(page).to have_current_path(%r{/admin/plugins/discourse-ai/ai-personas/\d+/edit})
28+
29+
persona = AiPersona.order("id desc").first
30+
31+
expect(persona.name).to eq("Test Persona")
32+
expect(persona.description).to eq("This is a test persona.")
33+
expect(persona.tools.count).to eq(1)
34+
expect(persona.tools.first[0]).to eq("UpdateArtifact")
35+
expect(persona.tools.first[1]["update_algorithm"]).to eq("full")
36+
end
37+
1338
it "remembers the last selected persona" do
1439
visit "/"
1540
find(".d-header .ai-bot-button").click()

spec/system/llms/ai_llm_spec.rb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
form.field("enabled_chat_bot").toggle
2020
form.submit
2121

22-
expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-llms")
22+
expect(page).to have_current_path(%r{/admin/plugins/discourse-ai/ai-llms/\d+/edit})
2323

2424
llm = LlmModel.order(:id).last
2525

@@ -38,6 +38,8 @@
3838
end
3939

4040
it "manually configures an LLM" do
41+
llm_count = LlmModel.count
42+
4143
visit "/admin/plugins/discourse-ai/ai-llms"
4244

4345
expect(page_header).to be_visible
@@ -58,19 +60,32 @@
5860
form.field("enabled_chat_bot").toggle
5961
form.submit
6062

61-
expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-llms")
62-
63+
expect(page).to have_current_path(%r{/admin/plugins/discourse-ai/ai-llms/\d+/edit})
6364
llm = LlmModel.order(:id).last
65+
expect(llm.max_output_tokens.to_i).to eq(2000)
66+
67+
expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-llms/#{llm.id}/edit")
68+
69+
form.field("max_output_tokens").fill_in(2001)
70+
form.submit
71+
72+
# should go to llm list and see the llms correctly configured
73+
page.go_back
74+
75+
expect(page).to have_selector(".ai-llms-list-editor__configured .ai-llm-list__row", count: 1)
6476

77+
llm.reload
6578
expect(llm.display_name).to eq("Self-hosted LLM")
6679
expect(llm.name).to eq("llava-hf/llava-v1.6-mistral-7b-hf")
6780
expect(llm.url).to eq("srv://self-hostest.test")
6881
expect(llm.tokenizer).to eq("DiscourseAi::Tokenizer::Llama3Tokenizer")
6982
expect(llm.max_prompt_tokens.to_i).to eq(8000)
7083
expect(llm.provider).to eq("vllm")
71-
expect(llm.max_output_tokens.to_i).to eq(2000)
84+
expect(llm.max_output_tokens.to_i).to eq(2001)
7285
expect(llm.vision_enabled).to eq(true)
7386
expect(llm.user_id).not_to be_nil
87+
88+
expect(LlmModel.count).to eq(llm_count + 1)
7489
end
7590

7691
context "when changing the provider" do

0 commit comments

Comments
 (0)