Skip to content

Commit 0bb48d7

Browse files
Fixes issue with completely empty prompt files
* this will still create an empty prompts array and will make it to the openai api
1 parent 4467424 commit 0bb48d7

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/prompts.clj

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@
8484

8585
(defn collect-extractors [f]
8686
(let [extractors (->>
87-
(-> (markdown/parse-metadata (metadata-file f)) first :extractors)
87+
(-> (try
88+
(markdown/parse-metadata (metadata-file f))
89+
(catch Throwable _
90+
;; files with empty strings will throw assertion failures
91+
nil))
92+
first
93+
:extractors)
8894
(map (fn [m] (merge (registry/get-extractor m) m))))]
8995
(if (seq extractors)
9096
extractors
@@ -95,12 +101,12 @@
95101
"--vs-machine-id" "none"
96102
"--workspace" "/project"]}])))
97103

98-
(defn collect-functions
104+
(defn collect-functions
99105
"get either :functions or :tools collection
100106
returns collection of openai compatiable tool definitions augmented with container info"
101107
[f]
102108
(->>
103-
(-> (markdown/parse-metadata (metadata-file f)) first (select-keys [:tools :functions]) seq first second)
109+
(-> (markdown/parse-metadata (metadata-file f)) first (select-keys [:tools :functions]) seq first second)
104110
(mapcat (fn [m] (if-let [tool (#{"curl" "qrencode" "toilet" "figlet" "gh" "typos" "fzf" "jq" "fmpeg"} (:name m))]
105111
[{:type "function"
106112
:function
@@ -210,7 +216,7 @@
210216
(when pat {:pat pat})
211217
(when timeout {:timeout timeout}))
212218
{:keys [pty-output exit-code done] :as result} (docker/run-function function-call)]
213-
(cond
219+
(cond
214220
(and (= :exited done) (= 0 exit-code))
215221
(resolve pty-output)
216222
(and (= :exited done) (not= 0 exit-code))
@@ -298,6 +304,19 @@
298304
(async/>! c {:messages [] :done "error"})
299305
c))))
300306

307+
(comment
308+
;; for testing conversation-loop in repl
309+
(def x {:stream true,
310+
:host-dir "/Users/slim/docker/labs-make-runbook",
311+
:prompts "/Users/slim/docker/labs-ai-tools-for-devs/prompts/hub/default.md"
312+
:platform "darwin", :user "jimclark106",
313+
:thread-id "3e61ffe7-840e-4177-b84a-f6f7db58b24d"})
314+
(get-prompts x)
315+
(run-extractors x)
316+
(collect-extractors (:prompts x))
317+
(async/<!! (conversation-loop
318+
x)))
319+
301320
(defn- with-volume [f & {:keys [thread-id save-thread-volume]}]
302321
(let [thread-id (or thread-id (str (random-uuid)))]
303322
(try

0 commit comments

Comments
 (0)