Skip to content

Commit 70d0c60

Browse files
Support {{hostDir}}
1 parent def0e7f commit 70d0c60

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

prompts/examples/using-host-dir.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
tools:
3+
- name: ls
4+
description: list files in a directory
5+
container:
6+
image: alpine:latest
7+
command:
8+
- ls
9+
- /project
10+
- name: echo
11+
description: echo the current host dir
12+
container:
13+
image: vonwig/bash_alpine
14+
command:
15+
- -c
16+
- "echo {{hostDir}}"
17+
---
18+
19+
# Background
20+
21+
The `host-dir` for the prompt-engine run is mounted at `/project` in the container.
22+
So in the tool above, you'll see that the tool can only access your host-dir from this `/project` path.
23+
However, the tools can be passed the _value_ of the hostDir even if they can only access it via the `/project` mount.
24+
See the `echo` tool for an example of how this value becomes accessible (the `{{hostDir}}`
25+
can also be used directly in prompt templates.
26+
27+
# Prompt user
28+
29+
Start by listing the files in my host-dir and then run echo. Summarize by writing the output of the echo command and then
30+
write a poem using the file names from that directory.
31+

src/graph.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,19 +274,19 @@
274274
["tools-query" tools-query]
275275
["completion" completion]
276276
[:edge tool-or-end]]
277-
[["sub-graph" (sub-graph-node nil)]
277+
[["sub-graph" (sub-graph-node {})]
278278
["tools-query"]]
279-
[["tool" (tool-node nil)]
279+
[["tool" (tool-node {})]
280280
["tools-query"]]
281281
[["end" end]]])
282282

283283
(defn one-tool-call [_]
284284
(-> {}
285285
(add-node "start" start)
286286
(add-node "completion" completion)
287-
(add-node "tool" (tool-node nil))
287+
(add-node "tool" (tool-node {}))
288288
(add-node "end" end)
289-
(add-node "sub-graph" (sub-graph-node nil))
289+
(add-node "sub-graph" (sub-graph-node {}))
290290
(add-edge "start" "completion")
291291
(add-edge "sub-graph" "end")
292292
(add-edge "tool" "end")
@@ -296,9 +296,9 @@
296296
[[["start" start]
297297
["completion" completion]
298298
[:edge tool-or-end]]
299-
[["sub-graph" (sub-graph-node nil)]
299+
[["sub-graph" (sub-graph-node {})]
300300
["completion"]]
301-
[["tool" (tool-node nil)]
301+
[["tool" (tool-node {})]
302302
["completion"]]
303303
[["end" end]]])
304304

src/graphs/sql.clj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
; add the schema tool
9191
(-> state
9292
(update-in [:opts :level] (fnil inc 0))
93-
(update-in [:opts :parameters] (constantly {:database "./Chinook.db"}))
9493
(update-in [:functions] (fnil concat []) (:tools model-get-schema))))
9594

9695
(defn seed-correct-query-conversation
@@ -101,7 +100,6 @@
101100
(dissoc :messages)
102101
(update-in [:opts :level] (fnil inc 0))
103102
(update-in [:opts :prompts] (constantly (fs/file "prompts/sql/query-check.md")))
104-
(update-in [:opts :parameters] (constantly {:database "./Chinook.db"}))
105103
(graph/construct-initial-state-from-prompts)
106104
(update-in [:messages] concat [(last (:messages state))])))
107105

src/prompts.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222

2323
(defn- facts
2424
"fix up facts before sending to templates"
25-
[project-facts user platform]
25+
[project-facts user platform host-dir]
2626
(medley/deep-merge
2727
{:platform platform
2828
:username user
29+
:hostDir host-dir
2930
:project-facts {:files (-> project-facts :project-facts :project/files)
3031
:dockerfiles (-> project-facts :project-facts :project/dockerfiles)
3132
:composefiles (-> project-facts :project-facts :project/composefiles)
@@ -187,10 +188,10 @@
187188
(defn get-prompts
188189
"run extractors and then render prompt templates
189190
returns ordered collection of chat messages"
190-
[{:keys [parameters prompts user platform] :as opts}]
191+
[{:keys [parameters prompts user platform host-dir] :as opts}]
191192
(let [;; TODO the docker default no longer makes sense here
192193
m (merge (run-extractors opts) parameters)
193-
renderer (partial selma-render prompts (facts m user platform))
194+
renderer (partial selma-render prompts (facts m user platform host-dir))
194195
prompts (if (fs/directory? prompts)
195196
;; directory based prompts
196197
(->> (fs/list-dir prompts)

src/tools.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
does not stream - calls resolve or fail only once
4646
should not throw exceptions
4747
params
48-
opts - options map for the engine
48+
opts - options map for the engine (partially bound))
4949
function-name - the name of the function that the LLM has selected
5050
json-arg-string - the JSON arg string that the LLM has generated
5151
resolve fail - callbacks"
@@ -54,7 +54,9 @@
5454
(->> (filter #(= function-name (-> % :function :name)) functions)
5555
first)
5656
:function)]
57-
(let [arg-context (arg-context json-arg-string)]
57+
(let [arg-context (merge
58+
{:hostDir (:host-dir opts)}
59+
(arg-context json-arg-string))]
5860
(try
5961
(if (:container definition) ;; synchronous call to container function
6062
(let [function-call (merge

0 commit comments

Comments
 (0)