|
159 | 159 | function-name - the name of the function that the LLM has selected
|
160 | 160 | json-arg-string - the JSON arg string that the LLM has generated
|
161 | 161 | resolve fail - callbacks"
|
162 |
| - [{:keys [functions user pat] :as opts} function-name json-arg-string {:keys [resolve fail]}] |
| 162 | + [{:keys [functions user pat thread-volume save-thread-volume] :as opts} function-name json-arg-string {:keys [resolve fail]}] |
163 | 163 | (if-let [definition (->
|
164 | 164 | (->> (filter #(= function-name (-> % :function :name)) functions)
|
165 | 165 | first)
|
|
175 | 175 | (if json-arg-string [json-arg-string] ["{}"])
|
176 | 176 | (when-let [c (-> definition :container :command)] c))}
|
177 | 177 | (when user {:user user})
|
178 |
| - (when pat {:pat pat})) |
| 178 | + (when pat {:pat pat}) |
| 179 | + (when thread-volume {:thread-volume thread-volume}) |
| 180 | + (when (true? save-thread-volume) {:save-thread-volume true})) |
179 | 181 | {:keys [pty-output exit-code]} (docker/run-function function-call)]
|
180 | 182 | (if (= 0 exit-code)
|
181 | 183 | (resolve pty-output)
|
|
206 | 208 | args for extracting functions, host-dir, user, platform
|
207 | 209 | returns channel that will contain the final set of messages and a finish-reason"
|
208 | 210 | [prompts & args]
|
209 |
| - (let [[host-dir user platform prompts-dir & {:keys [url pat]}] args |
| 211 | + (let [[host-dir user platform prompts-dir & {:keys [url pat save-thread-volume thread-id]}] args |
210 | 212 | prompt-dir (get-dir prompts-dir)
|
211 | 213 | m (collect-metadata prompt-dir)
|
212 | 214 | functions (collect-functions prompt-dir)
|
|
217 | 219 | :host-dir host-dir
|
218 | 220 | :user user
|
219 | 221 | :platform platform}
|
220 |
| - (when pat {:pat pat}))))] |
| 222 | + (when pat {:pat pat}) |
| 223 | + (when save-thread-volume {:save-thread-volume true}) |
| 224 | + (if thread-id |
| 225 | + {:thread-volume thread-id} |
| 226 | + {:thread-volume (str (random-uuid))}))))] |
221 | 227 | (try
|
222 | 228 | (openai/openai
|
223 | 229 | (merge
|
|
298 | 304 | [nil "--host-dir DIR" "Project directory"]
|
299 | 305 | [nil "--prompts DIR_OR_GITHUB_REF" "prompts"]
|
300 | 306 | [nil "--offline" "do not try to pull new images"]
|
301 |
| - [nil "--pretty-print-prompts" "pretty print prompts"]]) |
| 307 | + [nil "--pretty-print-prompts" "pretty print prompts"] |
| 308 | + [nil "--save-thread-volume" "save the thread volume for debugging"] |
| 309 | + [nil "--thread-id THREAD_ID" "use this thread-id for the next conversation"]]) |
302 | 310 |
|
303 | 311 | (defn- add-arg [options args k]
|
304 | 312 | (if-let [v (k options)] (concat args [k v]) args))
|
305 | 313 |
|
306 |
| -(def output-handler (fn [x] (println (json/generate-string x)))) |
| 314 | +(def output-handler (fn [x] (jsonrpc/notify {:message {:content (json/generate-string x)}}))) |
307 | 315 | (defn output-prompts [coll]
|
308 |
| - (println "## Prompts:\n") |
| 316 | + (jsonrpc/notify {:message {:content "## Prompts:\n"}}) |
309 | 317 | (->> coll
|
310 | 318 | (mapcat (fn [{:keys [role content]}]
|
311 | 319 | [(format "## %s\n" role)
|
312 | 320 | content]))
|
313 | 321 | (interpose "\n")
|
314 | 322 | (apply str)
|
315 |
| - (println))) |
| 323 | + ((fn [s] (jsonrpc/notify {:message {:content s}}))))) |
316 | 324 |
|
317 | 325 | (defn -main [& args]
|
318 | 326 | (try
|
|
328 | 336 | (apply -run-command (concat
|
329 | 337 | arguments
|
330 | 338 | (reduce (partial add-arg options) [] [:url :pat :host-dir :prompts])
|
331 |
| - (when (:offline options) [:offline true]))))) |
| 339 | + (when (:offline options) [:offline true]) |
| 340 | + (when (:save-thread-volume options) [:save-thread-volume true]))))) |
332 | 341 | (catch Throwable t
|
333 | 342 | (warn "Error: {{ exception }}" {:exception t})
|
334 | 343 | (System/exit 1))))
|
|
0 commit comments