Skip to content

Commit 7ac03a7

Browse files
Add a user notification method to jsonrpc
* this will output the system and user prompts
1 parent 7dcda3f commit 7ac03a7

File tree

8 files changed

+47
-11
lines changed

8 files changed

+47
-11
lines changed

functions/docker_scout_tag_recommendation/init.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
(try
2020
(let [repository (:repository (json/parse-string (second args) true))]
2121
(println
22-
((comp recommendation-response recommendation-request) repository)))
22+
#_((comp recommendation-response recommendation-request) repository)
23+
"22-slim"))
2324
(catch Throwable t
2425
(binding [*out* *err*]
2526
(println t))

functions/hub/curl/init.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
(let [[json-string & args] *command-line-args*
88
{llm-args :args} (cheshire.core/parse-string json-string true)]
99
(println
10-
(-> (apply babashka.process/process
11-
{:out :string}
12-
"curl" args)
10+
(-> (babashka.process/process
11+
{:out :string}
12+
(str "curl " llm-args))
1313
(deref)
1414
(babashka.process/check)
1515
:out)))

functions/hub/curl/runbook.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ docker run --rm \
1313
--mount type=bind,source=$PWD,target=/project \
1414
--entrypoint /app/result/bin/entrypoint \
1515
--workdir /project \
16-
vonwig/curl:latest '{}'
16+
vonwig/curl:latest '{"args": "--help"}'
1717
```
1818

1919
## Build
2020

2121
```sh
22-
docker build -t vonwig/fasttext:latest .
22+
docker build -t vonwig/curl:latest .
2323
```
2424

2525
```sh
@@ -28,8 +28,8 @@ docker build -t vonwig/fasttext:latest .
2828
docker buildx build \
2929
--builder hydrobuild \
3030
--platform linux/amd64,linux/arm64 \
31-
--tag vonwig/fasttext:latest \
31+
--tag vonwig/curl:latest \
3232
--file Dockerfile \
3333
--push .
34-
docker pull vonwig/fasttext:latest
34+
docker pull vonwig/curl:latest
3535
```

prompts/curl/100_user_prompts.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Run the curl command to fetch https://www.example.com
2+
3+
If you get an error, run `curl --help` and use the output to try again.

prompts/curl/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
extractors:
33
- name: linguist
4-
- name: docker-lsp
4+
- name: project-facts
55
model: gpt-4
66
stream: true
77
functions:

runbook.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,26 @@ docker run --rm \
161161
--thread-id "something" \
162162
--save-thread-volume
163163
```
164+
165+
# Test bad commands
166+
167+
1. remove the openai key
168+
2. break the url with the --url flag
169+
3. choose a bad prompts dir
170+
171+
```sh
172+
docker run --rm \
173+
-it \
174+
-v /var/run/docker.sock:/var/run/docker.sock \
175+
--mount type=volume,source=docker-prompts,target=/prompts \
176+
--mount type=bind,source=$PWD,target=/app/local \
177+
--mount type=bind,source=$HOME/.openai-api-key,target=/root/.openai-api-key \
178+
--workdir /app \
179+
vonwig/prompts:local \
180+
run \
181+
--host-dir $PWD \
182+
--user $USER \
183+
--platform "$(uname -o)" \
184+
--prompts-dir local/prompts/poem \
185+
```
186+

src/jsonrpc.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@
2323
:method method
2424
:params params})
2525

26+
;; message({:debug ""}) - debug messages are often serialized edn but still meant to be streamed
27+
;; message({:content ""}) - meant to be streamed
28+
;; prompts({:messages [{:role "", :content ""}]})
29+
;; functions("") - meant to be updated in place
30+
;; functions-done("")
2631
(defn -notify [{:keys [debug]} method params]
2732
(case method
2833
:message (write-message (io/output-stream System/out) (notification method params))
34+
:prompts (write-message (io/output-stream System/out) (notification method params))
2935
:functions (write-message (io/output-stream System/out) (notification method params))
3036
:functions-done (write-message (io/output-stream System/out) (notification method params))))
3137

@@ -36,7 +42,8 @@
3642
(:content params) (do (print (:content params)) (flush))
3743
(and debug (:debug params)) (do (println "### DEBUG\n") (println (:debug params))))
3844
:functions (do (print ".") (flush))
39-
:functions-done (println params)))
45+
:functions-done (println params)
46+
:prompts nil))
4047

4148
(def ^:dynamic notify -notify)
4249

src/prompts.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@
231231
;; get-prompts can only use extractors - we can't refine
232232
;; them based on output from function calls that the LLM plans
233233
(let [prompts (if (not (seq thread))
234-
(get-prompts opts)
234+
(let [new-prompts (get-prompts opts)]
235+
(jsonrpc/notify :prompts {:messages new-prompts})
236+
new-prompts)
235237
thread)
236238
{:keys [messages finish-reason] :as m}
237239
(async/<!! (run-prompts prompts opts))]

0 commit comments

Comments
 (0)