DEV: Rewire AI bot internals to use LlmModel (#638)
* DRAFT: Create AI Bot users dynamically and support custom LlmModels * Get user associated to llm_model * Track enabled bots with attribute * Don't store bot username. Minor touches to migrate default values in settings * Handle scenario where vLLM uses a SRV record * Made 3.5-turbo-16k the default version so we can remove hack
This commit is contained in:
@@ -11,7 +11,8 @@ export default class AiLlm extends RestModel {
|
||||
"tokenizer",
|
||||
"max_prompt_tokens",
|
||||
"url",
|
||||
"api_key"
|
||||
"api_key",
|
||||
"enabled_chat_bot"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
import Component from "@glimmer/component";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import { gt } from "truth-helpers";
|
||||
import DButton from "discourse/components/d-button";
|
||||
import i18n from "discourse-common/helpers/i18n";
|
||||
import { composeAiBotMessage } from "../lib/ai-bot-helper";
|
||||
|
||||
export default class AiBotHeaderIcon extends Component {
|
||||
@service currentUser;
|
||||
@service siteSettings;
|
||||
@service composer;
|
||||
|
||||
get bots() {
|
||||
return this.siteSettings.ai_bot_add_to_header
|
||||
? this.siteSettings.ai_bot_enabled_chat_bots.split("|").filter(Boolean)
|
||||
: [];
|
||||
const availableBots = this.currentUser.ai_enabled_chat_bots
|
||||
.filter((bot) => !bot.is_persosna)
|
||||
.filter(Boolean);
|
||||
|
||||
return availableBots ? availableBots.map((bot) => bot.model_name) : [];
|
||||
}
|
||||
|
||||
get showHeaderButton() {
|
||||
return this.bots.length > 0 && this.siteSettings.ai_bot_add_to_header;
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -22,7 +28,7 @@ export default class AiBotHeaderIcon extends Component {
|
||||
}
|
||||
|
||||
<template>
|
||||
{{#if (gt this.bots.length 0)}}
|
||||
{{#if this.showHeaderButton}}
|
||||
<li>
|
||||
<DButton
|
||||
@action={{this.compose}}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import Component from "@glimmer/component";
|
||||
import { tracked } from "@glimmer/tracking";
|
||||
import { Input } from "@ember/component";
|
||||
import { on } from "@ember/modifier";
|
||||
import { action } from "@ember/object";
|
||||
import { later } from "@ember/runloop";
|
||||
import { inject as service } from "@ember/service";
|
||||
import BackButton from "discourse/components/back-button";
|
||||
import DButton from "discourse/components/d-button";
|
||||
import DToggleSwitch from "discourse/components/d-toggle-switch";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
import icon from "discourse-common/helpers/d-icon";
|
||||
import i18n from "discourse-common/helpers/i18n";
|
||||
@@ -110,11 +112,31 @@ export default class AiLlmEditor extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
async toggleEnabledChatBot() {
|
||||
this.args.model.set("enabled_chat_bot", !this.args.model.enabled_chat_bot);
|
||||
if (!this.args.model.isNew) {
|
||||
try {
|
||||
await this.args.model.update({
|
||||
enabled_chat_bot: this.args.model.enabled_chat_bot,
|
||||
});
|
||||
} catch (e) {
|
||||
popupAjaxError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<template>
|
||||
<BackButton
|
||||
@route="adminPlugins.show.discourse-ai-llms"
|
||||
@label="discourse_ai.llms.back"
|
||||
/>
|
||||
{{#unless @model.url_editable}}
|
||||
<div class="alert alert-info">
|
||||
{{icon "exclamation-circle"}}
|
||||
{{I18n.t "discourse_ai.llms.srv_warning"}}
|
||||
</div>
|
||||
{{/unless}}
|
||||
<form class="form-horizontal ai-llm-editor">
|
||||
<div class="control-group">
|
||||
<label>{{i18n "discourse_ai.llms.display_name"}}</label>
|
||||
@@ -143,14 +165,16 @@ export default class AiLlmEditor extends Component {
|
||||
@content={{this.selectedProviders}}
|
||||
/>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label>{{I18n.t "discourse_ai.llms.url"}}</label>
|
||||
<Input
|
||||
class="ai-llm-editor-input ai-llm-editor__url"
|
||||
@type="text"
|
||||
@value={{@model.url}}
|
||||
/>
|
||||
</div>
|
||||
{{#if @model.url_editable}}
|
||||
<div class="control-group">
|
||||
<label>{{I18n.t "discourse_ai.llms.url"}}</label>
|
||||
<Input
|
||||
class="ai-llm-editor-input ai-llm-editor__url"
|
||||
@type="text"
|
||||
@value={{@model.url}}
|
||||
/>
|
||||
</div>
|
||||
{{/if}}
|
||||
<div class="control-group">
|
||||
<label>{{I18n.t "discourse_ai.llms.api_key"}}</label>
|
||||
<Input
|
||||
@@ -181,7 +205,14 @@ export default class AiLlmEditor extends Component {
|
||||
@content={{I18n.t "discourse_ai.llms.hints.max_prompt_tokens"}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<DToggleSwitch
|
||||
class="ai-llm-editor__enabled-chat-bot"
|
||||
@state={{@model.enabled_chat_bot}}
|
||||
@label="discourse_ai.llms.enabled_chat_bot"
|
||||
{{on "click" this.toggleEnabledChatBot}}
|
||||
/>
|
||||
</div>
|
||||
<div class="control-group ai-llm-editor__action_panel">
|
||||
<DButton
|
||||
class="ai-llm-editor__test"
|
||||
|
||||
@@ -4,7 +4,6 @@ import { hash } from "@ember/helper";
|
||||
import { next } from "@ember/runloop";
|
||||
import { inject as service } from "@ember/service";
|
||||
import KeyValueStore from "discourse/lib/key-value-store";
|
||||
import I18n from "I18n";
|
||||
import DropdownSelectBox from "select-kit/components/dropdown-select-box";
|
||||
|
||||
function isBotMessage(composer, currentUser) {
|
||||
@@ -110,15 +109,16 @@ export default class BotSelector extends Component {
|
||||
}
|
||||
|
||||
get llmOptions() {
|
||||
return this.siteSettings.ai_bot_enabled_chat_bots
|
||||
.split("|")
|
||||
.filter(Boolean)
|
||||
.map((bot) => {
|
||||
return {
|
||||
id: bot,
|
||||
name: I18n.t(`discourse_ai.ai_bot.bot_names.${bot}`),
|
||||
};
|
||||
});
|
||||
const availableBots = this.currentUser.ai_enabled_chat_bots
|
||||
.filter((bot) => !bot.is_persosna)
|
||||
.filter(Boolean);
|
||||
|
||||
return availableBots.map((bot) => {
|
||||
return {
|
||||
id: bot.model_name,
|
||||
name: bot.display_name,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user