docs: add docs for docs.ollama.com (#12805)

This commit is contained in:
Parth Sareen
2025-10-28 13:18:48 -07:00
committed by GitHub
parent 6d02a43a75
commit 3d99d9779a
74 changed files with 4997 additions and 2175 deletions

View File

@@ -1,4 +1,6 @@
# Template
---
title: Template
---
Ollama provides a powerful templating engine backed by Go's built-in templating engine to construct prompts for your large language model. This feature is a valuable tool to get the most out of your models.
@@ -6,13 +8,13 @@ Ollama provides a powerful templating engine backed by Go's built-in templating
A basic Go template consists of three main parts:
* **Layout**: The overall structure of the template.
* **Variables**: Placeholders for dynamic data that will be replaced with actual values when the template is rendered.
* **Functions**: Custom functions or logic that can be used to manipulate the template's content.
- **Layout**: The overall structure of the template.
- **Variables**: Placeholders for dynamic data that will be replaced with actual values when the template is rendered.
- **Functions**: Custom functions or logic that can be used to manipulate the template's content.
Here's an example of a simple chat template:
```go
```gotmpl
{{- range .Messages }}
{{ .Role }}: {{ .Content }}
{{- end }}
@@ -20,9 +22,9 @@ Here's an example of a simple chat template:
In this example, we have:
* A basic messages structure (layout)
* Three variables: `Messages`, `Role`, and `Content` (variables)
* A custom function (action) that iterates over an array of items (`range .Messages`) and displays each item
- A basic messages structure (layout)
- Three variables: `Messages`, `Role`, and `Content` (variables)
- A custom function (action) that iterates over an array of items (`range .Messages`) and displays each item
## Adding templates to your model
@@ -61,7 +63,7 @@ TEMPLATE """{{- if .System }}<|start_header_id|>system<|end_header_id|>
`Messages[].Role` (string): role which can be one of `system`, `user`, `assistant`, or `tool`
`Messages[].Content` (string): message content
`Messages[].Content` (string): message content
`Messages[].ToolCalls` (list): list of tools the model wants to call
@@ -99,9 +101,9 @@ TEMPLATE """{{- if .System }}<|start_header_id|>system<|end_header_id|>
Keep the following tips and best practices in mind when working with Go templates:
* **Be mindful of dot**: Control flow structures like `range` and `with` changes the value `.`
* **Out-of-scope variables**: Use `$.` to reference variables not currently in scope, starting from the root
* **Whitespace control**: Use `-` to trim leading (`{{-`) and trailing (`-}}`) whitespace
- **Be mindful of dot**: Control flow structures like `range` and `with` changes the value `.`
- **Out-of-scope variables**: Use `$.` to reference variables not currently in scope, starting from the root
- **Whitespace control**: Use `-` to trim leading (`{{-`) and trailing (`-}}`) whitespace
## Examples
@@ -155,13 +157,14 @@ CodeLlama [7B](https://ollama.com/library/codellama:7b-code) and [13B](https://o
<PRE> {{ .Prompt }} <SUF>{{ .Suffix }} <MID>
```
> [!NOTE]
> CodeLlama 34B and 70B code completion and all instruct and Python fine-tuned models do not support fill-in-middle.
<Note>
CodeLlama 34B and 70B code completion and all instruct and Python fine-tuned models do not support fill-in-middle.
</Note>
#### Codestral
Codestral [22B](https://ollama.com/library/codestral:22b) supports fill-in-middle.
```go
```gotmpl
[SUFFIX]{{ .Suffix }}[PREFIX] {{ .Prompt }}
```