|
20 | 20 | (update m :content (fn [c] (format "... %d characters ..." (count c))))) |
21 | 21 | (defn summarize-tool-calls [m] |
22 | 22 | (update-in m [:tool_calls] (each summarize-arguments))) |
| 23 | +(defn summarize-tool [m] |
| 24 | + (-> m :function :name)) |
23 | 25 |
|
24 | 26 | (defn summarize [state] |
25 | | - (-> state |
| 27 | + (-> (select-keys state [:messages :functions]) |
26 | 28 | (update :messages (each |
27 | 29 | ;summarize-content |
28 | 30 | ;summarize-tool-calls |
29 | | - )))) |
| 31 | + )) |
| 32 | + (update :functions (each summarize-tool)))) |
30 | 33 |
|
31 | 34 | (defn prompt? [m] |
32 | 35 | (= "prompt" (-> m :function :type))) |
|
48 | 51 |
|
49 | 52 | (defn add-tool-call-id [m id] (assoc m :role "tool" :tool_call_id id)) |
50 | 53 |
|
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}] |
56 | 55 | (try |
57 | 56 | (-> state |
58 | 57 | (merge |
|
70 | 69 | (format "failure for prompt configuration:\n %s" (with-out-str (pprint (dissoc opts :pat :jwt)))) |
71 | 70 | :exception (str ex)})))) |
72 | 71 |
|
| 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 | + |
73 | 86 | (defn tools-append [tools] |
74 | 87 | (fn [_ state] |
75 | 88 | (-> state |
|
109 | 122 | (update-in [:messages] (fnil concat []) (:messages orig))))) |
110 | 123 |
|
111 | 124 | (defn messages-from-prompt [s] |
112 | | - (fn [orig state] |
| 125 | + (fn [_ state] |
113 | 126 | (-> state |
114 | 127 | (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)))) |
126 | 129 |
|
127 | 130 | ; ========================================================= |
128 | 131 | ; produce the diffs that should be applied to the next state |
|
0 commit comments