|
| 1 | +--- |
| 2 | +title: Authoring Prompts |
| 3 | +weight: 2 |
| 4 | +--- |
| 5 | + |
1 | 6 | # Prompt files |
2 | 7 |
|
3 | 8 | 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 |
107 | 112 | Set streaming to false if you're using Ollama for tool calling. Ollama does not currently stream tool calls. |
108 | 113 | {{< /callout >}} |
109 | 114 |
|
| 115 | +## Prompt Templates |
| 116 | + |
| 117 | +It is common for prompts to contain parameters that are either extracted from a user interaction |
| 118 | +or, in the case of RAG, are populated by some sort of retrieval process. Markdown prompts can also |
| 119 | +contain template parameters. |
| 120 | + |
| 121 | +For example, the above curl example could be re-written as a template with a ``{{ user }}`` parameter. |
| 122 | + |
| 123 | +```markdown |
| 124 | +--- |
| 125 | +tools: |
| 126 | + - name: curl |
| 127 | +url: http://localhost/v1/chat/completions |
| 128 | +stream: false |
| 129 | +model: llama3.1 |
| 130 | +--- |
| 131 | + |
| 132 | +# prompt |
| 133 | + |
| 134 | +Run the curl command, in silent mode, to fetch gists for user {{ user }} from GitHub. |
| 135 | +``` |
| 136 | + |
| 137 | +### Binding values during testing |
| 138 | + |
| 139 | +When running in VSCode, you can set values of the parameters in the markdown preamble. |
| 140 | + |
| 141 | +```markdown |
| 142 | +--- |
| 143 | +parameter-values: |
| 144 | + user: slimslenderslacks |
| 145 | +--- |
| 146 | +``` |
| 147 | + |
| 148 | +### Extractors |
| 149 | + |
| 150 | +Extractors are container functions that can be used to extract values when the prompt has been deployed |
| 151 | +to a server. These extractors are also used to populate default values for a prompt when it is used from |
| 152 | +an MCP client. |
| 153 | + |
| 154 | +Extractor definitions also follow the pattern of compose services. They are just docker images but with |
| 155 | +the additional requirement that they should write `application/json` to stdout. This json will be used to |
| 156 | +populate the context for binding parameters in the prompt template. |
| 157 | + |
| 158 | +```markdown |
| 159 | +--- |
| 160 | +extractors: |
| 161 | + - name: linguist |
| 162 | + image: vonwig/go-linguist:latest |
| 163 | + command: |
| 164 | + - -json |
| 165 | +--- |
| 166 | +``` |
| 167 | + |
| 168 | +We can create lists if the extractor json output has array types. For example, |
| 169 | +if we run the linguist tool to extract language from a project, our prompt can list |
| 170 | +them using the following template. You need to be familar with the json format output |
| 171 | +by linguist (eg that it creates lists of maps with a `language` key). |
| 172 | + |
| 173 | +```markdown |
| 174 | +--- |
| 175 | +extractors: |
| 176 | + - name: linguist |
| 177 | +--- |
| 178 | + |
| 179 | +# prompt |
| 180 | + |
| 181 | +{{#linguist}} |
| 182 | + |
| 183 | +This project contains {{language}} code. |
| 184 | + |
| 185 | +{{/linguist}} |
| 186 | + |
| 187 | +``` |
| 188 | + |
| 189 | +### Template Engine |
| 190 | + |
| 191 | +We support two templating engines today. |
| 192 | + |
| 193 | +* [mustache](https://mustache.github.io/mustache.5.html) is the default |
| 194 | +* [django](https://docs.djangoproject.com/en/5.1/topics/templates/) |
| 195 | + |
| 196 | +If you want to use django, then add the following field in the markdown preamble. |
| 197 | + |
| 198 | +```markdown |
| 199 | +--- |
| 200 | +prompt-format: "django" |
| 201 | +--- |
| 202 | +``` |
| 203 | + |
| 204 | +### MCP arguments |
| 205 | + |
| 206 | + |
| 207 | + |
0 commit comments