UX: Improvements to the AI Bot header shortcut (#66)

- Humanize model names
- Focus composer editor when starting a PM with a bot
- Correctly close the models dropdown when clicking outside
This commit is contained in:
Roman Rizzi 2023-05-17 15:59:48 -03:00 committed by GitHub
parent e9ae28f773
commit 9ae8f86850
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 16 deletions

View File

@ -17,12 +17,12 @@
{{did-insert this.registerClickListener}}
{{will-destroy this.unregisterClickListener}}
>
{{#each this.enabledBotOptions as |modelName|}}
{{#each this.botNames as |bot|}}
<DButton
@class="btn-flat ai-bot-available-bot-content"
@translatedTitle={{modelName}}
@translatedLabel={{modelName}}
@action={{action "composeMessageWithTargetBot" modelName}}
@translatedTitle={{bot.humanized}}
@translatedLabel={{bot.humanized}}
@action={{action "composeMessageWithTargetBot" bot.modelName}}
/>
{{/each}}
</div>

View File

@ -43,7 +43,7 @@ export default class AiBotHeaderIcon extends Component {
@bind
closeDetails(event) {
if (this.open) {
const isLinkClick = event.target.className.includes(
const isLinkClick = Array.from(event.target.classList).includes(
"ai-bot-toggle-available-bots"
);
@ -55,7 +55,7 @@ export default class AiBotHeaderIcon extends Component {
#isOutsideDetailsClick(event) {
return !event.composedPath().some((element) => {
return element.className === "ai-bot-available-bot-options";
return element.className === "ai-bot-available-bot-content";
});
}
@ -67,6 +67,15 @@ export default class AiBotHeaderIcon extends Component {
document.addEventListener("click", this.closeDetails);
}
get botNames() {
return this.enabledBotOptions.map((bot) => {
return {
humanized: I18n.t(`discourse_ai.ai_bot.bot_names.${bot}`),
modelName: bot,
};
});
}
get enabledBotOptions() {
return this.siteSettings.ai_bot_enabled_chat_bots.split("|");
}
@ -82,15 +91,17 @@ export default class AiBotHeaderIcon extends Component {
return data.bot_username;
});
this.composer.open({
action: Composer.PRIVATE_MESSAGE,
recipients: botUsername,
topicTitle: `${I18n.t(
"discourse_ai.ai_bot.default_pm_prefix"
)} ${botUsername}`,
archetypeId: "private_message",
draftKey: Composer.NEW_PRIVATE_MESSAGE_KEY,
hasGroups: false,
this.composer.focusComposer({
fallbackToNewTopic: true,
openOpts: {
action: Composer.PRIVATE_MESSAGE,
recipients: botUsername,
topicTitle: I18n.t("discourse_ai.ai_bot.default_pm_prefix"),
archetypeId: "private_message",
draftKey: Composer.NEW_PRIVATE_MESSAGE_KEY,
hasGroups: false,
warningsDisabled: true,
},
});
this.open = false;

View File

@ -30,6 +30,12 @@ en:
default_pm_prefix: "[Untitled AI bot PM]"
shortcut_title: "Start a PM with an AI bot"
bot_names:
gpt-4: "GPT-4"
gpt-3:
5-turbo: "GPT-3.5"
claude-v1: "Claude V1"
review:
types:

View File

@ -194,7 +194,7 @@ plugins:
type: group_list
list_type: compact
default: "3|14" # 3: @staff, 14: @trust_level_4
# Adding a new bot? Make sure to create a user for it on the seed file.
# Adding a new bot? Make sure to create a user for it on the seed file and update translations.
ai_bot_enabled_chat_bots:
type: list
default: "gpt-3.5-turbo"