Skip to content

Commit ed3d552

Browse files
authored
UX: QoL impromevements to the admin LLM models page. (#674)
API Key value is secret by default, and we include a link to the AI bot user.
1 parent c4d9fab commit ed3d552

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

app/serializers/llm_model_serializer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class LlmModelSerializer < ApplicationSerializer
1414
:enabled_chat_bot,
1515
:url_editable
1616

17+
has_one :user, serializer: BasicUserSerializer, embed: :object
18+
1719
def url_editable
1820
object.url != LlmModel::RESERVED_VLLM_SRV_URL
1921
end

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

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ import { tracked } from "@glimmer/tracking";
33
import { Input } from "@ember/component";
44
import { on } from "@ember/modifier";
55
import { action } from "@ember/object";
6+
import { LinkTo } from "@ember/routing";
67
import { later } from "@ember/runloop";
78
import { inject as service } from "@ember/service";
89
import BackButton from "discourse/components/back-button";
910
import DButton from "discourse/components/d-button";
1011
import DToggleSwitch from "discourse/components/d-toggle-switch";
12+
import Avatar from "discourse/helpers/bound-avatar-template";
1113
import { popupAjaxError } from "discourse/lib/ajax-error";
1214
import icon from "discourse-common/helpers/d-icon";
1315
import i18n from "discourse-common/helpers/i18n";
1416
import I18n from "discourse-i18n";
17+
import AdminUser from "admin/models/admin-user";
1518
import ComboBox from "select-kit/components/combo-box";
1619
import DTooltip from "float-kit/components/d-tooltip";
1720

@@ -25,6 +28,7 @@ export default class AiLlmEditor extends Component {
2528
@tracked testRunning = false;
2629
@tracked testResult = null;
2730
@tracked testError = null;
31+
@tracked apiKeySecret = true;
2832

2933
get selectedProviders() {
3034
const t = (provName) => {
@@ -36,6 +40,10 @@ export default class AiLlmEditor extends Component {
3640
});
3741
}
3842

43+
get adminUser() {
44+
return AdminUser.create(this.args.model?.user);
45+
}
46+
3947
@action
4048
async save() {
4149
this.isSaving = true;
@@ -94,6 +102,16 @@ export default class AiLlmEditor extends Component {
94102
return this.testRunning || this.testResult !== null;
95103
}
96104

105+
@action
106+
makeApiKeySecret() {
107+
this.apiKeySecret = true;
108+
}
109+
110+
@action
111+
toggleApiKeySecret() {
112+
this.apiKeySecret = !this.apiKeySecret;
113+
}
114+
97115
@action
98116
delete() {
99117
return this.dialog.confirm({
@@ -177,11 +195,19 @@ export default class AiLlmEditor extends Component {
177195
{{/if}}
178196
<div class="control-group">
179197
<label>{{I18n.t "discourse_ai.llms.api_key"}}</label>
180-
<Input
181-
class="ai-llm-editor-input ai-llm-editor__api-key"
182-
@type="text"
183-
@value={{@model.api_key}}
184-
/>
198+
<div class="ai-llm-editor__secret-api-key-group">
199+
<Input
200+
@value={{@model.api_key}}
201+
class="ai-llm-editor-input ai-llm-editor__api-key"
202+
@type={{if this.apiKeySecret "password" "text"}}
203+
{{on "focusout" this.makeApiKeySecret}}
204+
/>
205+
<DButton
206+
@action={{this.toggleApiKeySecret}}
207+
@icon="far-eye-slash"
208+
{{on "focusout" this.makeApiKeySecret}}
209+
/>
210+
</div>
185211
</div>
186212
<div class="control-group">
187213
<label>{{I18n.t "discourse_ai.llms.tokenizer"}}</label>
@@ -213,6 +239,21 @@ export default class AiLlmEditor extends Component {
213239
{{on "click" this.toggleEnabledChatBot}}
214240
/>
215241
</div>
242+
{{#if @model.user}}
243+
<div class="control-group">
244+
<label>{{i18n "discourse_ai.llms.ai_bot_user"}}</label>
245+
<a
246+
class="avatar"
247+
href={{@model.user.path}}
248+
data-user-card={{@model.user.username}}
249+
>
250+
{{Avatar @model.user.avatar_template "small"}}
251+
</a>
252+
<LinkTo @route="adminUser" @model={{this.adminUser}}>
253+
{{@model.user.username}}
254+
</LinkTo>
255+
</div>
256+
{{/if}}
216257
<div class="control-group ai-llm-editor__action_panel">
217258
<DButton
218259
class="ai-llm-editor__test"

assets/stylesheets/modules/llms/common/ai-llms-editor.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,13 @@
3232
color: var(--success);
3333
}
3434
}
35+
36+
&__api-key {
37+
margin-right: 0.5em;
38+
}
39+
40+
&__secret-api-key-group {
41+
display: flex;
42+
align-items: center;
43+
}
3544
}

config/locales/client.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ en:
211211
url: "URL of the service hosting the model"
212212
api_key: "API Key of the service hosting the model"
213213
enabled_chat_bot: "Allow AI Bot"
214+
ai_bot_user: "AI Bot User"
214215
save: "Save"
215216
edit: "Edit"
216217
saved: "LLM Model Saved"

0 commit comments

Comments
 (0)