The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Let conversation titles run on their own model (#78954)
Maksym Yakubych9b159ccf7897
diff --git a/frontend/src/metabase-types/api/settings.ts b/frontend/src/metabase-types/api/settings.tsindex 2e5dc5056dd..a2546644b49 100644--- a/frontend/src/metabase-types/api/settings.ts+++ b/frontend/src/metabase-types/api/settings.ts@@ -832,6 +832,7 @@ export interface EnterpriseSettings extends Settings {"python-runner-timeout-seconds"?: number | null;"python-runner-test-run-timeout-seconds"?: number | null;"llm-metabot-provider"?: string | null;+ "llm-mini-model"?: string | null;"llm-anthropic-api-key"?: string | null;"llm-anthropic-model": string;"llm-proxy-configured?"?: boolean | null;diff --git a/frontend/src/metabase/admin/ai/AIModelSettingsSection.tsx b/frontend/src/metabase/admin/ai/AIModelSettingsSection.tsxnew file mode 100644index 00000000000..54ea78bd10b--- /dev/null+++ b/frontend/src/metabase/admin/ai/AIModelSettingsSection.tsx@@ -0,0 +1,28 @@+import { t } from "ttag";++import { SettingsSection } from "metabase/admin/components/SettingsSection";+import { LlmModelPicker } from "metabase/metabot";+import { Stack } from "metabase/ui";++export function AIModelSettingsSection({ id }: { id?: string }) {+ return (+ <SettingsSection+ id={id}+ title={t`Models`}+ description={t`Pick which model each AI feature runs on. Models come from the providers you've connected.`}+ >+ <Stack gap="lg">+ <LlmModelPicker+ settingKey="llm-metabot-provider"+ label={t`Default model`}+ description={t`Metabot, AI explorations and SQL generation all run on this model.`}+ />+ <LlmModelPicker+ settingKey="llm-mini-model"+ label={t`Mini model`}+ description={t`Quick tasks, like naming conversations, run on this cheaper model. Defaults to the fastest model from the same provider as the default model.`}+ />+ </Stack>+ </SettingsSection>+ );+}diff --git a/frontend/src/metabase/admin/ai/AIModelSettingsSection.unit.spec.tsx b/frontend/src/metabase/admin/ai/AIModelSettingsSection.unit.spec.tsxnew file mode 100644index 00000000000..8f870d18985--- /dev/null+++ b/frontend/src/metabase/admin/ai/AIModelSettingsSection.unit.spec.tsx@@ -0,0 +1,204 @@+import userEvent from "@testing-library/user-event";+import fetchMock from "fetch-mock";++import {+ setupPropertiesEndpoints,+ setupSettingsEndpoints,+ setupUpdateSettingEndpoint,+} from "__support__/server-mocks";+import { setupLlmModelsEndpoint } from "__support__/server-mocks/metabot";+import { mockSettings } from "__support__/settings";+import { renderWithProviders, screen, waitFor, within } from "__support__/ui";+import { UndoListing } from "metabase/common/components/UndoListing";+import type { LlmConnectionModels } from "metabase-types/api";+import {+ createMockLlmConnectionModels,+ createMockLlmModel,+ createMockSettingDefinition,+ createMockSettings,+ createMockUser,+} from "metabase-types/api/mocks";++import { AIModelSettingsSection } from "./AIModelSettingsSection";++const CONNECTION_MODELS = [+ createMockLlmConnectionModels({+ key: "anthropic",+ name: "Anthropic",+ type: "anthropic",+ models: [+ createMockLlmModel({+ id: "claude-sonnet-4-5",+ display_name: "Claude Sonnet 4.5",+ }),+ createMockLlmModel({+ id: "claude-haiku-4-5",+ display_name: "Claude Haiku 4.5",+ }),+ ],+ }),+ createMockLlmConnectionModels({+ key: "azure-prod",+ name: "Azure prod",+ type: "azure",+ models: [createMockLlmModel({ id: "gpt-5", display_name: "GPT-5" })],+ }),+];++type SetupOpts = {+ models?: LlmConnectionModels[];+ metabotModel?: string | null;+ metabotModelEnvVar?: string;+ miniModel?: string | null;+};++function renderSection({+ models = CONNECTION_MODELS,+ metabotModel = "anthropic/claude-sonnet-4-5",+ metabotModelEnvVar,+ miniModel = "anthropic/claude-haiku-4-5",+}: SetupOpts = {}) {+ fetchMock.removeRoutes();+ fetchMock.clearHistory();++ const sessionProperties = createMockSettings({+ "llm-metabot-provider": metabotModel,+ "llm-mini-model": miniModel,+ });++ setupPropertiesEndpoints(sessionProperties);+ setupSettingsEndpoints([+ createMockSettingDefinition({+ key: "llm-metabot-provider",+ value: metabotModel,+ is_env_setting: metabotModelEnvVar != null,+ env_name: metabotModelEnvVar,+ }),+ createMockSettingDefinition({ key: "llm-mini-model", value: miniModel }),+ ]);+ setupUpdateSettingEndpoint();+ setupLlmModelsEndpoint(models);++ renderWithProviders(+ <>+ <AIModelSettingsSection />+ <UndoListing />+ </>,+ {+ storeInitialState: {+ settings: mockSettings(sessionProperties),+ currentUser: createMockUser({ is_superuser: true }),+ },+ },+ );+}++async function setup(opts: SetupOpts = {}) {+ renderSection(opts);++ await screen.findByText("Models");+ await waitFor(() =>+ expect(screen.getByLabelText("Default model")).not.toHaveValue(""),+ );+}++async function openPicker(label: string) {+ await userEvent.click(screen.getByLabelText(label));+ return await screen.findByRole("listbox");+}++describe("AIModelSettingsSection", () => {+ it("stays on screen while the models are still loading", () => {+ renderSection();++ expect(screen.getByText("Models")).toBeInTheDocument();+ expect(screen.getByLabelText("Default model")).toBeDisabled();+ expect(screen.getByLabelText("Mini model")).toBeDisabled();+ expect(screen.getAllByPlaceholderText("Loading models...")).toHaveLength(2);+ });++ it("shows the model each use case runs on", async () => {+ await setup();++ expect(screen.getByLabelText("Default model")).toHaveValue(+ "Anthropic · Claude Sonnet 4.5",+ );+ expect(screen.getByLabelText("Mini model")).toHaveValue(+ "Anthropic · Claude Haiku 4.5",+ );+ });++ it("lists models grouped by connection and saves the picked default", async () => {+ await setup();++ const listbox = await openPicker("Default model");++ expect(within(listbox).getByText("Anthropic")).toBeInTheDocument();+ expect(within(listbox).getByText("Azure prod")).toBeInTheDocument();++ await userEvent.click(+ within(listbox).getByRole("option", { name: "GPT-5" }),+ );++ await waitFor(() => {+ expect(+ fetchMock.callHistory.called("path:/api/setting/llm-metabot-provider", {+ method: "PUT",+ body: { value: "azure-prod/gpt-5" },+ }),+ ).toBe(true);+ });++ expect(await screen.findAllByText("Changes saved")).toHaveLength(1);+ });++ it("surfaces a failure to save the picked model", async () => {+ await setup();++ fetchMock.modifyRoute("update-setting", {+ response: { status: 400, body: { message: "Unsupported model" } },+ });++ const listbox = await openPicker("Default model");+ await userEvent.click(+ within(listbox).getByRole("option", { name: "GPT-5" }),+ );++ expect(await screen.findByText("Unsupported model")).toBeInTheDocument();+ expect(screen.queryByText("Changes saved")).not.toBeInTheDocument();+ });++ it("locks the model picker and names the env var when the model is set by one", async () => {+ await setup({ metabotModelEnvVar: "MB_LLM_METABOT_PROVIDER" });++ expect(+ await screen.findByTestId("setting-env-var-message"),+ ).toHaveTextContent("MB_LLM_METABOT_PROVIDER");+ expect(screen.getByLabelText("Default model")).toBeDisabled();+ });++ it("saves the mini model separately from the default model", async () => {+ await setup();++ const listbox = await openPicker("Mini model");++ await userEvent.click(+ within(listbox).getByRole("option", { name: "GPT-5" }),+ );++ await waitFor(() => {+ expect(+ fetchMock.callHistory.called("path:/api/setting/llm-mini-model", {+ method: "PUT",+ body: { value: "azure-prod/gpt-5" },+ }),+ ).toBe(true);+ });++ expect(+ fetchMock.callHistory.called("path:/api/setting/llm-metabot-provider", {+ method: "PUT",+ }),+ ).toBe(false);+ });+});diff --git a/frontend/src/metabase/admin/ai/AIProviderSettingsSection.unit.spec.tsx b/frontend/src/metabase/admin/ai/AIProviderSettingsSection.unit.spec.tsxindex c329285a847..48bacc85240 100644--- a/frontend/src/metabase/admin/ai/AIProviderSettingsSection.unit.spec.tsx+++ b/frontend/src/metabase/admin/ai/AIProviderSettingsSection.unit.spec.tsx@@ -268,11 +268,6 @@ async function openAdvancedSettings(modal: HTMLElement) {);}-async function openModelPicker() {- await userEvent.click(screen.getByLabelText("Model"));- return await screen.findByRole("listbox");-}-describe("AIProviderSettingsSection", () => {afterEach(() => {reinitialize();@@ -319,7 +314,6 @@ describe("AIProviderSettingsSection", () => {expect(screen.getByRole("button", { name: /Add another provider/ }),).toBeInTheDocument();- expect(screen.getByLabelText("Model")).toBeInTheDocument();});it("picks the provider and fills the key in when one is pasted", async () => {@@ -654,87 +648,6 @@ describe("AIProviderSettingsSection", () => {screen.queryByRole("button", { name: "Provider options" }),).not.toBeInTheDocument();});-- it("lists models grouped by connection and saves the picked one", async () => {- await setup({- connections: [ANTHROPIC_CONNECTION, AZURE_CONNECTION],- models: CONNECTION_MODELS,- modelRef: "anthropic/claude-sonnet-4-5",- });-- // closed, the picker names the provider too — the dropdown does not, because its group- // heading already does- await waitFor(() =>- expect(screen.getByLabelText("Model")).toHaveValue(- "Anthropic · Claude Sonnet 4.5",- ),- );-- const listbox = await openModelPicker();-- expect(within(listbox).getByText("Anthropic")).toBeInTheDocument();- expect(within(listbox).getByText("Azure prod")).toBeInTheDocument();- expect(- within(listbox).getByRole("option", { name: "Claude Haiku 4.5" }),- ).toBeInTheDocument();-- await userEvent.click(- within(listbox).getByRole("option", { name: "GPT-5" }),- );-- await waitFor(() => {- expect(- fetchMock.callHistory.called("path:/api/setting/llm-metabot-provider", {- method: "PUT",- body: { value: "azure-prod/gpt-5" },- }),- ).toBe(true);- });-- expect(await screen.findAllByText("Changes saved")).toHaveLength(1);- });-- it("surfaces a failure to save the picked model", async () => {- await setup({- connections: [ANTHROPIC_CONNECTION, AZURE_CONNECTION],- models: CONNECTION_MODELS,- modelRef: "anthropic/claude-sonnet-4-5",- });-- // closed, the picker names the provider too — the dropdown does not, because its group- // heading already does- await waitFor(() =>- expect(screen.getByLabelText("Model")).toHaveValue(- "Anthropic · Claude Sonnet 4.5",- ),- );-- fetchMock.modifyRoute("update-setting", {- response: { status: 400, body: { message: "Unsupported model" } },- });-- const listbox = await openModelPicker();- await userEvent.click(- within(listbox).getByRole("option", { name: "GPT-5" }),- );-- expect(await screen.findByText("Unsupported model")).toBeInTheDocument();- expect(screen.queryByText("Changes saved")).not.toBeInTheDocument();- });-- it("locks the model picker and names the env var when the model is set by one", async () => {- await setup({- connections: [ANTHROPIC_CONNECTION],- models: CONNECTION_MODELS,- modelRef: "anthropic/claude-sonnet-4-5",- modelRefEnvVar: "MB_LLM_METABOT_PROVIDER",- });-- expect(- await screen.findByTestId("setting-env-var-message"),- ).toHaveTextContent("MB_LLM_METABOT_PROVIDER");- expect(screen.getByLabelText("Model")).toBeDisabled();- });});describe("AIProviderSetup (ad-hoc connect modal)", () => {diff --git a/frontend/src/metabase/admin/ai/AISettingsPage.tsx b/frontend/src/metabase/admin/ai/AISettingsPage.tsxindex 085e510d4a7..95caa664442 100644--- a/frontend/src/metabase/admin/ai/AISettingsPage.tsx+++ b/frontend/src/metabase/admin/ai/AISettingsPage.tsx@@ -20,6 +20,7 @@ import { queryToSearch, useSearchParams } from "metabase/router";import { useAdminSetting, useSetting } from "metabase/settings";import { Divider, Flex, Stack, Switch, Tabs } from "metabase/ui";+import { AIModelSettingsSection } from "./AIModelSettingsSection";import { AIProviderSettingsSection } from "./AIProviderSettingsSection";import { EmbeddedMetabotUpsell } from "./EmbeddedMetabotUpsell";import { McpAppsSettings } from "./McpAppsSettings";@@ -30,6 +31,7 @@ type MetabotTabId =| typeof FIXED_METABOT_IDS.EMBEDDED;const SETUP_SECTION_ID = "setup";+const MODELS_SECTION_ID = "models";const METABOT_SECTION_ID = "metabot";const MCP_SECTION_ID = "mcp";const AGENT_API_SECTION_ID = "agent-api";@@ -71,6 +73,7 @@ export function AISettingsPage() {<><AIProviderSettingsSection id={SETUP_SECTION_ID} /><DisabledSection disabled={!isConfigured}>+ <AIModelSettingsSection id={MODELS_SECTION_ID} /><MetabotSettingsSectionhasEmbedding={hasEmbedding}id={METABOT_SECTION_ID}diff --git a/frontend/src/metabase/metabot/components/AIProviderConfigurationForm/AIProviderList.tsx b/frontend/src/metabase/metabot/components/AIProviderConfigurationForm/AIProviderList.tsxindex 798b0341c50..9fef0af6a15 100644--- a/frontend/src/metabase/metabot/components/AIProviderConfigurationForm/AIProviderList.tsx+++ b/frontend/src/metabase/metabot/components/AIProviderConfigurationForm/AIProviderList.tsx@@ -34,7 +34,6 @@ import type {LlmProviderType,} from "metabase-types/api";-import { LlmModelPicker } from "./LlmModelPicker";import { ProviderConnectionModal } from "./ProviderConnectionModal";import { ProviderTypeIcon } from "./ProviderTypeIcon";import { getAddableProviderTypes } from "./addable-provider-types";@@ -163,8 +162,6 @@ export function AIProviderList() {</Button></Stack>- {hasConnections && <LlmModelPicker />}-{(isAdding || editing) && (<ProviderConnectionModalproviderTypes={editing ? providerTypes : addableProviderTypes}diff --git a/frontend/src/metabase/metabot/components/AIProviderConfigurationForm/AIProviderList.unit.spec.tsx b/frontend/src/metabase/metabot/components/AIProviderConfigurationForm/AIProviderList.unit.spec.tsxindex 54c4c7e07ef..719ebdde656 100644--- a/frontend/src/metabase/metabot/components/AIProviderConfigurationForm/AIProviderList.unit.spec.tsx+++ b/frontend/src/metabase/metabot/components/AIProviderConfigurationForm/AIProviderList.unit.spec.tsx@@ -11,7 +11,7 @@ import {setupLlmProvidersEndpoint,} from "__support__/server-mocks/metabot";import { mockSettings } from "__support__/settings";-import { renderWithProviders, screen, within } from "__support__/ui";+import { renderWithProviders, screen, waitFor, within } from "__support__/ui";import type { LlmConnectionModels } from "metabase-types/api";import {createMockLlmConnectionModels,@@ -119,9 +119,12 @@ describe("AIProviderList", () => {});expect(await screen.findByTestId("provider-anthropic")).toBeInTheDocument();- expect(await screen.findByText("Model")).toBeInTheDocument();- expect(fetchMock.callHistory.calls("path:/api/llm/models")).toHaveLength(1);+ await waitFor(() =>+ expect(fetchMock.callHistory.calls("path:/api/llm/models")).toHaveLength(+ 1,+ ),+ );});it.each([diff --git a/frontend/src/metabase/metabot/components/AIProviderConfigurationForm/LlmModelPicker.tsx b/frontend/src/metabase/metabot/components/AIProviderConfigurationForm/LlmModelPicker.tsxindex 28cc4855c9f..31fc0fa381a 100644--- a/frontend/src/metabase/metabot/components/AIProviderConfigurationForm/LlmModelPicker.tsx+++ b/frontend/src/metabase/metabot/components/AIProviderConfigurationForm/LlmModelPicker.tsx@@ -6,12 +6,22 @@ import { useLlmConnectionModels } from "metabase/metabot/hooks";import { useAdminSetting } from "metabase/settings";import { DefaultSelectItem, Select, Stack } from "metabase/ui";-export function LlmModelPicker() {+export type LlmModelSettingKey = "llm-metabot-provider" | "llm-mini-model";++export function LlmModelPicker({+ settingKey = "llm-metabot-provider",+ label = t`Model`,+ description = t`Metabot uses this model by default. Models are listed per connected provider.`,+}: {+ settingKey?: LlmModelSettingKey;+ label?: string;+ description?: string;+}) {const {value: modelRef,updateSetting,settingDetails,- } = useAdminSetting("llm-metabot-provider");+ } = useAdminSetting(settingKey);const { modelOptions, modelNameByRef, isLoading, error } =useLlmConnectionModels();@@ -22,14 +32,14 @@ export function LlmModelPicker() {if (!value) {return;}- await updateSetting({ key: "llm-metabot-provider", value });+ await updateSetting({ key: settingKey, value });};return (<Stack gap="sm"><Select- label={t`Model`}- description={t`Metabot uses this model by default. Models are listed per connected provider.`}+ label={label}+ description={description}placeholder={isLoading ? t`Loading models...` : t`Select a model`}error={error ? getErrorMessage(error, t`Unable to load models.`) : null}data={modelOptions}diff --git a/src/metabase/llm/api/provider.clj b/src/metabase/llm/api/provider.cljindex 7e39c1d693e..4a6eb8846e2 100644--- a/src/metabase/llm/api/provider.clj+++ b/src/metabase/llm/api/provider.clj@@ -259,15 +259,19 @@[]nil)+(defn- repoint!+ "Write `model-ref` as `setting-key` — unless an env var pins that setting, in which case the write would land in+ the app DB and lose to the env var on every read, leaving the UI claiming a selection the instance is not+ actually using."+ [setting-key model-ref]+ (if (setting/env-var-value setting-key)+ (log/warnf "Leaving %s alone: %s is set by the environment"+ (name setting-key) (setting/env-var-name setting-key))+ (setting/set! setting-key model-ref)))+(defn- repoint-metabot!- "Write `model-ref` as the Metabot selection — unless `MB_LLM_METABOT_PROVIDER` pins it, in which case the write- would land in the app DB and lose to the env var on every read, leaving the UI claiming a selection the instance- is not actually using."[model-ref]- (if (setting/env-var-value :llm-metabot-provider)- (log/warnf "Leaving llm-metabot-provider alone: %s is set by the environment"- (setting/env-var-name :llm-metabot-provider))- (setting/set! :llm-metabot-provider model-ref)))+ (repoint! :llm-metabot-provider model-ref))(defn- metabot-has-a-usable-model?"Whether `llm-metabot-provider` currently names a connection that can serve requests. Callers must read this@@ -288,23 +292,32 @@(repoint-metabot! model-ref)))(defn- follow-edited-connection-model!- "Keep `llm-metabot-provider` on the model an edited connection actually serves.+ "Keep the model-reference settings on the model an edited connection actually serves.A model reference stores the model as a string rather than as a live lookup, so for a type whose model comes fromits own config — Azure, whose reference bakes in `{family}/{deployment-name}` — editing the connection can leave- the selection naming a deployment that no longer exists. The connection still reports usable, and the next+ a selection naming a deployment that no longer exists. The connection still reports usable, and the nextrequest fails at the provider. For a type with a fixed catalog the model in the edit form is a pick, not a- probe input: when the selection points at this connection, the pick follows through to it."- [{conn-key :key :keys [type config] :as conn} requested-model]- (when (= conn-key (llm.provider/model-ref->connection-key (metabot.settings/llm-metabot-provider)))- (when-let [model-ref (cond- (llm.provider/connection-model type (llm.provider/with-field-defaults type config))- (connection-model-ref conn)+ probe input: when the selection points at this connection, the pick follows through to it.- (and (not-empty requested-model) (seq (llm.provider/fixed-models type)))- (str conn-key "/" requested-model))]- (when-not (= model-ref (metabot.settings/llm-metabot-provider))- (repoint-metabot! model-ref)))))+ An explicitly pinned mini model moves with a composed model the same way — its reference goes just as stale —+ but not with a pick, which changes what the admin prefers rather than what the connection can serve. A derived+ mini model needs no help, since it follows the Metabot selection on its own."+ [{conn-key :key :keys [type config] :as conn} requested-model]+ (let [composed-ref (when (llm.provider/connection-model type (llm.provider/with-field-defaults type config))+ (connection-model-ref conn))+ picked-ref (when (and (not-empty requested-model) (seq (llm.provider/fixed-models type)))+ (str conn-key "/" requested-model))+ metabot-ref (metabot.settings/llm-metabot-provider)+ mini-ref (metabot.settings/explicit-mini-model)]+ (when-let [model-ref (or composed-ref picked-ref)]+ (when (and (= conn-key (llm.provider/model-ref->connection-key metabot-ref))+ (not= model-ref metabot-ref))+ (repoint-metabot! model-ref)))+ (when (and composed-ref+ (= conn-key (llm.provider/model-ref->connection-key mini-ref))+ (not= composed-ref mini-ref))+ (repoint! :llm-mini-model composed-ref))));;; -------------------------------------------------- Endpoints ---------------------------------------------------@@ -427,6 +440,8 @@(cancel-managed-ai-subscription!))(let [remaining (vec (remove #(= (:key %) conn-key) (llm.provider/stored-connections)))](llm.provider/set-connections! remaining)+ (when (= conn-key (llm.provider/model-ref->connection-key (metabot.settings/explicit-mini-model)))+ (setting/set! :llm-mini-model nil))(when (= conn-key (llm.provider/model-ref->connection-key (metabot.settings/llm-metabot-provider)))(repoint-metabot! (fallback-model-ref)))))nil)diff --git a/src/metabase/llm/provider.clj b/src/metabase/llm/provider.cljindex 32562de19cc..53780bb12fc 100644--- a/src/metabase/llm/provider.clj+++ b/src/metabase/llm/provider.clj@@ -45,6 +45,7 @@[{:type "anthropic":label (deferred-tru "Anthropic"):default-model "claude-sonnet-4-6"+ :mini-model "claude-haiku-4-5-20251001":fields [{:key :api-key:label (deferred-tru "API key"):type :password@@ -61,6 +62,7 @@{:type "openai":label (deferred-tru "OpenAI"):default-model "gpt-5.4"+ :mini-model "gpt-5.4-mini":fields [{:key :api-key:label (deferred-tru "API key"):type :password@@ -77,6 +79,7 @@{:type "openrouter":label (deferred-tru "OpenRouter"):default-model "anthropic/claude-sonnet-4.6"+ :mini-model "anthropic/claude-haiku-4.5":fields [{:key :api-key:label (deferred-tru "API key"):type :password@@ -93,6 +96,7 @@{:type "mistral":label (deferred-tru "Mistral"):default-model "mistral-medium-3-5"+ :mini-model "mistral-medium-3-5":fields [{:key :api-key:label (deferred-tru "API key"):type :password@@ -109,6 +113,7 @@{:type "zai":label (deferred-tru "Z.AI"):default-model "glm-5.2"+ :mini-model "glm-5.2":fields [{:key :api-key:label (deferred-tru "API key"):type :password@@ -125,6 +130,7 @@{:type "moonshot":label (deferred-tru "Moonshot AI"):default-model "kimi-k3"+ :mini-model "kimi-k3":fields [{:key :api-key:label (deferred-tru "API key"):type :password@@ -238,6 +244,7 @@{:type "bedrock":label (deferred-tru "Amazon Bedrock"):default-model "anthropic.claude-opus-4-8"+ :mini-model "anthropic.claude-haiku-4-5":fields [{:key :access-key-id:label (deferred-tru "Access key ID"):type :password@@ -329,6 +336,14 @@[type-name](:default-model (provider-type type-name)))+(defn mini-model+ "The fastest and cheapest model `type-name` serves — what short utility calls such as conversation titles run on+ when no model has been picked for them. Returns nil for the types that have no cheaper tier to fall back to: the+ ones whose connection names the single model it serves rather than picking from a catalog, and the managed+ provider, which serves one benchmarked model."+ [type-name]+ (:mini-model (provider-type type-name)))+;;; -------------------------------------------------- Validation --------------------------------------------------(defn connection-modeldiff --git a/src/metabase/metabot/conversation_title.clj b/src/metabase/metabot/conversation_title.cljindex aa17d1e10d4..7016e806002 100644--- a/src/metabase/metabot/conversation_title.clj+++ b/src/metabase/metabot/conversation_title.clj@@ -122,7 +122,7 @@;; titles must respect the usage limit too, like metabot.self/call-llm(not (metabot.usage/check-usage-limits!)))(let [response (metabot.self/call-llm-structured- (metabot.settings/llm-metabot-provider)+ (metabot.settings/llm-mini-model)[{:role "system" :content title-system-prompt}{:role "user" :content (str "<session>\n" message "\n</session>")}]title-json-schemadiff --git a/src/metabase/metabot/settings.clj b/src/metabase/metabot/settings.cljindex da71f4d1f5e..94483b13ffc 100644--- a/src/metabase/metabot/settings.clj+++ b/src/metabase/metabot/settings.clj@@ -136,14 +136,14 @@(pr-str model) (str/join ", " (sort allowed))){:status-code 400 :model model})))))-(defn- validate-metabot-provider!+(defn- validate-model-ref!"Validate that `value` is a `connection-key/model` string with a non-blank model, plus whatever extra rules thenamed connection's provider type imposes on its models.- Deliberately does *not* require the connection to exist. The setting can legitimately be written before the- connection it names — an env var, a config file, or a serdes import can land in either order — and a value naming- a missing connection is already reported where it is actionable: [[llm-metabot-configured?]] reads false, and- resolving it for a request throws a 400 that names the connection.+ Deliberately does *not* require the connection to exist. A model-reference setting can legitimately be written+ before the connection it names — an env var, a config file, or a serdes import can land in either order — and a+ value naming a missing connection is already reported where it is actionable: [[llm-metabot-configured?]] reads+ false, and resolving it for a request throws a 400 that names the connection.Throws an exception with `:status-code 400` on invalid input."[value]@@ -169,9 +169,47 @@:deprecated-name :ee-ai-metabot-provider:setter (fn [new-value](when new-value- (validate-metabot-provider! new-value))+ (validate-model-ref! new-value))(setting/set-value-of-type! :string :llm-metabot-provider new-value)))+(defn- mini-model-ref+ "The model reference for the fastest model of the connection `model-ref` names, or nil when that connection's+ provider type has no such model."+ [model-ref]+ (let [conn-key (llm.provider/model-ref->connection-key model-ref)]+ (when-let [model (llm.provider/mini-model (:type (llm.provider/connection conn-key)))]+ (str conn-key "/" model))))++(defn explicit-mini-model+ "The model reference [[llm-mini-model]] was explicitly set to, or nil while it is being derived+ from [[llm-metabot-provider]]. Callers that act on the admin's choice rather than on the model quick tasks happen+ to run on want this: [[llm-mini-model]] itself resolves, so it names a connection even when none was ever picked."+ []+ (setting/get-value-of-type :string :llm-mini-model))++(defn- -llm-mini-model+ "Quick background tasks — naming a conversation, and whatever short, high-volume calls come next — do not need the+ model Metabot chats on, so with nothing stored this resolves to the fastest model of the+ connection [[llm-metabot-provider]] names. Connections whose provider type has no such model — the ones that name+ the single model they serve, and the managed provider — fall through to the Metabot model itself, so this always+ names a model as long as Metabot does."+ []+ (or (explicit-mini-model)+ (let [metabot-ref (llm-metabot-provider)]+ (or (mini-model-ref metabot-ref) metabot-ref))))++(defsetting llm-mini-model+ (deferred-tru "The AI provider connection and model used for quick background tasks, such as naming Metabot conversations, in the same connection-key/model-name format as `llm-metabot-provider`. Defaults to the fastest model offered by the connection Metabot runs on.")+ :type :string+ :encryption :no+ :visibility :settings-manager+ :export? false+ :getter #'-llm-mini-model+ :setter (fn [new-value]+ (when new-value+ (validate-model-ref! new-value))+ (setting/set-value-of-type! :string :llm-mini-model new-value)))+(defsetting llm-metabot-configured?"Whether the connection selected for Metabot has the credentials it needs.":type :booleandiff --git a/test/metabase/llm/api/provider_test.clj b/test/metabase/llm/api/provider_test.cljindex 470590e3807..5463dd65a84 100644--- a/test/metabase/llm/api/provider_test.clj+++ b/test/metabase/llm/api/provider_test.clj@@ -553,6 +553,52 @@{:config {:deployment-name "gpt-4.1"}})(is (= "anthropic/claude-opus-4-1" (metabot.settings/llm-metabot-provider))))))))+(deftest update-follows-the-deployment-on-a-pinned-mini-model-test+ (testing "a mini model pinned to the edited connection moves to the deployment it now serves"+ (mt/with-dynamic-fn-redefs [metabot.self/list-models (fn [& _] {:models []})]+ (mt/with-temporary-setting-values [llm-providers [(connection "anthropic" "anthropic" {:api-key "sk-ant-stored"})+ (connection "azure" "azure"+ {:api-key "azure-key"+ :base-url "https://r.services.ai.azure.com/openai"+ :model-family "openai"+ :deployment-name "gpt-4.1-mini"})]]+ (mt/with-temporary-raw-setting-values [llm-metabot-provider "anthropic/claude-opus-4-1"+ llm-mini-model "azure/openai/gpt-4.1-mini"]+ (mt/user-http-request :crowberto :put 200 "llm/providers/azure"+ {:config {:deployment-name "gpt-4.1"}})+ (is (= "azure/openai/gpt-4.1" (metabot.settings/explicit-mini-model))))))))++(deftest update-leaves-a-derived-mini-model-derived-test+ (testing "a mini model that was never pinned stays derived rather than being materialized by the edit"+ (mt/with-dynamic-fn-redefs [metabot.self/list-models (fn [& _] {:models []})]+ (mt/with-temporary-setting-values [llm-providers [(connection "azure" "azure"+ {:api-key "azure-key"+ :base-url "https://r.services.ai.azure.com/openai"+ :model-family "openai"+ :deployment-name "gpt-4.1-mini"})]]+ (mt/with-temporary-raw-setting-values [llm-metabot-provider "azure/openai/gpt-4.1-mini"+ llm-mini-model nil]+ (mt/user-http-request :crowberto :put 200 "llm/providers/azure"+ {:config {:deployment-name "gpt-4.1"}})+ (is (nil? (metabot.settings/explicit-mini-model)))+ (testing "and resolves through the followed Metabot selection"+ (is (= "azure/openai/gpt-4.1" (metabot.settings/llm-mini-model)))))))))++(deftest update-leaves-a-mini-model-on-another-connection-alone-test+ (testing "editing an Azure connection the mini model is not pinned to leaves the pin alone"+ (mt/with-dynamic-fn-redefs [metabot.self/list-models (fn [& _] {:models []})]+ (mt/with-temporary-setting-values [llm-providers [(connection "anthropic" "anthropic" {:api-key "sk-ant-stored"})+ (connection "azure" "azure"+ {:api-key "azure-key"+ :base-url "https://r.services.ai.azure.com/openai"+ :model-family "openai"+ :deployment-name "gpt-4.1-mini"})]]+ (mt/with-temporary-raw-setting-values [llm-metabot-provider "anthropic/claude-opus-4-1"+ llm-mini-model "anthropic/claude-haiku-4-5-20251001"]+ (mt/user-http-request :crowberto :put 200 "llm/providers/azure"+ {:config {:deployment-name "gpt-4.1"}})+ (is (= "anthropic/claude-haiku-4-5-20251001" (metabot.settings/explicit-mini-model))))))))+(deftest delete-removes-the-connection-test(mt/with-temporary-raw-setting-values [llm-metabot-provider "openai/gpt-4.1-mini"](mt/with-temporary-setting-values [llm-providers [(connection "anthropic" "anthropic" {:api-key "sk-ant-stored"})@@ -621,6 +667,24 @@(mt/user-http-request :crowberto :delete 204 "llm/providers/anthropic")(is (= "azure/openai/gpt-4.1-mini" (metabot.settings/llm-metabot-provider)))))))+(deftest delete-clears-a-mini-model-on-the-deleted-connection-test+ (testing "an explicit mini model pointing at the deleted connection goes back to being derived"+ (mt/with-temporary-raw-setting-values [llm-metabot-provider "openai/gpt-5.4"+ llm-mini-model "anthropic/claude-haiku-4-5"]+ (mt/with-temporary-setting-values [llm-providers [(connection "anthropic" "anthropic" {:api-key "sk-ant-stored"})+ (connection "openai" "openai" {:api-key "sk-stored"})]]+ (mt/user-http-request :crowberto :delete 204 "llm/providers/anthropic")+ (is (nil? (setting/db-stored-value :llm-mini-model)))+ (is (= "openai/gpt-5.4-mini" (metabot.settings/llm-mini-model)))))))++(deftest delete-leaves-an-unrelated-mini-model-alone-test+ (mt/with-temporary-raw-setting-values [llm-metabot-provider "openai/gpt-5.4"+ llm-mini-model "openai/gpt-5.4-mini"]+ (mt/with-temporary-setting-values [llm-providers [(connection "anthropic" "anthropic" {:api-key "sk-ant-stored"})+ (connection "openai" "openai" {:api-key "sk-stored"})]]+ (mt/user-http-request :crowberto :delete 204 "llm/providers/anthropic")+ (is (= "openai/gpt-5.4-mini" (setting/db-stored-value :llm-mini-model))))))+(deftest delete-unknown-connection-is-a-404-test(mt/with-temporary-setting-values [llm-providers []](mt/user-http-request :crowberto :delete 404 "llm/providers/nope")))diff --git a/test/metabase/llm/provider_test.clj b/test/metabase/llm/provider_test.cljindex e86fa014db6..4e42cd7654a 100644--- a/test/metabase/llm/provider_test.clj+++ b/test/metabase/llm/provider_test.clj@@ -467,6 +467,21 @@"metabase" "anthropic/claude-sonnet-4-6"}(into {} (map (juxt :type #(llm.provider/default-model (:type %)))) (llm.provider/provider-types))))(is (nil? (llm.provider/default-model "evilai"))))+ (testing (str "every type's mini model, which short utility calls like conversation titles fall back to. A type "+ "that grows a mini model, or loses one, has to be spelled out here — a missing `:mini-model` reads "+ "as nil and quietly sends titles to the full-size model instead.")+ (is (= {"anthropic" "claude-haiku-4-5-20251001"+ "openai" "gpt-5.4-mini"+ "openrouter" "anthropic/claude-haiku-4.5"+ "mistral" "mistral-medium-3-5"+ "zai" "glm-5.2"+ "moonshot" "kimi-k3"+ "google" nil+ "azure" nil+ "bedrock" "anthropic.claude-haiku-4-5"+ "metabase" nil}+ (into {} (map (juxt :type #(llm.provider/mini-model (:type %)))) (llm.provider/provider-types))))+ (is (nil? (llm.provider/mini-model "evilai"))))(testing "every type other than the managed one is always available"(is (true? (llm.provider/type-available? "anthropic")))(is (false? (llm.provider/type-available? "evilai")))))diff --git a/test/metabase/metabot/self_test.clj b/test/metabase/metabot/self_test.cljindex c00ee0ce54e..7c18bd7b59a 100644--- a/test/metabase/metabot/self_test.clj+++ b/test/metabase/metabot/self_test.clj@@ -6,13 +6,19 @@[clojure.test :refer :all][metabase.analytics-interface.core :as analytics][metabase.analytics.snowplow-test :as snowplow-test]+ [metabase.llm.provider :as llm.provider][metabase.llm.test-util :as llm.tu][metabase.metabot.schema.v2 :as schema.v2][metabase.metabot.scope :as scope][metabase.metabot.self :as self]+ [metabase.metabot.self.bedrock :as bedrock][metabase.metabot.self.claude :as self.claude][metabase.metabot.self.core :as self.core]+ [metabase.metabot.self.mistral :as mistral]+ [metabase.metabot.self.moonshot :as moonshot]+ [metabase.metabot.self.openai :as openai][metabase.metabot.self.openrouter :as openrouter]+ [metabase.metabot.self.zai :as zai][metabase.metabot.settings :as metabot.settings][metabase.metabot.test-util :as test-util][metabase.metabot.usage :as usage]@@ -29,6 +35,25 @@;;; provider resolution tests+(def ^:private supported-models-by-provider-type+ {"anthropic" #'self.claude/supported-models+ "bedrock" #'bedrock/supported-models+ "mistral" #'mistral/supported-models+ "moonshot" #'moonshot/supported-models+ "openai" #'openai/supported-models+ "openrouter" #'openrouter/supported-models+ "zai" #'zai/supported-models})++(deftest ^:parallel registry-models-are-listable-test+ (testing (str "`list-models` hands the admin picker the intersection of the adapter's whitelist with the "+ "provider's own catalog, so a model the registry names but the whitelist omits is never offered: "+ "the picker renders it as a blank selection. Azure and the managed provider are absent because "+ "neither adapter filters against a whitelist.")+ (doseq [[provider-type supported] supported-models-by-provider-type]+ (testing provider-type+ (is (contains? @supported (llm.provider/default-model provider-type)))+ (is (contains? @supported (llm.provider/mini-model provider-type)))))))+(deftest parse-provider-model-test(llm.tu/with-default-connections(testing "resolves connection-key/model against the configured connections"diff --git a/test/metabase/metabot/settings_test.clj b/test/metabase/metabot/settings_test.cljindex ba430346016..9b3b1cb32ab 100644--- a/test/metabase/metabot/settings_test.clj+++ b/test/metabase/metabot/settings_test.clj@@ -302,6 +302,61 @@clojure.lang.ExceptionInfo #"Model name is required"(metabot.settings/llm-metabot-provider! "metabase/")))))))+(deftest llm-mini-model-defaults-to-the-metabot-connections-mini-model-test+ (testing "with nothing stored, quick tasks run on the fastest model of the connection Metabot uses"+ (mt/with-temporary-raw-setting-values [llm-mini-model nil]+ (with-connections [configured-anthropic+ (connection "openai" "openai" {:api-key "sk-openai"})]+ (with-selected-model "anthropic/claude-sonnet-4-6"+ (is (= "anthropic/claude-haiku-4-5-20251001" (metabot.settings/llm-mini-model))))+ (testing "including a second connection of the same type, which keeps its own key"+ (with-selected-model "openai/gpt-5.4"+ (is (= "openai/gpt-5.4-mini" (metabot.settings/llm-mini-model)))))))))++(deftest llm-mini-model-falls-back-to-the-metabot-model-test+ (mt/with-temporary-raw-setting-values [llm-mini-model nil]+ (testing "provider types with no mini model fall through to the model Metabot itself uses"+ (with-connections [(connection "azure" "azure" {:api-key "azure-key"+ :base-url "https://my-resource.services.ai.azure.com/openai"})]+ (with-selected-model "azure/openai/my-gpt-deployment"+ (is (= "azure/openai/my-gpt-deployment" (metabot.settings/llm-mini-model))))))+ (testing "so does a model reference naming a connection that does not exist"+ (with-connections []+ (with-selected-model "gone/some-model"+ (is (= "gone/some-model" (metabot.settings/llm-mini-model))))))))++(deftest llm-mini-model-explicit-value-wins-test+ (with-connections [configured-anthropic]+ (with-selected-model "anthropic/claude-sonnet-4-6"+ (mt/with-temporary-setting-values [llm-mini-model "anthropic/claude-opus-4-8"]+ (is (= "anthropic/claude-opus-4-8" (metabot.settings/llm-mini-model))))+ (testing "and clearing it returns to the derived mini model"+ (mt/with-temporary-setting-values [llm-mini-model nil]+ (is (= "anthropic/claude-haiku-4-5-20251001" (metabot.settings/llm-mini-model))))))))++(deftest explicit-mini-model-reports-only-what-was-set-test+ (testing "the explicit reading is nil while the model is derived, so callers can tell a choice from a fallback"+ (with-connections [configured-anthropic]+ (with-selected-model "anthropic/claude-sonnet-4-6"+ (mt/with-temporary-setting-values [llm-mini-model nil]+ (is (nil? (metabot.settings/explicit-mini-model)))+ (is (= "anthropic/claude-haiku-4-5-20251001" (metabot.settings/llm-mini-model))))+ (mt/with-temporary-setting-values [llm-mini-model "anthropic/claude-opus-4-8"]+ (is (= "anthropic/claude-opus-4-8" (metabot.settings/explicit-mini-model))))))))++(deftest llm-mini-model-is-validated-like-the-metabot-model-test+ (with-connections [configured-anthropic+ (connection "azure" "azure" {:api-key "azure-key"+ :base-url "https://my-resource.services.ai.azure.com/openai"})]+ (testing "rejects a reference with no model"+ (is (thrown-with-msg?+ clojure.lang.ExceptionInfo #"Model name is required"+ (metabot.settings/llm-mini-model! "anthropic"))))+ (testing "applies the azure deployment-name rules"+ (is (thrown-with-msg?+ clojure.lang.ExceptionInfo #"Invalid Azure model"+ (metabot.settings/llm-mini-model! "azure/gemini/some-deployment"))))))+(deftest ai-usage-max-retention-days-default-test(testing "defaults to 180 days when no env var is set"(mt/with-temp-env-var-value! [mb-ai-usage-max-retention-days nil]