Skip to content

Commit 55634ff

Browse files
Improve error handling
1 parent f2aa11f commit 55634ff

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/openai.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
(slurp (:body response))))
4444
(doseq [chunk (line-seq (io/reader (:body response)))]
4545
(cb chunk)))
46-
(throw (ex-info "Failed to call OpenAI API" {:body (slurp (:body response))})))))
46+
(throw (ex-info "Failed to call OpenAI API" {:body (if (string? (:body response))
47+
(:body response)
48+
(slurp (:body response)))})))))
4749

4850
(defn call-function
4951
" returns channel that will emit one message and then close"

src/prompts.clj

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
:entrypoint "/app/result/bin/docker-lsp"
9696
:command ["project-facts"
9797
"--vs-machine-id" "none"
98-
"--workspace" "/docker"]}])))
98+
"--workspace" "/project"]}])))
9999

100100
(defn collect-functions [dir]
101101
(->>
@@ -268,6 +268,7 @@
268268
:validate [#(#{"darwin" "linux" "windows"} (string/lower-case %)) "valid platforms are Darwin|Linux|Windows"]]
269269
[nil "--prompts-dir DIR_PATH" "path to local prompts directory"
270270
:id :prompts-dir
271+
:validate [#(fs/exists? (fs/file %)) "prompts dir does not a valid directory"]
271272
:parse-fn #(fs/file %)]
272273
[nil "--prompts REF" "git ref to remote prompts directory"
273274
:id :prompts-dir
@@ -292,7 +293,10 @@
292293
[nil "--debug" "add debug logging"]
293294
[nil "--help" "print option summary"]])
294295

295-
(def output-handler (fn [x] (jsonrpc/notify :message {:content (json/generate-string x)})))
296+
(def output-handler (fn [x]
297+
(jsonrpc/notify :message {:content (json/generate-string (if (= "error" (:done x))
298+
(update x :messages last)
299+
(select-keys x [:done])))})))
296300
(defn output-prompts [coll]
297301
(->> coll
298302
(mapcat (fn [{:keys [role content]}]
@@ -356,13 +360,11 @@
356360
"run" (fn []
357361
(with-volume
358362
(fn [thread-id]
359-
(select-keys
360-
(async/<!! ((comp conversation-loop (validate ::run-args))
361-
(-> opts
362-
(assoc :thread-id thread-id)
363-
((fn [opts] (apply merge-deprecated opts (rest args)))))))
363+
(async/<!! ((comp conversation-loop (validate ::run-args))
364+
(-> opts
365+
(assoc :thread-id thread-id)
366+
((fn [opts] (apply merge-deprecated opts (rest args))))))))
364367

365-
[:done]))
366368
opts))
367369
(fn []
368370
((comp get-prompts (validate ::run-args)) (apply merge-deprecated opts args)))))

0 commit comments

Comments
 (0)