Skip to content
Snippets Groups Projects
Unverified Commit 8dc7f17f authored by Mark Bastian's avatar Mark Bastian Committed by GitHub
Browse files

Update default Metabot model (#38491)

* Update default Metabot model

The default GPT-based Metabot model has been `"gpt-4"`. This model is no longer state of the art, has a limit of 8,192 tokens, and is priced at input: $0.03/ktoken and output: $0.06/ktoken.

`"gpt-4-turbo-preview"`, which points internally to `"gpt-4-0125-preview"` is the current state of the art, has a limit of 128,000 tokens, and is priced at input: $0.01/ktoken and output: $0.03/ktoken.

This should solve any issues of reasonable cases of token limit failures (e.g. [Metabot 2.0 failing when context length exceeded](https://github.com/metabase/metabase/issues/29932)) without needing to do any extra handling on the backend.

For more info on the models, token limits, and pricing, see:
- [OpenAI model docs](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo)
- [OpenAI pricing](https://openai.com/pricing)

* whitespace

* Removing irrelevant settings test
parent 2d4ea257
No related branches found
No related tags found
No related merge requests found
......@@ -2,15 +2,14 @@
(:require
[clojure.core.memoize :as memoize]
[metabase.models.setting :as setting :refer [defsetting]]
[metabase.util :as u]
[metabase.util.i18n :refer [deferred-tru]]
[metabase.util.log :as log]
[wkok.openai-clojure.api :as openai.api]))
(defsetting openai-model
(deferred-tru "The OpenAI Model (e.g. 'gpt-4', 'gpt-3.5-turbo')")
(deferred-tru "The OpenAI Model (e.g. 'gpt-4-turbo-preview', 'gpt-4', 'gpt-3.5-turbo')")
:visibility :settings-manager
:default "gpt-4")
:default "gpt-4-turbo-preview")
(defsetting openai-api-key
(deferred-tru "The OpenAI API Key.")
......@@ -52,29 +51,11 @@
(defn- select-models
"Downselect the available openai models to only the latest version of each GPT family."
[models]
(->> models
(map (fn [{:keys [id] :as m}]
(when-some [[_ v r] (re-matches #"gpt-([\d\.]+)(.*)"
(u/lower-case-en id))]
(let [version (parse-double v)]
(assoc m
:version version
:version-string v
:generation (int version)
:details r)))))
;; Drop anything that doesn't match
(filter identity)
;; Order by generation (asc), version (desc),
;; length of details string (asc), length of version string (desc)
(sort-by (juxt :generation
(comp - :version)
(comp count :details)
(comp - count :version-string)))
;; Split out each generation
(partition-by :generation)
;; Take the top item in each partition and select what we want
(map (comp #(select-keys % [:id :owned_by]) first))
reverse))
(let [selectable-models ["gpt-4-turbo-preview"
"gpt-4"
"gpt-3.5-turbo"]
available-models (zipmap (map :id models) (map #(select-keys % [:id :owned_by]) models))]
(keep available-models selectable-models)))
(def ^:private memoized-fetch-openai-models
(memoize/ttl
......
(ns metabase.metabot.settings-test
(:require
[clojure.test :refer :all]
[metabase.metabot.settings :as metabot-settings]))
(deftest ^:parallel select-models-test
(testing "Ensure we are downselecting to the right models."
(let [wierd-models (shuffle
[{:id "froob" :owned_by "openai"}
{:id "froob-32" :owned_by "openai"}
{:id "gpt-3.5-turbo" :owned_by "openai"}
{:id "gpt-3.5-turbo-0301" :owned_by "openai"}
{:id "gpt-4" :owned_by "openai"}
{:id "GPT-4.1" :owned_by "openai"}
{:id "gpt-4.0" :owned_by "openai"}
{:id "gpt-4.55" :owned_by "openai"}
{:id "gpt-4-0314" :owned_by "openai"}
{:id "gpt-5" :owned_by "openai"}
{:id "gpt-5.0" :owned_by "openai"}])]
(is (= [{:id "gpt-5.0" :owned_by "openai"}
{:id "gpt-4.55" :owned_by "openai"}
{:id "gpt-3.5-turbo" :owned_by "openai"}]
(#'metabot-settings/select-models wierd-models))))
(let [realistic-models (shuffle
[{:id "gpt-3.5-turbo" :owned_by "openai"}
{:id "gpt-3.5-turbo-0301" :owned_by "openai"}
{:id "gpt-4" :owned_by "openai"}
{:id "gpt-4-0314" :owned_by "openai"}])]
(is (= [{:id "gpt-4" :owned_by "openai"}
{:id "gpt-3.5-turbo" :owned_by "openai"}]
(#'metabot-settings/select-models realistic-models)))))
(testing "Select 'baseline' versions over checkpoints."
(let [version-string-case (shuffle
[{:id "gpt-4" :owned_by "openai"}
{:id "gpt-4-0101" :owned_by "openai"}])]
(is (= [{:id "gpt-4" :owned_by "openai"}]
(#'metabot-settings/select-models version-string-case)))))
(testing "Choose higher numbered versions over lower ones."
(let [version-string-case (shuffle
[{:id "gpt-4" :owned_by "openai"}
{:id "gpt-4.2" :owned_by "openai"}])]
(is (= [{:id "gpt-4.2" :owned_by "openai"}]
(#'metabot-settings/select-models version-string-case)))))
(testing "All other things being equal, choose the one with the longer version number."
(let [version-string-case (shuffle
[{:id "gpt-5" :owned_by "openai"}
{:id "gpt-5.0" :owned_by "openai"}])]
(is (= [{:id "gpt-5.0" :owned_by "openai"}]
(#'metabot-settings/select-models version-string-case))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment