[GH-ISSUE #6212] show --modelfile (still) doesn't properly quote MESSAGE statements #3881

Closed
opened 2026-04-12 14:43:17 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @Maltz42 on GitHub (Aug 7, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/6212

What is the issue?

The patch added to v0.3.3 for issue #6103 didn't work, and actually made the situation harder to mitigate with find/replace. Request that patch be rolled back, the issue be re-opened, and quoting of MESSAGE strings be revisited and tested more thoroughly. Thanks!

(Or let me know if I should copy my posts from that issue here and just start anew.)

OS

Windows

GPU

Nvidia

CPU

Intel

Ollama version

0.3.4

Originally created by @Maltz42 on GitHub (Aug 7, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/6212 ### What is the issue? The patch added to v0.3.3 for issue #6103 didn't work, and actually made the situation harder to mitigate with find/replace. Request that patch be rolled back, the issue be re-opened, and quoting of MESSAGE strings be revisited and tested more thoroughly. Thanks! (Or let me know if I should copy my posts from that issue here and just start anew.) ### OS Windows ### GPU Nvidia ### CPU Intel ### Ollama version 0.3.4
GiteaMirror added the bug label 2026-04-12 14:43:17 -05:00
Author
Owner

@mxyng commented on GitHub (Aug 7, 2024):

From the linked issue:

The messages need to be surrounded by triple-quotes, not single quotes.

Multi-line strings can be surrounded with 1x or 3x double quotes depending on usage. Which type depends on the content:

  • 1x quote if content does not contain "
  • 3x quote otherwise

Here's your example from the linked issue:

  1. Create model tmp with multiline messages:

    FROM gemma2:2b
    MESSAGE user """write a humorous limerick"""
    MESSAGE assistant """There once was a fellow named Pete,
    Whose dancing was quite incomplete.
    He spun and he fell,
    And let out a yell,
    Now his dancing's no longer so neat!"""
    
  2. Check the manifest for tmp contains this messages layer:

    $ jq '.layers[] | select(.mediaType == "application/vnd.ollama.image.messages")' ~/.ollama/models/manifests/registry.ollama.ai/library/tmp/latest
    {
      "mediaType": "application/vnd.ollama.image.messages",
      "digest": "sha256:561b820248ab51aad2a7903c8c28f102c1e7026a9cdaa6a852b307808e71617e",
      "size": 243
    }
    

    which contains this list of messages

    $ jq . ~/.ollama/models/blobs/sha256-561b820248ab51aad2a7903c8c28f102c1e7026a9cdaa6a852b307808e71617e
    [
      {
        "role": "user",
        "content": "write a humorous limerick"
      },
      {
        "role": "assistant",
        "content": "There once was a fellow named Pete,\nWhose dancing was quite incomplete.\nHe spun and he fell,\nAnd let out a yell,\nNow his dancing's no longer so neat!"
      }
    ]
    
  3. ollama show --modelfile tmp produces this output:

    # Modelfile generated by "ollama show"
    # To build a new Modelfile based on this, replace FROM with:
    # FROM tmp:latest
    
    FROM /Users/<user>/.ollama/models/blobs/sha256-7462734796d67c40ecec2ca98eddf970e171dbb6b370e43fd633ee75b69abe1b
    TEMPLATE """{{- range $i, $_ := .Messages }}
    {{- $last := eq (len (slice $.Messages $i)) 1 }}
    {{- if or (eq .Role "user") (eq .Role "system") }}<start_of_turn>user
    {{ .Content }}<end_of_turn>
    {{ if $last }}<start_of_turn>model
    {{ end }}
    {{- else if eq .Role "assistant" }}<start_of_turn>model
    {{ .Content }}{{ if not $last }}<end_of_turn>
    {{ end }}
    {{- end }}
    {{- end }}"""
    PARAMETER stop <start_of_turn>
    PARAMETER stop <end_of_turn>
    LICENSE """
    <snip>
    """
    MESSAGE user write a humorous limerick
    MESSAGE assistant "There once was a fellow named Pete,
    Whose dancing was quite incomplete.
    He spun and he fell,
    And let out a yell,
    Now his dancing's no longer so neat!"
    
  4. Create a model tmp2 from this show output and check the manifest for tmp2 shows it uses the exact same messages layer

    $ jq '.layers[] | select(.mediaType == "application/vnd.ollama.image.messages")' ~/.ollama/models/manifests/registry.ollama.ai/library/tmp2/latest
    {
      "mediaType": "application/vnd.ollama.image.messages",
      "digest": "sha256:561b820248ab51aad2a7903c8c28f102c1e7026a9cdaa6a852b307808e71617e",
      "size": 243
    }
    
<!-- gh-comment-id:2272447615 --> @mxyng commented on GitHub (Aug 7, 2024): From the linked issue: > The messages need to be surrounded by triple-quotes, not single quotes. Multi-line strings can be surrounded with 1x or 3x double quotes depending on usage. Which type depends on the content: * 1x quote if content does not contain `"` * 3x quote otherwise Here's your example from the linked issue: 1. Create model `tmp` with multiline messages: ``` FROM gemma2:2b MESSAGE user """write a humorous limerick""" MESSAGE assistant """There once was a fellow named Pete, Whose dancing was quite incomplete. He spun and he fell, And let out a yell, Now his dancing's no longer so neat!""" ``` 2. Check the manifest for `tmp` contains this messages layer: ``` $ jq '.layers[] | select(.mediaType == "application/vnd.ollama.image.messages")' ~/.ollama/models/manifests/registry.ollama.ai/library/tmp/latest { "mediaType": "application/vnd.ollama.image.messages", "digest": "sha256:561b820248ab51aad2a7903c8c28f102c1e7026a9cdaa6a852b307808e71617e", "size": 243 } ``` which contains this list of messages ``` $ jq . ~/.ollama/models/blobs/sha256-561b820248ab51aad2a7903c8c28f102c1e7026a9cdaa6a852b307808e71617e [ { "role": "user", "content": "write a humorous limerick" }, { "role": "assistant", "content": "There once was a fellow named Pete,\nWhose dancing was quite incomplete.\nHe spun and he fell,\nAnd let out a yell,\nNow his dancing's no longer so neat!" } ] ``` 3. `ollama show --modelfile tmp` produces this output: ``` # Modelfile generated by "ollama show" # To build a new Modelfile based on this, replace FROM with: # FROM tmp:latest FROM /Users/<user>/.ollama/models/blobs/sha256-7462734796d67c40ecec2ca98eddf970e171dbb6b370e43fd633ee75b69abe1b TEMPLATE """{{- range $i, $_ := .Messages }} {{- $last := eq (len (slice $.Messages $i)) 1 }} {{- if or (eq .Role "user") (eq .Role "system") }}<start_of_turn>user {{ .Content }}<end_of_turn> {{ if $last }}<start_of_turn>model {{ end }} {{- else if eq .Role "assistant" }}<start_of_turn>model {{ .Content }}{{ if not $last }}<end_of_turn> {{ end }} {{- end }} {{- end }}""" PARAMETER stop <start_of_turn> PARAMETER stop <end_of_turn> LICENSE """ <snip> """ MESSAGE user write a humorous limerick MESSAGE assistant "There once was a fellow named Pete, Whose dancing was quite incomplete. He spun and he fell, And let out a yell, Now his dancing's no longer so neat!" ``` 4. Create a model `tmp2` from this `show` output and check the manifest for `tmp2` shows it uses the exact same messages layer ``` $ jq '.layers[] | select(.mediaType == "application/vnd.ollama.image.messages")' ~/.ollama/models/manifests/registry.ollama.ai/library/tmp2/latest { "mediaType": "application/vnd.ollama.image.messages", "digest": "sha256:561b820248ab51aad2a7903c8c28f102c1e7026a9cdaa6a852b307808e71617e", "size": 243 } ```
Author
Owner

@Maltz42 commented on GitHub (Aug 7, 2024):

Yeah, after digging into this further, using fresh sessions, I think some of the things I was experiencing in the other issue may have been corruption from saving and re-importing modelfiles that screwed up quotes even further. I'm unable to reproduce any of that now in v0.3.3. I'll chalk this up to having made a mess of things on my end then for now. Thanks for the detailed walk through.

<!-- gh-comment-id:2272631547 --> @Maltz42 commented on GitHub (Aug 7, 2024): Yeah, after digging into this further, using fresh sessions, I think some of the things I was experiencing in the other issue may have been corruption from saving and re-importing modelfiles that screwed up quotes even further. I'm unable to reproduce any of that now in v0.3.3. I'll chalk this up to having made a mess of things on my end then for now. Thanks for the detailed walk through.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#3881