[GH-ISSUE #3287] Allow system message to be on its own #2026

Closed
opened 2026-04-12 12:14:41 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @jackielii on GitHub (Mar 21, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/3287

Originally assigned to: @BruceMacD on GitHub.

What are you trying to do?

Current prompt rendering assumes there is only one system message. With the Command-R model from Cohere AI, there can be multiple system message: https://docs.cohere.com/docs/prompting-command-r#structured-prompt-templates. There is no way to get around this.

Consider the following messages:

{Role: "system", Content: "Preambles"},
{Role: "user", Content: "i'm user"},
{Role: "system", Content: "Tool output"},
{Role: "system", Content: "---Instructions---"},

And the template:

<BOS_TOKEN>
  {{ if .System }}<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{ .System }}<|END_OF_TURN_TOKEN|>{{ end }}
  {{ if .Prompt }}<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{ .Prompt }}<|END_OF_TURN_TOKEN|>{{ end }}<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{{ .Response }}

We get

<BOS_TOKEN>
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Preambles<|END_OF_TURN_TOKEN|>
<|START_OF_TURN_TOKEN|><|USER_TOKEN|>i'm user<|END_OF_TURN_TOKEN|>
<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><BOS_TOKEN>
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Tool output<|END_OF_TURN_TOKEN|>

<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><BOS_TOKEN>
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>---Instructions---<|END_OF_TURN_TOKEN|>

<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>

However, the desired output is:

<BOS_TOKEN>
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Preambles<|END_OF_TURN_TOKEN|>
<|START_OF_TURN_TOKEN|><|USER_TOKEN|>i'm user<|END_OF_TURN_TOKEN|>
<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><BOS_TOKEN>
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Tool output<|END_OF_TURN_TOKEN|>
<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>---Instructions---<|END_OF_TURN_TOKEN|>
<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>

How should we solve this?

In order to make this backward compatible, I suggest we introduce a new version of the template that formats each message as is. It'll be much easier to control the desired output

The code to render the prompt should detect is the new template is present and use it instead. Preferably, gradually deprecate old template.

What is the impact of not solving this?

There doesn't seems to be a backward compatible way to fix this. Introducing a new template add complexity, especially for new users. But there doesn't seems to be a better way.

Anything else?

No response

Originally created by @jackielii on GitHub (Mar 21, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/3287 Originally assigned to: @BruceMacD on GitHub. ### What are you trying to do? Current prompt rendering assumes there is only one system message. With the [Command-R model from Cohere AI](https://huggingface.co/CohereForAI/c4ai-command-r-v01), there can be multiple system message: https://docs.cohere.com/docs/prompting-command-r#structured-prompt-templates. There is no way to get around this. Consider the following messages: ```go {Role: "system", Content: "Preambles"}, {Role: "user", Content: "i'm user"}, {Role: "system", Content: "Tool output"}, {Role: "system", Content: "---Instructions---"}, ``` And the template: ``` <BOS_TOKEN> {{ if .System }}<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{ .System }}<|END_OF_TURN_TOKEN|>{{ end }} {{ if .Prompt }}<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{ .Prompt }}<|END_OF_TURN_TOKEN|>{{ end }}<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>{{ .Response }} ``` We get ``` <BOS_TOKEN> <|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Preambles<|END_OF_TURN_TOKEN|> <|START_OF_TURN_TOKEN|><|USER_TOKEN|>i'm user<|END_OF_TURN_TOKEN|> <|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><BOS_TOKEN> <|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Tool output<|END_OF_TURN_TOKEN|> <|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><BOS_TOKEN> <|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>---Instructions---<|END_OF_TURN_TOKEN|> <|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|> ``` However, the desired output is: ``` <BOS_TOKEN> <|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Preambles<|END_OF_TURN_TOKEN|> <|START_OF_TURN_TOKEN|><|USER_TOKEN|>i'm user<|END_OF_TURN_TOKEN|> <|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><BOS_TOKEN> <|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Tool output<|END_OF_TURN_TOKEN|> <|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>---Instructions---<|END_OF_TURN_TOKEN|> <|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|> ``` ### How should we solve this? In order to make this backward compatible, I suggest we introduce a new version of the template that formats each message as is. It'll be much easier to control the desired output The code to render the prompt should detect is the new template is present and use it instead. Preferably, gradually deprecate old template. ### What is the impact of not solving this? There doesn't seems to be a backward compatible way to fix this. Introducing a new template add complexity, especially for new users. But there doesn't seems to be a better way. ### Anything else? _No response_
GiteaMirror added the feature request label 2026-04-12 12:14:41 -05:00
Author
Owner

@jackielii commented on GitHub (Mar 22, 2024):

Maybe can we introduce a "raw" mode which lets the user skip the template? this will be hard to use but also maximum flexibility that covers all cases.
Update: I realised in this mode it's mostly the /api/generate endpoint.

<!-- gh-comment-id:2015645393 --> @jackielii commented on GitHub (Mar 22, 2024): Maybe can we introduce a "raw" mode which lets the user skip the template? this will be hard to use but also maximum flexibility that covers all cases. __Update__: I realised in this mode it's mostly the `/api/generate` endpoint.
Author
Owner

@pdevine commented on GitHub (May 15, 2024):

Hey @jackielii , sorry for the slow response. There actually is a raw mode for /api/generate if you check out the API documentation. We've been trying to rethink the way the templating works but haven't landed on anything ideal as of yet.

<!-- gh-comment-id:2111391819 --> @pdevine commented on GitHub (May 15, 2024): Hey @jackielii , sorry for the slow response. There actually is a _raw mode_ for `/api/generate` if you check out the [API documentation](https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-completion). We've been trying to rethink the way the templating works but haven't landed on anything ideal as of yet.
Author
Owner

@jmorganca commented on GitHub (Sep 4, 2024):

Hi @jackielii, this should be fixed. Some models do expect the system prompt to be bundled into one message at the beginning (e.g. Mistral, Llama 3/3.1), but otherwise Ollama will respect system messages that are interleaved with others. Let me know if you're seeing different behavior from this.

<!-- gh-comment-id:2327905894 --> @jmorganca commented on GitHub (Sep 4, 2024): Hi @jackielii, this should be fixed. Some models do expect the system prompt to be bundled into one message at the beginning (e.g. Mistral, Llama 3/3.1), but otherwise Ollama will respect system messages that are interleaved with others. Let me know if you're seeing different behavior from this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#2026