import Component from "@glimmer/component"; import { concat, fn } from "@ember/helper"; import { action } from "@ember/object"; import { LinkTo } from "@ember/routing"; import { service } from "@ember/service"; import DBreadcrumbsItem from "discourse/components/d-breadcrumbs-item"; import icon from "discourse-common/helpers/d-icon"; import i18n from "discourse-common/helpers/i18n"; import I18n from "discourse-i18n"; import AdminPageSubheader from "admin/components/admin-page-subheader"; import AdminSectionLandingItem from "admin/components/admin-section-landing-item"; import AdminSectionLandingWrapper from "admin/components/admin-section-landing-wrapper"; import AiLlmEditor from "./ai-llm-editor"; export default class AiLlmsListEditor extends Component { @service adminPluginNavManager; @service router; @action modelDescription(llm) { // this is a bit of an odd object, it can be an llm model or a preset model // handle both flavors // in the case of model let key = ""; if (typeof llm.id === "number") { key = `${llm.provider}-${llm.name}`; } else { // case of preset key = llm.id.replace(/\./g, "-"); } key = `discourse_ai.llms.model_description.${key}`; if (I18n.lookup(key, { ignoreMissing: true })) { return I18n.t(key); } return ""; } sanitizedTranslationKey(id) { return id.replace(/\./g, "-"); } get hasLlmElements() { return this.args.llms.length !== 0; } get preconfiguredTitle() { if (this.hasLlmElements) { return "discourse_ai.llms.preconfigured.title"; } else { return "discourse_ai.llms.preconfigured.title_no_llms"; } } get preConfiguredLlms() { const options = [ { id: "none", name: I18n.t("discourse_ai.llms.preconfigured.fake"), provider: "fake", }, ]; const llmsContent = this.args.llms.content.map((llm) => ({ provider: llm.provider, name: llm.name, })); this.args.llms.resultSetMeta.presets.forEach((llm) => { if (llm.models) { llm.models.forEach((model) => { const id = `${llm.id}-${model.name}`; const isConfigured = llmsContent.some( (content) => content.provider === llm.provider && content.name === model.name ); if (!isConfigured) { options.push({ id, name: model.display_name, provider: llm.provider, }); } }); } }); return options; } @action transitionToLlmEditor(llmTemplate) { this.router.transitionTo("adminPlugins.show.discourse-ai-llms.new", { queryParams: { llmTemplate }, }); } localizeUsage(usage) { if (usage.type === "ai_persona") { return I18n.t("discourse_ai.llms.usage.ai_persona", { persona: usage.name, }); } else { return I18n.t("discourse_ai.llms.usage." + usage.type); } } }