From 7582a73b51f77905b640a7f28020f5af2f56c71a Mon Sep 17 00:00:00 2001 From: Jim Clark Date: Thu, 16 Jan 2025 14:40:11 -0800 Subject: [PATCH] role is optional in h1 prompt headers - defaults to user --- docs/content/_index.md | 2 +- docs/content/projects/vscode.md | 6 ++ docs/content/tools/_index.md | 8 +- docs/content/tools/docs/_index.md | 2 +- docs/content/tools/docs/authoring-prompts.md | 98 ++++++++++++++++++++ docs/content/tools/docs/claude-desktop.md | 1 + docs/content/tools/docs/quickstart.md | 6 ++ docs/content/tools/mcp.md | 3 + prompts/examples/curl.md | 2 +- src/markdown.clj | 15 ++- 10 files changed, 136 insertions(+), 7 deletions(-) create mode 100644 docs/content/tools/docs/quickstart.md create mode 100644 docs/content/tools/mcp.md diff --git a/docs/content/_index.md b/docs/content/_index.md index 8591864..7d95a5f 100644 --- a/docs/content/_index.md +++ b/docs/content/_index.md @@ -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 >}} diff --git a/docs/content/projects/vscode.md b/docs/content/projects/vscode.md index e69de29..a03fce3 100644 --- a/docs/content/projects/vscode.md +++ b/docs/content/projects/vscode.md @@ -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. diff --git a/docs/content/tools/_index.md b/docs/content/tools/_index.md index 9372fdf..a3868f3 100644 --- a/docs/content/tools/_index.md +++ b/docs/content/tools/_index.md @@ -1,4 +1,10 @@ --- -title: Tools For Devs (Model Context Protocol) +title: Tools For Devs weight: 1 --- + +## AI Tools for Dev + + + +## Model Context Protocol diff --git a/docs/content/tools/docs/_index.md b/docs/content/tools/docs/_index.md index 138128b..a259453 100644 --- a/docs/content/tools/docs/_index.md +++ b/docs/content/tools/docs/_index.md @@ -1,5 +1,5 @@ --- -title: Documentation +title: Tools Project Documentation --- diff --git a/docs/content/tools/docs/authoring-prompts.md b/docs/content/tools/docs/authoring-prompts.md index 73d199e..d26bcf6 100644 --- a/docs/content/tools/docs/authoring-prompts.md +++ b/docs/content/tools/docs/authoring-prompts.md @@ -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. @@ -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 + + + diff --git a/docs/content/tools/docs/claude-desktop.md b/docs/content/tools/docs/claude-desktop.md index 7bc0fa8..b9ac86b 100644 --- a/docs/content/tools/docs/claude-desktop.md +++ b/docs/content/tools/docs/claude-desktop.md @@ -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. diff --git a/docs/content/tools/docs/quickstart.md b/docs/content/tools/docs/quickstart.md new file mode 100644 index 0000000..f147366 --- /dev/null +++ b/docs/content/tools/docs/quickstart.md @@ -0,0 +1,6 @@ +--- +title: Quick Start +weight: 1 +--- + + diff --git a/docs/content/tools/mcp.md b/docs/content/tools/mcp.md new file mode 100644 index 0000000..5187ea4 --- /dev/null +++ b/docs/content/tools/mcp.md @@ -0,0 +1,3 @@ +--- +title: Model Context Protocol +--- diff --git a/prompts/examples/curl.md b/prompts/examples/curl.md index e8ee26e..90bc2dc 100644 --- a/prompts/examples/curl.md +++ b/prompts/examples/curl.md @@ -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. diff --git a/src/markdown.clj b/src/markdown.clj index 5b2050e..d90b2de 100644 --- a/src/markdown.clj +++ b/src/markdown.clj @@ -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] @@ -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))