Skip to content

Commit

Permalink
role is optional in h1 prompt headers
Browse files Browse the repository at this point in the history
- defaults to user
  • Loading branch information
slimslenderslacks committed Jan 16, 2025
1 parent 08a4440 commit 7582a73
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ breadcrumbs: false
{{< cards >}}
{{< card link="tools" title="AI Tools for Devs" subtitle="Using Docker to extend AI systems with custom tool runtimes" image="https://spec.modelcontextprotocol.io/images/dark.svg" tag="Incubating">}}
{{< card link="speculative" title="Speculative Execution" image="img/speculative.png" tag="Incubating">}}
{{< card link="projects/vscode.md" title="Docker VSCode Extension" image="img/vscode.png" tag="Engineering">}}
{{< card link="projects/vscode" title="Docker VSCode Extension" image="img/vscode.png" tag="Engineering">}}
{{< /cards >}}
6 changes: 6 additions & 0 deletions docs/content/projects/vscode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# Background

We worked on a VSCode extension to add a new Docker Language Service. The language sevice is IDE agnostic and can be attached to IDEs like Intellij, and neovim.

The [current extension releases](https://github.com/docker/docker-vscode-extension/releases) are available internally to Docker employees.
8 changes: 7 additions & 1 deletion docs/content/tools/_index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
---
title: Tools For Devs (Model Context Protocol)
title: Tools For Devs
weight: 1
---

## AI Tools for Dev



## Model Context Protocol
2 changes: 1 addition & 1 deletion docs/content/tools/docs/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Documentation
title: Tools Project Documentation
---


98 changes: 98 additions & 0 deletions docs/content/tools/docs/authoring-prompts.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
title: Authoring Prompts
weight: 2
---

# Prompt files

A prompt is markdown content with a preamble describing tools available to the agent when executing this prompt.
Expand Down Expand Up @@ -107,3 +112,96 @@ Run the curl command, in silent mode, to fetch gists for user slimslenderslacks
Set streaming to false if you're using Ollama for tool calling. Ollama does not currently stream tool calls.
{{< /callout >}}

## Prompt Templates

It is common for prompts to contain parameters that are either extracted from a user interaction
or, in the case of RAG, are populated by some sort of retrieval process. Markdown prompts can also
contain template parameters.

For example, the above curl example could be re-written as a template with a ``{{ user }}`` parameter.

```markdown
---
tools:
- name: curl
url: http://localhost/v1/chat/completions
stream: false
model: llama3.1
---

# prompt

Run the curl command, in silent mode, to fetch gists for user {{ user }} from GitHub.
```

### Binding values during testing

When running in VSCode, you can set values of the parameters in the markdown preamble.

```markdown
---
parameter-values:
user: slimslenderslacks
---
```

### Extractors

Extractors are container functions that can be used to extract values when the prompt has been deployed
to a server. These extractors are also used to populate default values for a prompt when it is used from
an MCP client.

Extractor definitions also follow the pattern of compose services. They are just docker images but with
the additional requirement that they should write `application/json` to stdout. This json will be used to
populate the context for binding parameters in the prompt template.

```markdown
---
extractors:
- name: linguist
image: vonwig/go-linguist:latest
command:
- -json
---
```

We can create lists if the extractor json output has array types. For example,
if we run the linguist tool to extract language from a project, our prompt can list
them using the following template. You need to be familar with the json format output
by linguist (eg that it creates lists of maps with a `language` key).

```markdown
---
extractors:
- name: linguist
---

# prompt

{{#linguist}}

This project contains {{language}} code.

{{/linguist}}

```

### Template Engine

We support two templating engines today.

* [mustache](https://mustache.github.io/mustache.5.html) is the default
* [django](https://docs.djangoproject.com/en/5.1/topics/templates/)

If you want to use django, then add the following field in the markdown preamble.

```markdown
---
prompt-format: "django"
---
```

### MCP arguments



1 change: 1 addition & 0 deletions docs/content/tools/docs/claude-desktop.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Using Claude Desktop
weight: 3
---

Enable mcp_run in your claude_desktop_config.json file using the following snippet. See the [quickstart for Claude Desktop Users](https://modelcontextprotocol.io/quickstart/user) for more details.
Expand Down
6 changes: 6 additions & 0 deletions docs/content/tools/docs/quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Quick Start
weight: 1
---


3 changes: 3 additions & 0 deletions docs/content/tools/mcp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Model Context Protocol
---
2 changes: 1 addition & 1 deletion prompts/examples/curl.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tools:
- name: curl
---

# prompt user
# prompt

Run the curl command, in silent mode, to fetch gists for user slimslenderslacks from GitHub.

15 changes: 12 additions & 3 deletions src/markdown.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
(update 0 (fn [s] (.substring ^String s (dec c1))))
(update (dec (count lines)) (fn [s] (.substring ^String s 0 (- c2 c1))))))))

(def prompt-pattern #"(?i)\s*prompt\s+(\w+)\s?")
(def prompt-pattern-with-role-capture #"(?i)\s*prompt\s+(\w+)\s?")
(def prompt-pattern #"(?i)\s*prompt\s?(\w+)?\s?")

(defn extract-role [s]
(second
(re-find prompt-pattern s)))
(re-find prompt-pattern-with-role-capture s)))

;; headings that include the word Prompt
(defn prompt-section? [content node]
Expand All @@ -51,10 +52,18 @@
;; extract Role from Prompt ....
(defn node-content [content node]
{:role
(-> node (nth 2) (nth 3) (nth 1) (from-range content) (extract-role))
(or (-> node (nth 2) (nth 3) (nth 1) (from-range content) (extract-role)) "user")
:content
(remove-first-line (from-range (nth node 1) content))})

(comment
(extract-role "prompt user")
(extract-role "prompt")
(extract-role "prompt user and more")
(re-matches prompt-pattern "prompt")
(re-matches prompt-pattern "prompt user")
(re-matches prompt-pattern "prompt user"))

(defn extract-prompts [content ast]
(->>
(iterate zip/next (zip/seq-zip ast))
Expand Down

0 comments on commit 7582a73

Please sign in to comment.