Skip to content

Commit 5cfeee8

Browse files
Update debug json items
1 parent 4245fe6 commit 5cfeee8

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

src/docker/main.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@
178178
(user-loop/create-step
179179
(fn [state]
180180
(let [m (state/construct-initial-state-from-prompts
181-
state
182181
(assoc state :opts
183182
(-> (with-options opts (rest args))
184183
(assoc :thread-id thread-id))))]

src/graph.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
(into []
8383
(async/<!
8484
(->> (tools/make-tool-calls
85-
(-> state :opts :level)
85+
(or (-> state :opts :level) 0)
8686
(partial tools/function-handler (assoc (:opts state) :functions (:functions state)))
8787
calls)
8888
(async/reduce conj []))))})))
@@ -120,7 +120,7 @@
120120
(if (coll? init-state)
121121
(apply-functions init-state)
122122
init-state))
123-
(comp (partial state/construct-initial-state-from-prompts state) state/add-prompt-ref)) state)
123+
(comp state/construct-initial-state-from-prompts state/add-prompt-ref)) state)
124124
(update-in [:opts :level] (fnil inc 0)))))]
125125
((or next-state state/add-last-message-as-tool-call) state sub-graph-state)))))
126126

@@ -166,7 +166,7 @@
166166
[state m
167167
node "start"]
168168
(jsonrpc/notify :message {:debug (format "\n-> entering %s\n\n" node)})
169-
(jsonrpc/notify :message {:debug (with-out-str (pprint/pprint (state/summarize (dissoc state :opts))))})
169+
#_(jsonrpc/notify :message {:debug (with-out-str (pprint/pprint (state/summarize (dissoc state :opts))))})
170170
;; TODO handling bad graphs with missing nodes
171171
(let [enter-node (get-in graph [:nodes node])
172172
new-state (state-reducer state (async/<! (enter-node state)))]

src/graphs/sql.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777

7878
;; query-gen has a prompt
7979
;; seed-correct-query-conversation has a prompt
80-
;; prompts/sql/query-gen.md has a hard-coded db file
8180
(defn graph [_]
8281
(graph/construct-graph
8382
[[["start" graph/start]

src/state.clj

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@
2020
(update m :content (fn [c] (format "... %d characters ..." (count c)))))
2121
(defn summarize-tool-calls [m]
2222
(update-in m [:tool_calls] (each summarize-arguments)))
23+
(defn summarize-tool [m]
24+
(-> m :function :name))
2325

2426
(defn summarize [state]
25-
(-> state
27+
(-> (select-keys state [:messages :functions])
2628
(update :messages (each
2729
;summarize-content
2830
;summarize-tool-calls
29-
))))
31+
))
32+
(update :functions (each summarize-tool))))
3033

3134
(defn prompt? [m]
3235
(= "prompt" (-> m :function :type)))
@@ -48,11 +51,7 @@
4851

4952
(defn add-tool-call-id [m id] (assoc m :role "tool" :tool_call_id id))
5053

51-
; ========================================
52-
; operate on conversation state
53-
; ========================================
54-
55-
(defn construct-initial-state-from-prompts [_ {{:keys [prompts] :as opts} :opts :as state}]
54+
(defn construct-initial-state-from-prompts [{{:keys [prompts] :as opts} :opts :as state}]
5655
(try
5756
(-> state
5857
(merge
@@ -70,6 +69,20 @@
7069
(format "failure for prompt configuration:\n %s" (with-out-str (pprint (dissoc opts :pat :jwt))))
7170
:exception (str ex)}))))
7271

72+
(defn add-prompt-ref
73+
[state]
74+
(let [definition (state/get-function-definition state)
75+
arg-context (let [raw-args (-> state :messages last :tool_calls first :function :arguments)]
76+
(tools/arg-context raw-args))]
77+
(-> state
78+
(dissoc :messages)
79+
(update-in [:opts :prompts] (constantly (git/prompt-file (-> definition :function :ref))))
80+
(update-in [:opts :parameters] (constantly arg-context)))))
81+
82+
; ========================================
83+
; operate on conversation state
84+
; ========================================
85+
7386
(defn tools-append [tools]
7487
(fn [_ state]
7588
(-> state
@@ -109,20 +122,10 @@
109122
(update-in [:messages] (fnil concat []) (:messages orig)))))
110123

111124
(defn messages-from-prompt [s]
112-
(fn [orig state]
125+
(fn [_ state]
113126
(-> state
114127
(update-in [:opts :prompts] (constantly (fs/file s)))
115-
((partial construct-initial-state-from-prompts orig)))))
116-
117-
(defn add-prompt-ref
118-
[_ state]
119-
(let [definition (state/get-function-definition state)
120-
arg-context (let [raw-args (-> state :messages last :tool_calls first :function :arguments)]
121-
(tools/arg-context raw-args))]
122-
(-> state
123-
(dissoc :messages)
124-
(update-in [:opts :prompts] (constantly (git/prompt-file (-> definition :function :ref))))
125-
(update-in [:opts :parameters] (constantly arg-context)))))
128+
(construct-initial-state-from-prompts))))
126129

127130
; =========================================================
128131
; produce the diffs that should be applied to the next state

0 commit comments

Comments
 (0)