Skip to content

Commit

Permalink
Update debug json items
Browse files Browse the repository at this point in the history
  • Loading branch information
slimslenderslacks committed Nov 15, 2024
1 parent 4245fe6 commit 5cfeee8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
1 change: 0 additions & 1 deletion src/docker/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@
(user-loop/create-step
(fn [state]
(let [m (state/construct-initial-state-from-prompts
state
(assoc state :opts
(-> (with-options opts (rest args))
(assoc :thread-id thread-id))))]
Expand Down
6 changes: 3 additions & 3 deletions src/graph.clj
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
(into []
(async/<!
(->> (tools/make-tool-calls
(-> state :opts :level)
(or (-> state :opts :level) 0)
(partial tools/function-handler (assoc (:opts state) :functions (:functions state)))
calls)
(async/reduce conj []))))})))
Expand Down Expand Up @@ -120,7 +120,7 @@
(if (coll? init-state)
(apply-functions init-state)
init-state))
(comp (partial state/construct-initial-state-from-prompts state) state/add-prompt-ref)) state)
(comp state/construct-initial-state-from-prompts state/add-prompt-ref)) state)
(update-in [:opts :level] (fnil inc 0)))))]
((or next-state state/add-last-message-as-tool-call) state sub-graph-state)))))

Expand Down Expand Up @@ -166,7 +166,7 @@
[state m
node "start"]
(jsonrpc/notify :message {:debug (format "\n-> entering %s\n\n" node)})
(jsonrpc/notify :message {:debug (with-out-str (pprint/pprint (state/summarize (dissoc state :opts))))})
#_(jsonrpc/notify :message {:debug (with-out-str (pprint/pprint (state/summarize (dissoc state :opts))))})
;; TODO handling bad graphs with missing nodes
(let [enter-node (get-in graph [:nodes node])
new-state (state-reducer state (async/<! (enter-node state)))]
Expand Down
1 change: 0 additions & 1 deletion src/graphs/sql.clj
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@

;; query-gen has a prompt
;; seed-correct-query-conversation has a prompt
;; prompts/sql/query-gen.md has a hard-coded db file
(defn graph [_]
(graph/construct-graph
[[["start" graph/start]
Expand Down
41 changes: 22 additions & 19 deletions src/state.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
(update m :content (fn [c] (format "... %d characters ..." (count c)))))
(defn summarize-tool-calls [m]
(update-in m [:tool_calls] (each summarize-arguments)))
(defn summarize-tool [m]
(-> m :function :name))

(defn summarize [state]
(-> state
(-> (select-keys state [:messages :functions])
(update :messages (each
;summarize-content
;summarize-tool-calls
))))
))
(update :functions (each summarize-tool))))

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

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

; ========================================
; operate on conversation state
; ========================================

(defn construct-initial-state-from-prompts [_ {{:keys [prompts] :as opts} :opts :as state}]
(defn construct-initial-state-from-prompts [{{:keys [prompts] :as opts} :opts :as state}]
(try
(-> state
(merge
Expand All @@ -70,6 +69,20 @@
(format "failure for prompt configuration:\n %s" (with-out-str (pprint (dissoc opts :pat :jwt))))
:exception (str ex)}))))

(defn add-prompt-ref
[state]
(let [definition (state/get-function-definition state)
arg-context (let [raw-args (-> state :messages last :tool_calls first :function :arguments)]
(tools/arg-context raw-args))]
(-> state
(dissoc :messages)
(update-in [:opts :prompts] (constantly (git/prompt-file (-> definition :function :ref))))
(update-in [:opts :parameters] (constantly arg-context)))))

; ========================================
; operate on conversation state
; ========================================

(defn tools-append [tools]
(fn [_ state]
(-> state
Expand Down Expand Up @@ -109,20 +122,10 @@
(update-in [:messages] (fnil concat []) (:messages orig)))))

(defn messages-from-prompt [s]
(fn [orig state]
(fn [_ state]
(-> state
(update-in [:opts :prompts] (constantly (fs/file s)))
((partial construct-initial-state-from-prompts orig)))))

(defn add-prompt-ref
[_ state]
(let [definition (state/get-function-definition state)
arg-context (let [raw-args (-> state :messages last :tool_calls first :function :arguments)]
(tools/arg-context raw-args))]
(-> state
(dissoc :messages)
(update-in [:opts :prompts] (constantly (git/prompt-file (-> definition :function :ref))))
(update-in [:opts :parameters] (constantly arg-context)))))
(construct-initial-state-from-prompts))))

; =========================================================
; produce the diffs that should be applied to the next state
Expand Down

0 comments on commit 5cfeee8

Please sign in to comment.