[GH-ISSUE #4851] Add strings module from Go for template processing #65106

Open
opened 2026-05-03 19:45:31 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @qbit- on GitHub (Jun 6, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/4851

Currently, the TEMPLATE parameter in the Modelfile is a simple Go template. For example, I can do something like this to print first 25 characters of the model's response:

{{ printf "%.*s" 25 .Response }}

However, this basic processing is not usable. What I'm trying to do is to remove the BOS token from the model's output. The token is <|begin_of_text|> and it is outputted not in every message, but at the beginning of the dialog. One possible solution is to use Go's strings module to strip the prefix:

{{ .Response | strings.TrimPrefix <|begin_of_text|> }}

but this is not supported in ollama. Can we include extra functions for template processing?

Originally created by @qbit- on GitHub (Jun 6, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/4851 Currently, the `TEMPLATE` parameter in the `Modelfile` is a simple Go template. For example, I can do something like this to print first 25 characters of the model's response: ```go {{ printf "%.*s" 25 .Response }} ``` However, this basic processing is not usable. What I'm trying to do is to remove the BOS token from the model's output. The token is `<|begin_of_text|>` and it is outputted not in every message, but at the beginning of the dialog. One possible solution is to use Go's `strings` module to strip the prefix: ```go {{ .Response | strings.TrimPrefix <|begin_of_text|> }} ``` but this is not supported in ollama. Can we include extra functions for template processing?
GiteaMirror added the feature request label 2026-05-03 19:45:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#65106