[GH-ISSUE #3977] api/create inserts escape quotes \" for the last PARAMETER stop. #64498

Closed
opened 2026-05-03 17:54:03 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @chigkim on GitHub (Apr 27, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/3977

What is the issue?

Hi,

If you run the following python code to copy llama3 to test, it creates a modelfile with escape qotes for the last PARAMETER stop.
If I use ollama create test -f test.modelfile, it works fine.
First I thought ollama/ollama-python was the problem, but I tried with just python requests library, and it had the same problem.

from ollama import Client
import re

client = Client(host='http://localhost:11434')
modelfile = client.show('llama3')['modelfile']
print('Original modelfile:\n', modelfile)
from_str = re.search('# (FROM.*?\n)', modelfile)[1]
modelfile = re.sub('FROM /Users.*?\n', from_str, modelfile)
print('Modified modelfile:\n', modelfile)
client.create('test', modelfile=modelfile, stream=False)
response = client.generate(model='test', prompt='hello!')
print('Response:\n', response['response'])
modelfile = client.show('test')['modelfile']
print('new modelfile:\n', modelfile)
client.delete('test')

Here's the output.

Original modelfile:
 # Modelfile generated by "ollama show"
# To build a new Modelfile based on this one, replace the FROM line with:
# FROM llama3:latest

FROM /Users/cgk/.ollama/models/blobs/sha256-00e1317cbf74d901080d7100f57580ba8dd8de57203072dc6f668324ba545f29
TEMPLATE """{{ if .System }}<|start_header_id|>system<|end_header_id|>

{{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>

{{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>

{{ .Response }}<|eot_id|>"""
PARAMETER num_keep 24
PARAMETER stop "<|start_header_id|>"
PARAMETER stop "<|end_header_id|>"
PARAMETER stop "<|eot_id|>"
Modified modelfile:
 # Modelfile generated by "ollama show"
# To build a new Modelfile based on this one, replace the FROM line with:
# FROM llama3:latest

FROM llama3:latest
TEMPLATE """{{ if .System }}<|start_header_id|>system<|end_header_id|>

{{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>

{{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>

{{ .Response }}<|eot_id|>"""
PARAMETER num_keep 24
PARAMETER stop "<|start_header_id|>"
PARAMETER stop "<|end_header_id|>"
PARAMETER stop "<|eot_id|>"
Response:
 Hello there! It's nice to meet you. Is there something I can help you with, or would you like to chat?<|eot_id|>
new modelfile:
 # Modelfile generated by "ollama show"
# To build a new Modelfile based on this one, replace the FROM line with:
# FROM test:latest

FROM llama3:latest
TEMPLATE """{{ if .System }}<|start_header_id|>system<|end_header_id|>

{{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>

{{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>

{{ .Response }}<|eot_id|>"""
PARAMETER num_keep 24
PARAMETER stop "<|start_header_id|>"
PARAMETER stop "<|end_header_id|>"
PARAMETER stop "\"<|eot_id|>\""

If you look at the last line, there's the escape quotes ". Not sure why only the last line has that.
Also if you look at the response string, it ends with <|eot_id|> because the last PARAMETER stop string in the new modelfile doesn't work.

The following python code that uses requests library has the same problem.

import requests
url ='http://localhost:11434/api/create'
data = {'name': 'test', 'modelfile': modelfile, 'stream': False}
response = requests.post(url, json=data)

Could you look into this?
Thanks so much!

OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.1.32

Originally created by @chigkim on GitHub (Apr 27, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/3977 ### What is the issue? Hi, If you run the following python code to copy llama3 to test, it creates a modelfile with escape qotes for the last PARAMETER stop. If I use `ollama create test -f test.modelfile`, it works fine. First I thought [ollama/ollama-python](https://github.com/ollama/ollama-python/issues/136) was the problem, but I tried with just python requests library, and it had the same problem. ```python from ollama import Client import re client = Client(host='http://localhost:11434') modelfile = client.show('llama3')['modelfile'] print('Original modelfile:\n', modelfile) from_str = re.search('# (FROM.*?\n)', modelfile)[1] modelfile = re.sub('FROM /Users.*?\n', from_str, modelfile) print('Modified modelfile:\n', modelfile) client.create('test', modelfile=modelfile, stream=False) response = client.generate(model='test', prompt='hello!') print('Response:\n', response['response']) modelfile = client.show('test')['modelfile'] print('new modelfile:\n', modelfile) client.delete('test') ``` Here's the output. ```bash Original modelfile: # Modelfile generated by "ollama show" # To build a new Modelfile based on this one, replace the FROM line with: # FROM llama3:latest FROM /Users/cgk/.ollama/models/blobs/sha256-00e1317cbf74d901080d7100f57580ba8dd8de57203072dc6f668324ba545f29 TEMPLATE """{{ if .System }}<|start_header_id|>system<|end_header_id|> {{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|> {{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|> {{ .Response }}<|eot_id|>""" PARAMETER num_keep 24 PARAMETER stop "<|start_header_id|>" PARAMETER stop "<|end_header_id|>" PARAMETER stop "<|eot_id|>" Modified modelfile: # Modelfile generated by "ollama show" # To build a new Modelfile based on this one, replace the FROM line with: # FROM llama3:latest FROM llama3:latest TEMPLATE """{{ if .System }}<|start_header_id|>system<|end_header_id|> {{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|> {{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|> {{ .Response }}<|eot_id|>""" PARAMETER num_keep 24 PARAMETER stop "<|start_header_id|>" PARAMETER stop "<|end_header_id|>" PARAMETER stop "<|eot_id|>" Response: Hello there! It's nice to meet you. Is there something I can help you with, or would you like to chat?<|eot_id|> new modelfile: # Modelfile generated by "ollama show" # To build a new Modelfile based on this one, replace the FROM line with: # FROM test:latest FROM llama3:latest TEMPLATE """{{ if .System }}<|start_header_id|>system<|end_header_id|> {{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|> {{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|> {{ .Response }}<|eot_id|>""" PARAMETER num_keep 24 PARAMETER stop "<|start_header_id|>" PARAMETER stop "<|end_header_id|>" PARAMETER stop "\"<|eot_id|>\"" ``` If you look at the last line, there's the escape quotes \". Not sure why only the last line has that. Also if you look at the response string, it ends with <|eot_id|> because the last PARAMETER stop string in the new modelfile doesn't work. The following python code that uses requests library has the same problem. ```python import requests url ='http://localhost:11434/api/create' data = {'name': 'test', 'modelfile': modelfile, 'stream': False} response = requests.post(url, json=data) ``` Could you look into this? Thanks so much! ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version 0.1.32
GiteaMirror added the bug label 2026-05-03 17:54:03 -05:00
Author
Owner

@mxyng commented on GitHub (May 2, 2024):

this is a bug with the parser and will be fixed by #3892

<!-- gh-comment-id:2091824076 --> @mxyng commented on GitHub (May 2, 2024): this is a bug with the parser and will be fixed by #3892
Author
Owner

@chigkim commented on GitHub (May 3, 2024):

Awesome,! Thanks!

<!-- gh-comment-id:2093178320 --> @chigkim commented on GitHub (May 3, 2024): Awesome,! Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#64498