-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e10b155
commit 64df775
Showing
8 changed files
with
182 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM alpine:latest | ||
|
||
RUN apk add inotify-tools | ||
|
||
ENTRYPOINT ["/usr/bin/inotifywait"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```sh | ||
docker build -t vonwig/inotifywait . | ||
``` | ||
|
||
```sh | ||
docker run --rm -v "docker-prompts:/prompts" vonwig/inotifywait -e modify -e create -e delete -m -q /prompts/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,49 @@ | ||
(ns jsonrpc.db | ||
(ns jsonrpc.db | ||
(:require | ||
[clj-yaml.core :as yaml] | ||
git | ||
[jsonrpc.logger :as logger] | ||
prompts)) | ||
|
||
(def db* (atom {})) | ||
|
||
(defn get-prompt-data [{:keys [register] :as opts}] | ||
(logger/info "get-prompt-data " register) | ||
(->> register | ||
(map (fn [ref] [ref (git/prompt-file ref)])) | ||
(map (fn [[ref f]] | ||
(let [m (prompts/get-prompts (assoc opts :prompts f))] | ||
[(or (-> m :metadata :name) ref) m]))) | ||
(into {}))) | ||
|
||
(defn add [opts] | ||
(logger/info "adding prompts" (:register opts)) | ||
(let [m (get-prompt-data opts)] | ||
(swap! db* update-in [:mcp.prompts/registry] (fnil merge {}) m))) | ||
(defn add-static-prompts [db m] | ||
(-> db | ||
(update :mcp.prompts/registry (fnil merge {}) m) | ||
(assoc :mcp.prompts/static m))) | ||
|
||
(defn add-dynamic-prompts [db m] | ||
(logger/info "dynamic keys" (keys (:mcp.prompts/registry db))) | ||
(logger/info "static keys" (keys (:mcp.prompts/static db))) | ||
(-> db | ||
(assoc :mcp.prompts/registry (merge m (:mcp.prompts/static db))))) | ||
|
||
(defn add | ||
"add any static prompts to db" | ||
[opts] | ||
(logger/info "adding static prompts" (:register opts)) | ||
(let [prompt-registry (get-prompt-data opts)] | ||
(swap! db* add-static-prompts prompt-registry))) | ||
|
||
(comment | ||
(add {:register ["github:docker/labs-ai-tools-for-devs?path=prompts/examples/explain_dockerfile.md" | ||
"github:docker/labs-ai-tools-for-devs?path=prompts/examples/hello_world.md"]})) | ||
|
||
(defn merge [{:keys [registry-content] :as opts}] | ||
(logger/info "adding dynamic prompts" registry-content) | ||
(try | ||
(let [{:keys [registry]} (yaml/parse-string registry-content) | ||
prompt-registry (get-prompt-data (assoc opts :register (map :ref (vals registry))))] | ||
(logger/info "merging" prompt-registry) | ||
(swap! db* add-dynamic-prompts prompt-registry)) | ||
(catch Throwable e | ||
(logger/error e "could not merge dynamic prompts")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
(ns jsonrpc.watch | ||
(:require | ||
[babashka.process :as process] | ||
[clj-yaml.core :as yaml] | ||
[clojure.core.async :as async] | ||
[clojure.java.io :as io] | ||
[clojure.string :as string] | ||
[jsonrpc.logger :as logger])) | ||
|
||
(def watcher-args | ||
["inotifywait" "-e" "modify" "-e" "create" "-e" "delete" "-m" "-q" "/prompts"]) | ||
|
||
; split on white space | ||
; only care about registry.yaml | ||
;/prompts/ DELETE registry.yaml | ||
;/prompts/ CREATE registry.yaml | ||
;/prompts/ MODIFY registry.yaml | ||
|
||
(defn init [cb] | ||
(async/go | ||
(let [p (apply process/process {:out :stream} watcher-args) | ||
rdr (io/reader (:out p))] | ||
(for [line (line-seq rdr) :let [[_ event f] (string/split line #"\s+")]] | ||
(do | ||
(logger/info (format "event: %s file: %s" event f)) | ||
(when (= f "registry.yaml") | ||
(cb | ||
(try | ||
(yaml/parse-string (slurp "/prompts/registry.yaml")) | ||
(catch Throwable _ | ||
{}))))))))) |