Skip to content

Commit e68c0ae

Browse files
Refactor sql graph
1 parent 53e4e72 commit e68c0ae

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/graph.clj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
(ns graph
22
(:require
3-
[babashka.fs :as fs]
43
[clojure.core.async :as async]
54
[clojure.core.match :refer [match]]
5+
[clojure.pprint :as pprint]
66
git
77
jsonrpc
88
openai
@@ -155,7 +155,7 @@
155155
[state m
156156
node "start"]
157157
(jsonrpc/notify :message {:debug (format "\n-> entering %s\n\n" node)})
158-
#_(jsonrpc/notify :message {:debug (with-out-str (pprint (state/summarize (dissoc state :opts))))})
158+
(jsonrpc/notify :message {:debug (with-out-str (pprint/pprint (state/summarize (dissoc state :opts))))})
159159
;; TODO handling bad graphs with missing nodes
160160
(let [enter-node (get-in graph [:nodes node])
161161
new-state (state-reducer state (async/<! (enter-node state)))]
@@ -256,3 +256,6 @@
256256
[["tool" (tool-node {})]
257257
["end"]]])
258258

259+
(defn generate-start-with-tool [_]
260+
(construct-graph start-with-tool))
261+

src/graphs/sql.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@
114114
[[["start" graph/start]
115115
["list-tables-tool" (graph/sub-graph-node
116116
{:init-state seed-list-tables-conversation
117-
:construct-graph (fn [_] (graph/construct-graph graph/start-with-tool))
118-
:next-state state/take-last-two-messages})]
117+
:construct-graph graph/generate-start-with-tool
118+
:next-state (state/take-last-messages 2)})]
119119
["model-get-schema" (graph/sub-graph-node
120120
{:init-state seed-get-schema-conversation
121121
:next-state state/append-new-messages})]

src/state.clj

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns state
1+
(ns state
22
(:require
33
git
44
jsonrpc
@@ -22,10 +22,10 @@
2222

2323
(defn summarize [state]
2424
(-> state
25-
(update :messages (each
25+
(update :messages (each
2626
;summarize-content
2727
;summarize-tool-calls
28-
))))
28+
))))
2929

3030
(defn prompt? [m]
3131
(= "prompt" (-> m :function :type)))
@@ -75,7 +75,6 @@
7575
(update-in [:opts :prompts] (constantly (git/prompt-file (-> definition :function :ref))))
7676
(update-in [:opts :parameters] (constantly arg-context)))))
7777

78-
7978
(defn add-last-message-as-tool-call
8079
[state sub-graph-state]
8180
{:messages [(-> sub-graph-state
@@ -88,9 +87,11 @@
8887
{:messages (->> (:messages sub-graph-state)
8988
(filter (complement (fn [m] (some #(= m %) (:messages state))))))})
9089

91-
(defn take-last-two-messages
92-
[_ sub-graph-state]
93-
{:messages (->> (:messages sub-graph-state)
94-
(take-last 2))})
90+
(defn take-last-messages
91+
[n]
92+
(fn
93+
[_ sub-graph-state]
94+
{:messages (->> (:messages sub-graph-state)
95+
(take-last n))}))
9596

9697

0 commit comments

Comments
 (0)