Skip to content

Commit 7bc4a40

Browse files
Initial Commit
0 parents  commit 7bc4a40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3335
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build and Push Prompts Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up QEMU
17+
uses: docker/setup-qemu-action@v3
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
22+
- name: Login to Docker Hub
23+
uses: docker/login-action@v3
24+
with:
25+
username: ${{ secrets.TEMP_DOCKER_USERNAME }}
26+
password: ${{ secrets.TEMP_DOCKER_PAT }}
27+
28+
- name: Build and push
29+
uses: docker/build-push-action@v5
30+
with:
31+
platforms: linux/amd64,linux/arm64
32+
push: true
33+
tags: vonwig/prompts:latest

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**/.direnv/
2+
**/result
3+
.clj-kondo
4+
.lsp

Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM babashka/babashka:latest@sha256:4bc4beea38406782845ae8effaa9bd2f45345d46a4290ea4c96037970a0ca430 AS bb
2+
3+
FROM bb AS base
4+
5+
RUN <<EOF
6+
apt-get update
7+
apt-get install -y git
8+
EOF
9+
10+
FROM eclipse-temurin:latest@sha256:ac1545309de7e27001a80d91df2d42865c0bacaec75e016cb4482255d7691187 AS build
11+
12+
WORKDIR /app
13+
14+
COPY --from=bb /usr/local/bin/bb /usr/local/bin/bb
15+
COPY bb.edn bb.edn
16+
COPY ./src ./src
17+
RUN bb uberjar prompts.jar -m prompts
18+
19+
FROM base
20+
21+
WORKDIR /app
22+
23+
COPY --from=build /app/prompts.jar /app/prompts.jar
24+
25+
COPY prompts/docker docker
26+
COPY prompts/npm_setup npm_setup
27+
COPY prompts/lazy_docker lazy_docker
28+
29+
# Can't be shell form because we need to pass JSON as an arg
30+
ENTRYPOINT [ "bb", "/app/prompts.jar" ]

README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
2+
## Running Prompts
3+
4+
To generate prompts for a project, clone a repo into `$PWD` and run the
5+
following command.
6+
7+
```sh
8+
docker run --rm \
9+
-v /var/run/docker.sock:/var/run/docker.sock \
10+
--mount type=volume,source=docker-prompts,target=/prompts \
11+
vonwig/prompts:latest $PWD \
12+
jimclark106 \
13+
darwin \
14+
"github:docker/labs-make-runbook?ref=main&path=prompts/lazy_docker"
15+
```
16+
17+
The four arguments are
18+
* `project root dir on host`,
19+
* `docker login username`,
20+
* `platform`,
21+
* `github ref` for prompt files.
22+
23+
If you need to test prompts before you push, you can bind a local prompt directory instead of using
24+
a GitHub ref. For example, to test some local prompts in a directory named `my_prompts`, run:
25+
26+
```sh
27+
docker run --rm \
28+
-v /var/run/docker.sock:/var/run/docker.sock \
29+
--mount type=bind,source=$PWD,target=/app/my_prompts \
30+
--workdir /app
31+
vonwig/prompts:latest $PWD \
32+
jimclark106 \
33+
darwin \
34+
my_prompts
35+
```
36+
37+
## Running a Conversation Loop
38+
39+
```sh
40+
docker run --rm \
41+
-it \
42+
-v /var/run/docker.sock:/var/run/docker.sock \
43+
--mount type=volume,source=docker-prompts,target=/prompts \
44+
--mount type=bind,source=$HOME/.openai-api-key,target=/root/.openai-api-key \
45+
vonwig/prompts:latest \
46+
run \
47+
$PWD \
48+
$USER \
49+
"$(uname -o)" \
50+
"github:docker/labs-githooks?ref=main&path=prompts/git_hooks"
51+
```
52+
53+
### Running a Conversation Loop with Local Prompts
54+
55+
If you want to run a conversation loop with local prompts then you need to think about two different directories, the one that the root of your project ($PWD above),
56+
and the one that contains your prompts (let's call that $PROMPTS_DIR). Here's a command line for running the prompts when our $PWD is the project root and we've set the environment variable
57+
$PROMPTS_DIR to point at the directory containing our prompts.
58+
59+
```sh
60+
docker run --rm \
61+
-it \
62+
-v /var/run/docker.sock:/var/run/docker.sock \
63+
--mount type=bind,source=$PROMPTS_DIR,target=/app/my_prompts \
64+
--workdir /app
65+
--mount type=volume,source=docker-prompts,target=/prompts \
66+
--mount type=bind,source=$HOME/.openai-api-key,target=/root/.openai-api-key \
67+
vonwig/prompts:latest \
68+
run \
69+
$PWD \
70+
$USER \
71+
"$(uname -o)" \
72+
my_prompts
73+
```
74+
75+
## GitHub refs
76+
77+
Prompts are fetched from a GitHub repository. The mandatory parts of the ref are `github:{owner}/{repo}`
78+
but optional `path` and `ref` can be added to pull prompts from branches, and to specify a subdirectory
79+
where the prompt files are located in the repo.
80+
81+
### Prompt file layout
82+
83+
Each prompt directory should contain a README.md describing the prompts and their purpose. Each prompt file
84+
is a markdown document that supports moustache templates for subsituting context extracted from the project.
85+
86+
```
87+
prompt_dir/
88+
├── 010_system_prompt.md
89+
├── 020_user_prompt.md
90+
└── README.md
91+
```
92+
93+
* ordering of messages is determined by filename sorting
94+
* the role is encoded in the name of the file
95+
96+
### Moustache Templates
97+
98+
The prompt templates can contain expressions like {{dockerfiles}} to add information
99+
extracted from the current project. Examples of facts that can be added to the
100+
prompts are:
101+
102+
* `{{platform}}` - the platform of the current development environment.
103+
* `{{username}}` - the DockerHub username (and default namespace for image pushes)
104+
* `{{languages}}` - names of languages discovered in the project.
105+
* `{{project.dockerfiles}}` - the relative paths to local DockerFiles
106+
* `{{project.composefiles}}` - the relative paths to local Docker Compose files.
107+
108+
The entire `project-facts` map is also available using dot-syntax
109+
forms like `{{project-facts.project-root-uri}}`. All moustache template
110+
expressions documented [here](https://github.com/yogthos/Selmer) are supported.
111+
112+
## Building
113+
114+
```sh
115+
#docker:command=build
116+
117+
docker build -t vonwig/prompts:local -f Dockerfile .
118+
```
119+

bb.edn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{:paths ["src" "dev"]
2+
:deps {markdown-clj/markdown-clj {:mvn/version "1.12.1"}
3+
pogonos/pogonos {:mvn/version "0.2.1"}
4+
dev.weavejester/medley {:mvn/version "1.8.0"}
5+
io.replikativ/hasch {:mvn/version "0.3.94"}}}

dev/clean_local_images.clj

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(ns clean-local-images
2+
(:require [docker]
3+
[clojure.pprint :refer [pprint]]))
4+
5+
(def images
6+
#{"vonwig/prompts:latest"
7+
"vonwig/github-cli"
8+
"vonwig/function_write_file"
9+
"vonwig/docker_scout_tag_recommendation"
10+
"vonwig/extractor-node"
11+
"vonwig/go-linguist"
12+
"vonwig/codescope"
13+
"vonwig/pre-commit"
14+
"markdownlint/markdownlint"
15+
"hadolint/hadolint"})
16+
17+
(comment
18+
(docker/delete-image {:image "vonwig/function_write_files"}))
19+
20+
(defn repo? [images]
21+
(fn [tag-or-digest]
22+
(some (fn [image] (.startsWith tag-or-digest image)) images)))
23+
24+
(defn -main []
25+
(println
26+
(->> (docker/images {})
27+
#_(map #(concat (:RepoTags %) (:RepoDigests %)))
28+
(filter #(some (repo? images) (concat (:RepoTags %) (:RepoDigests %))))
29+
(map :Id)
30+
(map #(docker/delete-image {:image %})))))
31+
32+
(comment
33+
(pprint (docker/images {}))
34+
)
35+

dev/ollama.clj

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
(ns dev.ollama
2+
(:require
3+
[prompts]
4+
[babashka.curl :as curl]
5+
[babashka.process :as p]
6+
[cheshire.core :as json]
7+
[clojure.pprint :as pprint]
8+
[selmer.parser :as selmer.parser]
9+
[clojure.string :as string]))
10+
11+
(def x (p/process
12+
{:out :string :err :string}
13+
"docker"
14+
"run"
15+
"--rm"
16+
"vonwig/prompts"
17+
"{}" "jimclark106" "darwin"))
18+
19+
(def f "/Users/slim/docker/genai-stack/")
20+
21+
(def x (p/process
22+
{:out :string :err :string}
23+
"docker"
24+
"run"
25+
"--rm"
26+
"--interactive"
27+
"--init"
28+
"--mount" "type=volume,source=docker-lsp,target=/docker"
29+
"--mount" (format "type=bind,source=%s,target=/project" f)
30+
"--entrypoint" "/app/result/bin/docker-lsp"
31+
"docker/lsp:staging"
32+
"project-facts"
33+
"--workspace" "/docker"
34+
"--vs-machine-id" "none"))
35+
36+
(def y (p/process
37+
{:out :string :err :string :extra-env {"DOCKER_LSP" "nix"}}
38+
"nix"
39+
"run"
40+
"/Users/slim/docker/lsp#clj"
41+
"project-facts"
42+
"--"
43+
"--pod-exe-path" "/Users/slim/docker/babashka-pod-docker/result/bin/entrypoint"
44+
"--workspace" "/Users/slim/.docker"
45+
"--project-root" f
46+
"--vs-machine-id" "none"))
47+
48+
(def project-facts
49+
(-> y
50+
(deref)
51+
:out
52+
(json/parse-string keyword)))
53+
54+
(pprint/pprint project-facts)
55+
56+
(prompts/prompts (json/generate-string (dissoc project-facts :project/dockerfiles)) "jimclark106" "darwin")
57+
58+
(defn ollama [messages]
59+
(->
60+
(curl/post "http://localhost:11434/v1/chat/completions"
61+
{:body (json/generate-string
62+
{:model "llama3"
63+
:temperature 0.1
64+
:messages messages})})
65+
:body
66+
(json/parse-string keyword)))
67+
68+
(def api-key "")
69+
70+
(defn openai [messages]
71+
(->
72+
(curl/post "https://api.openai.com/v1/chat/completions"
73+
{:headers {"Authorization" (format "Bearer %s" api-key)
74+
"Content-Type" "application/json"}
75+
:throw false
76+
:body (json/generate-string
77+
{:model "gpt-4"
78+
:temperature 0.1
79+
:messages messages})})
80+
:body
81+
(json/parse-string keyword)))
82+
83+
(-> (with-out-str (prompts/prompts
84+
(json/generate-string project-facts)
85+
"jimclark106"
86+
"darwin"))
87+
(json/parse-string keyword)
88+
(openai)
89+
;:choices
90+
;first
91+
;:message
92+
;:content
93+
;println
94+
)
95+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flake-profile-1-link
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/nix/store/aq253zh53pswib3bf6xcr6fzjbk45kb5-python-env

functions/codescope/.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

0 commit comments

Comments
 (0)