From 91121bc3f1cf33f091228454b40e9445ab9ba9a6 Mon Sep 17 00:00:00 2001 From: Jim Clark Date: Wed, 11 Dec 2024 18:05:34 -0800 Subject: [PATCH] Interpolate into prompts --- prompts/examples/explain_dockerfile.md | 8 +++++- src/tools.clj | 38 ++++++++++++++------------ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/prompts/examples/explain_dockerfile.md b/prompts/examples/explain_dockerfile.md index 03ad12d..f52aa78 100644 --- a/prompts/examples/explain_dockerfile.md +++ b/prompts/examples/explain_dockerfile.md @@ -13,11 +13,17 @@ tools: parameters: type: object properties: + project: + type: string + description: absolute path in the project root path: type: string description: Path of the folder to delete container: image: vonwig/bash_alpine + mounts: + - "{{project|safe}}:/workdir:ro" + workdir: /workdir command: - "cat {{path|safe}}" prompt-format: "django" @@ -25,7 +31,7 @@ prompt-format: "django" # prompt user -Start by fetching the ./Dockerfile in the project root. +Start by fetching the ./Dockerfile in the project root at /Users/slim/docker/labs-ai-tools-for-devs. After fetching the Dockerfile contents, explain the Dockerfile line by line. diff --git a/src/tools.clj b/src/tools.clj index 4a1959e..741c71f 100644 --- a/src/tools.clj +++ b/src/tools.clj @@ -62,24 +62,28 @@ (try (if (:container definition) ;; synchronous call to container function (let [function-call (cond-> (merge - (:container definition) - (dissoc defaults :functions) - {:command (interpolate-coll - (-> definition :container :command) - arg-context)} - ;; workdirs in a container definition will always override ones - ;; set in the metadata - (when-let [wd (or - (-> definition :container :workdir) - (:workdir defaults))] - {:workdir (first (interpolate arg-context wd))})) + (:container definition) + (dissoc defaults :functions) + {:command (interpolate-coll + (-> definition :container :command) + arg-context)} + (when (-> definition :container :mounts) + {:mounts (->> (-> definition :container :mounts) + (map (fn [s] (first (interpolate arg-context s)))) + (into []))}) + ;; workdirs in a container definition will always override ones + ;; set in the metadata + (when-let [wd (or + (-> definition :container :workdir) + (:workdir defaults))] + {:workdir (first (interpolate arg-context wd))})) (-> definition :stdin :file) (update-in [:stdin :file] (fn [s] (first (interpolate arg-context s)))))] - (jsonrpc/notify - :message - {:debug (format "function call %s" - (with-out-str - (pp/pprint (-> function-call - (update :jwt (fn [s] (if s "xxxxxxx" "not-set")))))))}) + (jsonrpc/notify + :message + {:debug (format "function call %s" + (with-out-str + (pp/pprint (-> function-call + (update :jwt (fn [s] (if s "xxxxxxx" "not-set")))))))}) (trace/container-call (update function-call :jwt (fn [s] (if s "xxxxxxx" "not-set")))) (let [{:keys [pty-output exit-code done] :as result} (docker/run-container function-call) exit-code-fail? (if (false? (:check-exit-code definition))