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
BOT-1033: Add box plot support to the metabot chart tools (#81198)
Andrei Simionescu58ad1ba5648f
diff --git a/src/metabase/metabot/tools/charts.clj b/src/metabase/metabot/tools/charts.cljindex 0c307b922cc..432db464425 100644--- a/src/metabase/metabot/tools/charts.clj+++ b/src/metabase/metabot/tools/charts.clj@@ -22,9 +22,7 @@"<instructions>\n" (instructions/chart-created-instructions chart-id) "\n</instructions>")))(def ^:private chart-type-enum- [:enum "table" "bar" "line" "pie" "sunburst" "treemap" "area" "combo"- "row" "pivot" "scatter" "waterfall" "sankey" "scalar"- "smartscalar" "gauge" "progress" "funnel" "object" "map"])+ (into [:enum] shared/chart-types))(def ^:private create-chart-schema[:map {:closed true}diff --git a/src/metabase/metabot/tools/charts/create.clj b/src/metabase/metabot/tools/charts/create.cljindex 4c2da2fbf4c..4f6917c43f5 100644--- a/src/metabase/metabot/tools/charts/create.clj+++ b/src/metabase/metabot/tools/charts/create.clj@@ -3,15 +3,14 @@(:require[clojure.string :as str][metabase.metabot.agent.links :as links]+ [metabase.metabot.tools.shared :as shared][metabase.util.log :as log]))(set! *warn-on-reflection* true)(def ^:private valid-chart-types"Valid chart types supported by Metabase."- #{:table :bar :line :pie :sunburst :treemap :area :combo :row :pivot- :scatter :waterfall :sankey :scalar :smartscalar :gauge- :progress :funnel :object :map})+ (into #{} (map keyword) shared/chart-types))(defn- format-chart-for-llm"Format chart data as XML for LLM consumption."diff --git a/src/metabase/metabot/tools/charts/edit.clj b/src/metabase/metabot/tools/charts/edit.cljindex 2c9fdfd58fc..31c51bbb56f 100644--- a/src/metabase/metabot/tools/charts/edit.clj+++ b/src/metabase/metabot/tools/charts/edit.clj@@ -1,13 +1,12 @@(ns metabase.metabot.tools.charts.edit"Tool for editing chart visualization settings."(:require+ [metabase.metabot.tools.shared :as shared][metabase.util.log :as log]))(def ^:private valid-chart-types"Valid chart types supported by Metabase."- #{:table :bar :line :pie :sunburst :treemap :area :combo :row :pivot- :scatter :waterfall :sankey :scalar :smartscalar :gauge- :progress :funnel :object :map})+ (into #{} (map keyword) shared/chart-types))(defn- format-chart-link"Format a metabase:// link to the chart."diff --git a/src/metabase/metabot/tools/document.clj b/src/metabase/metabot/tools/document.cljindex 6fe02969bea..d313a86c70a 100644--- a/src/metabase/metabot/tools/document.clj+++ b/src/metabase/metabot/tools/document.clj@@ -16,9 +16,7 @@(set! *warn-on-reflection* true)(def ^:private chart-type-enum- [:enum "table" "bar" "line" "pie" "sunburst" "area" "combo"- "row" "pivot" "scatter" "waterfall" "sankey" "scalar"- "smartscalar" "gauge" "progress" "funnel" "object" "map"])+ (into [:enum] shared/chart-types))(defn- parse-reference[[k v]]diff --git a/src/metabase/metabot/tools/shared.clj b/src/metabase/metabot/tools/shared.cljindex 0a28d7fb52b..2da651b9f71 100644--- a/src/metabase/metabot/tools/shared.clj+++ b/src/metabase/metabot/tools/shared.clj@@ -5,6 +5,14 @@(set! *warn-on-reflection* true)+(def chart-types+ "Display types the chart tools can produce, as model-facing strings. The main+ and document chart tool enums derive from this list; the Slackbot query tool+ has its own smaller enum."+ ["table" "bar" "line" "pie" "sunburst" "treemap" "boxplot" "area" "combo"+ "row" "pivot" "scatter" "waterfall" "sankey" "scalar"+ "smartscalar" "gauge" "progress" "funnel" "object" "map"])+(def ^:dynamic *memory-atom*"Dynamic memory atom bound for tools that need access to agent state."nil)diff --git a/test/metabase/metabot/tools/charts/create_test.clj b/test/metabase/metabot/tools/charts/create_test.cljindex 18696f7c1df..545f3b2c596 100644--- a/test/metabase/metabot/tools/charts/create_test.clj+++ b/test/metabase/metabot/tools/charts/create_test.clj@@ -30,7 +30,7 @@(let [queries-state {"q-456" {:query-id "q-456":sql "SELECT COUNT(*) FROM users":database 1}}]- (doseq [chart-type [:line :pie :table :scatter :area :treemap]]+ (doseq [chart-type [:line :pie :table :scatter :area :treemap :boxplot]](let [result (create-chart/create-chart{:query-id "q-456":chart-type chart-typediff --git a/test/metabase/metabot/tools/charts/edit_test.clj b/test/metabase/metabot/tools/charts/edit_test.cljindex 54e5a885f7a..bc67cb54fd7 100644--- a/test/metabase/metabot/tools/charts/edit_test.clj+++ b/test/metabase/metabot/tools/charts/edit_test.clj@@ -40,7 +40,7 @@(let [mp (mt/metadata-provider)charts-state {"chart-456" {:chart-id "chart-456":queries [(lib/native-query mp "SELECT * FROM orders")]}}]- (doseq [new-type [:pie :table :scatter :area :sunburst :treemap]]+ (doseq [new-type [:pie :table :scatter :area :sunburst :treemap :boxplot]](let [{:keys [result]} (edit-chart/edit-chart{:chart-id "chart-456":new-chart-type new-typediff --git a/test/metabase/metabot/tools/charts_test.clj b/test/metabase/metabot/tools/charts_test.cljindex 2ece1caf66a..f5050dc27aa 100644--- a/test/metabase/metabot/tools/charts_test.clj+++ b/test/metabase/metabot/tools/charts_test.clj@@ -42,11 +42,12 @@(testing "keeps the query in structured-output so chart memory stores it for later edits"(is (= stub-query (get-in result [:structured-output :query])))))))-(deftest create-chart-treemap-test- (testing "the tool schema accepts treemap as a chart type"- (let [result (run-create-chart "treemap")]- (is (= :treemap (get-in result [:structured-output :chart-type])))- (is (= "treemap" (get-in result [:data-parts 0 :data :display]))))))+(deftest create-chart-new-chart-types-test+ (testing "the tool schema accepts newly added chart types"+ (doseq [chart-type ["treemap" "boxplot"]]+ (let [result (run-create-chart chart-type)]+ (is (= (keyword chart-type) (get-in result [:structured-output :chart-type])))+ (is (= chart-type (get-in result [:data-parts 0 :data :display])))))))(deftest edit-chart-query-fallback-test(testing "edit_chart resolves the query from queries-state when chart memory has no query"diff --git a/test/metabase/metabot/tools/document_test.clj b/test/metabase/metabot/tools/document_test.cljindex 9f7ff96aa2e..a735b4f58aa 100644--- a/test/metabase/metabot/tools/document_test.clj+++ b/test/metabase/metabot/tools/document_test.clj@@ -143,3 +143,20 @@(is (= {:database 1:type "query"}(:dataset_query structured)))))))++(deftest document-construct-model-chart-new-chart-types-test+ (testing "the tool schema accepts newly added chart types"+ (mt/with-dynamic-fn-redefs [construct-tools/construct-notebook-query-tool+ (fn [_]+ {:structured-output {:query-id "3"+ :query {:database 1+ :type "query"}}})]+ (doseq [chart-type ["treemap" "boxplot"]]+ (let [result (document-tools/document-construct-model-chart-tool+ {:name "Test Name"+ :description "Test Desc"+ :query ""+ :viz_settings {:chart_type chart-type}})+ structured (:structured-output result)]+ (is (= chart-type (:display structured)))+ (is (= chart-type (:chart_type structured))))))))