Skip to content

Commit

Permalink
Only pull if image is not already present
Browse files Browse the repository at this point in the history
  • Loading branch information
slimslenderslacks committed Nov 12, 2024
1 parent b88a4d1 commit 7025618
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
16 changes: 14 additions & 2 deletions src/docker.clj
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,20 @@
{:creds {:username (:user m)
:password (or (:jwt m) (:pat m))}}))))

(defn has-image? [image]
(let [[_ digest] (re-find #".*@(.*)" image)]
(some
(fn [{:keys [RepoTags Id]}]
(or
(some #(= % image) RepoTags)
(and digest (= digest Id))))
(images {}))))

(defn run-function
"run container function with no stdin"
[{:keys [timeout] :or {timeout 600000} :as m}]
(-pull m)
(when (not (has-image? (:image m)))
(-pull m))
(let [x (create m)
finished-channel (async/promise-chan)]
(start x)
Expand Down Expand Up @@ -314,7 +324,8 @@
"")))

(defn function-call-with-stdin [m]
(-pull m)
(when (not (has-image? (:image m)))
(-pull m))
(let [x (merge
m
(create (assoc m
Expand Down Expand Up @@ -392,6 +403,7 @@
(get-token {})
(get-login-info {})
(get-login-info-from-desktop-backend)
(images {})

(pprint
(json/parse-string
Expand Down
44 changes: 28 additions & 16 deletions src/graphs/sql.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
:command ["{{database}}" "{{query}}"]}}]})

(def first-tool-call
{:messages [{:content ""
:tool_calls [{:function {:name "sql_db_list_tables_tool"
{:messages [{:role "assistant"
:content ""
:tool_calls [{:type "function"
:function {:name "sql_db_list_tables_tool"
:arguments "{\"database\": \"./Chinook.db\"}"}
:id "tool_abc123"}]}]
:tools [{:type "function"
Expand All @@ -37,17 +39,17 @@
:command ["{{database}}" ".tables"]}}}]})

(def model-get-schema
{:messages []
:tools [{:name "sql_db_get_schema_tool"
:description "List all tables in the database"
:parameters
{:type "object"
:properties
{:database {:type "string" :description "the database to query"}
:table {:type "string" :description "the table to get the schema for"}}}
:container
{:image "vonwig/sqlite:latest"
:command ["{{database}}" ".schema {{table}}"]}}]})
{:tools [{:type "function"
:function {:name "sql_db_get_schema_tool"
:description "List all tables in the database"
:parameters
{:type "object"
:properties
{:database {:type "string" :description "the database to query"}
:table {:type "string" :description "the table to get the schema for"}}}
:container
{:image "vonwig/sqlite:latest"
:command ["{{database}}" ".schema {{table}}"]}}}]})

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

(defn seed-get-schema-conversation [state]
; inherit full conversation
; no prompts
; add the schema tool
(-> state
(update-in [:opts :level] (fnil inc 0))
(update-in [:opts :parameters] (constantly {:database "./Chinook.db"}))
(update-in [:functions] (fnil concat []) (:tools model-get-schema))))

(defn graph [_]
(-> {}
(graph/add-node "start" graph/start)
Expand All @@ -88,10 +99,11 @@
(graph/add-node "list-tables-tool" (graph/tool-node nil))
(graph/add-edge "list-tables-inject-tool" "list-tables-tool")

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

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

0 comments on commit 7025618

Please sign in to comment.