Skip to content

Commit 7025618

Browse files
Only pull if image is not already present
1 parent b88a4d1 commit 7025618

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

src/docker.clj

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,20 @@
249249
{:creds {:username (:user m)
250250
:password (or (:jwt m) (:pat m))}}))))
251251

252+
(defn has-image? [image]
253+
(let [[_ digest] (re-find #".*@(.*)" image)]
254+
(some
255+
(fn [{:keys [RepoTags Id]}]
256+
(or
257+
(some #(= % image) RepoTags)
258+
(and digest (= digest Id))))
259+
(images {}))))
260+
252261
(defn run-function
253262
"run container function with no stdin"
254263
[{:keys [timeout] :or {timeout 600000} :as m}]
255-
(-pull m)
264+
(when (not (has-image? (:image m)))
265+
(-pull m))
256266
(let [x (create m)
257267
finished-channel (async/promise-chan)]
258268
(start x)
@@ -314,7 +324,8 @@
314324
"")))
315325

316326
(defn function-call-with-stdin [m]
317-
(-pull m)
327+
(when (not (has-image? (:image m)))
328+
(-pull m))
318329
(let [x (merge
319330
m
320331
(create (assoc m
@@ -392,6 +403,7 @@
392403
(get-token {})
393404
(get-login-info {})
394405
(get-login-info-from-desktop-backend)
406+
(images {})
395407

396408
(pprint
397409
(json/parse-string

src/graphs/sql.clj

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
:command ["{{database}}" "{{query}}"]}}]})
2222

2323
(def first-tool-call
24-
{:messages [{:content ""
25-
:tool_calls [{:function {:name "sql_db_list_tables_tool"
24+
{:messages [{:role "assistant"
25+
:content ""
26+
:tool_calls [{:type "function"
27+
:function {:name "sql_db_list_tables_tool"
2628
:arguments "{\"database\": \"./Chinook.db\"}"}
2729
:id "tool_abc123"}]}]
2830
:tools [{:type "function"
@@ -37,17 +39,17 @@
3739
:command ["{{database}}" ".tables"]}}}]})
3840

3941
(def model-get-schema
40-
{:messages []
41-
:tools [{:name "sql_db_get_schema_tool"
42-
:description "List all tables in the database"
43-
:parameters
44-
{:type "object"
45-
:properties
46-
{:database {:type "string" :description "the database to query"}
47-
:table {:type "string" :description "the table to get the schema for"}}}
48-
:container
49-
{:image "vonwig/sqlite:latest"
50-
:command ["{{database}}" ".schema {{table}}"]}}]})
42+
{:tools [{:type "function"
43+
:function {:name "sql_db_get_schema_tool"
44+
:description "List all tables in the database"
45+
:parameters
46+
{:type "object"
47+
:properties
48+
{:database {:type "string" :description "the database to query"}
49+
:table {:type "string" :description "the table to get the schema for"}}}
50+
:container
51+
{:image "vonwig/sqlite:latest"
52+
:command ["{{database}}" ".schema {{table}}"]}}}]})
5153

5254
(defn list-tables-inject-tool [_]
5355
(async/go
@@ -79,6 +81,15 @@
7981
(string/starts-with? last-message "Error:") "query-gen"
8082
:else "correct-query")))
8183

84+
(defn seed-get-schema-conversation [state]
85+
; inherit full conversation
86+
; no prompts
87+
; add the schema tool
88+
(-> state
89+
(update-in [:opts :level] (fnil inc 0))
90+
(update-in [:opts :parameters] (constantly {:database "./Chinook.db"}))
91+
(update-in [:functions] (fnil concat []) (:tools model-get-schema))))
92+
8293
(defn graph [_]
8394
(-> {}
8495
(graph/add-node "start" graph/start)
@@ -88,10 +99,11 @@
8899
(graph/add-node "list-tables-tool" (graph/tool-node nil))
89100
(graph/add-edge "list-tables-inject-tool" "list-tables-tool")
90101

91-
(graph/add-node "end" graph/end)
92-
(graph/add-edge "list-tables-tool" "end")
102+
(graph/add-node "model-get-schema" (graph/sub-graph-node {:init-state seed-get-schema-conversation})) ; assistant
103+
(graph/add-edge "list-tables-tool" "model-get-schema")
93104

94-
;(graph/add-node "model-get-schema" (graph/sub-graph-node model-get-schema)) ; assistant
105+
(graph/add-node "end" graph/end)
106+
(graph/add-edge "model-get-schema" "end")
95107
;(graph/add-node "query-gen" query-gen) ; assistant - might just end if it generates the right response
96108
;; - might just loop back to query-gen if there's an error
97109
;; - otherwise switch to correct-query

0 commit comments

Comments
 (0)