Skip to content

Commit

Permalink
Add unmerged changes from previous repo
Browse files Browse the repository at this point in the history
* complete the conversation loop when using prompts
  • Loading branch information
slimslenderslacks committed Jul 10, 2024
1 parent 76b41dc commit c4eb943
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ a GitHub ref. For example, to test some local prompts in a directory named `my_
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
--mount type=bind,source=$PWD,target=/app/my_prompts \
--workdir /app
--workdir /app \
vonwig/prompts:latest $PWD \
jimclark106 \
darwin \
Expand Down Expand Up @@ -61,7 +61,7 @@ docker run --rm \
-it \
-v /var/run/docker.sock:/var/run/docker.sock \
--mount type=bind,source=$PROMPTS_DIR,target=/app/my_prompts \
--workdir /app
--workdir /app \
--mount type=volume,source=docker-prompts,target=/prompts \
--mount type=bind,source=$HOME/.openai-api-key,target=/root/.openai-api-key \
vonwig/prompts:latest \
Expand Down
2 changes: 1 addition & 1 deletion prompts/dockerfiles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ functions:
- name: analyze_project
description: Analyze a project to determine how it should be built
type: prompt
ref: project_type
ref: github:docker/labs-ai-tools-for-devs?ref=main&path=prompts/project_type
- name: write_files
description: Write a set of files to my project
parameters:
Expand Down
25 changes: 19 additions & 6 deletions src/prompts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@
(into []))]
(map (comp merge-role renderer fs/file) prompts)))

(declare conversation-loop)

(defn function-handler
"call function
params
Expand Down Expand Up @@ -207,9 +209,17 @@
(resolve pty-output)
(fail (format "call exited with non-zero code (%d): %s" exit-code pty-output))))
(= "prompt" (:type definition)) ;; asynchronous call to another agent
(do
;; TODO use the assistant here
(resolve "This is an NPM project.")))
(let [{:keys [messages _finish-reason] :as m}
(async/<!! (conversation-loop
(:host-dir opts)
user
(:host-dir opts)
(:ref definition)))]
(jsonrpc/notify :message {:debug (with-out-str (pprint m))})
(resolve (->> messages
(filter #(= "assistant" (:role %)))
(last)
:content))))
(catch Throwable t
(fail (format "system failure %s" t))))
(fail "no function found")))
Expand Down Expand Up @@ -240,14 +250,15 @@
[& args]
(async/go-loop
[prompts (apply get-prompts args)]
(let [{:keys [messages finish-reason] :as m} (async/<!! (apply run-prompts prompts args))]
(let [{:keys [messages finish-reason] :as m}
(async/<!! (apply run-prompts prompts args))]
(if (= "tool_calls" finish-reason)
(do
(jsonrpc/notify :message {:debug (with-out-str (pprint m))})
(recur (concat prompts messages)))
(do
(jsonrpc/notify :message {:debug (with-out-str (pprint m))})
{:done finish-reason})))))
{:messages (concat prompts messages) :done finish-reason})))))

(defn- -run-command
[& args]
Expand Down Expand Up @@ -276,7 +287,9 @@
(update-in m [:prompts] (fn [coll] (remove (fn [{:keys [type]}] (= type (second args))) coll)))))

(= "run" (first args))
(async/<!! (apply conversation-loop (rest args)))
(select-keys
(async/<!! (apply conversation-loop (rest args)))
[:done])

:else
(apply get-prompts args)))
Expand Down

0 comments on commit c4eb943

Please sign in to comment.