[GH-ISSUE #3614] API response content contains leading space before some non-alphabetical chars #48740

Open
opened 2026-04-28 09:10:41 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @Propheticus on GitHub (Apr 12, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/3614

What is the issue?

When calling the /v1/chat/completions endpoint the response sometimes contains a leading space.

e.g. when asking for a markdown table the first char is a | , or when asking for a quote and the first char is a _ (to later end with another to make italic) the content returned often -but not always- looks like:

"message":{
				"role":"assistant",
				"content":" \"_The only way to do great work is to love what you do._\" - Steve Jobs"
			},
			"finish_reason":"stop"

The same happens when streaming data chunks:

data: {"id":"chatcmpl-139","object":"chat.completion.chunk","created":1712915479,"model":"mistral7bq5","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" **\""},"finish_reason":null}]}

data: {"id":"chatcmpl-139","object":"chat.completion.chunk","created":1712915479,"model":"mistral7bq5","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"The"},"finish_reason":null}]}

data: {"id":"chatcmpl-139","object":"chat.completion.chunk","created":1712915479,"model":"mistral7bq5","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" only"},"finish_reason":null}]}

data: {"id":"chatcmpl-139","object":"chat.completion.chunk","created":1712915479,"model":"mistral7bq5","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" way"},"finish_reason":null}]}

Why is this a problem?
A leading space ruins the header row of a markdown table.
It's also not in line with the Open AI API specs.

What did you expect to see?

No leading spaces. e.g.:

"message":{
				"role":"assistant",
				"content":"\"_The only way to do great work is to love what you do._\" - Steve Jobs"
			},
			"finish_reason":"stop"

Steps to reproduce

Calling the completions endpoint from either Obsidian (using BMO chatbot plugin) or from Notepad++ using Rest API to text plugin. Ask the model Mistral instruct 7B v0.2 Q5_K_M (gguf) to make me a markdown table or output text in quotes.

In the syntax understood by "Rest API to text" NP++ plugin

POST http://127.0.0.1:11434/v1/chat/completions
**headers**
content-type: application/json
**RestApiToTextOptions**
	ShowResponseHeaders
**body**
{
    "messages": [
        {
            "content": "You are a helpful assistant.",
            "role": "system"
        },
        {
            "content": "make me a markdown table of 3 columns and 2 rows. Don't use a code block.",
            "role": "user"
        }
    ],
    "model": "mistral7bq5",
    "stream": true
}

50/50 chance of leading space.

Are there any recent changes that introduced the issue?

No response

OS

Windows

Architecture

amd64

Platform

No response

Ollama version

0.1.31

GPU

AMD

GPU info

AMD Radeon RX 6800 XT

GcnArchName: gfx1030
Total Mem: 16918130688
ggml_cuda_init: found 1 ROCm devices:
Device 0: AMD Radeon RX 6800 XT, compute capability 10.3, VMM: no

CPU

AMD

Other software

No response

Originally created by @Propheticus on GitHub (Apr 12, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/3614 ### What is the issue? When calling the /v1/chat/completions endpoint the response sometimes contains a leading space. e.g. when asking for a markdown table the first char is a `|` , or when asking for a quote and the first char is a `_` (to later end with another to make _italic_) the content returned often -but not always- looks like: ``` "message":{ "role":"assistant", "content":" \"_The only way to do great work is to love what you do._\" - Steve Jobs" }, "finish_reason":"stop" ``` The same happens when streaming data chunks: ``` data: {"id":"chatcmpl-139","object":"chat.completion.chunk","created":1712915479,"model":"mistral7bq5","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" **\""},"finish_reason":null}]} data: {"id":"chatcmpl-139","object":"chat.completion.chunk","created":1712915479,"model":"mistral7bq5","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"The"},"finish_reason":null}]} data: {"id":"chatcmpl-139","object":"chat.completion.chunk","created":1712915479,"model":"mistral7bq5","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" only"},"finish_reason":null}]} data: {"id":"chatcmpl-139","object":"chat.completion.chunk","created":1712915479,"model":"mistral7bq5","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" way"},"finish_reason":null}]} ``` Why is this a problem? A leading space ruins the header row of a markdown table. It's also not in line with the Open AI API specs. ### What did you expect to see? No leading spaces. e.g.: ``` "message":{ "role":"assistant", "content":"\"_The only way to do great work is to love what you do._\" - Steve Jobs" }, "finish_reason":"stop" ``` ### Steps to reproduce Calling the completions endpoint from either Obsidian (using BMO chatbot plugin) or from Notepad++ using Rest API to text plugin. Ask the model Mistral instruct 7B v0.2 Q5_K_M (gguf) to make me a markdown table or output text in quotes. In the syntax understood by "Rest API to text" NP++ plugin ``` http POST http://127.0.0.1:11434/v1/chat/completions **headers** content-type: application/json **RestApiToTextOptions** ShowResponseHeaders **body** { "messages": [ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "make me a markdown table of 3 columns and 2 rows. Don't use a code block.", "role": "user" } ], "model": "mistral7bq5", "stream": true } ``` 50/50 chance of leading space. ### Are there any recent changes that introduced the issue? _No response_ ### OS Windows ### Architecture amd64 ### Platform _No response_ ### Ollama version 0.1.31 ### GPU AMD ### GPU info AMD Radeon RX 6800 XT ``` GcnArchName: gfx1030 Total Mem: 16918130688 ``` ``` ggml_cuda_init: found 1 ROCm devices: Device 0: AMD Radeon RX 6800 XT, compute capability 10.3, VMM: no ``` ### CPU AMD ### Other software _No response_
GiteaMirror added the bugapi labels 2026-04-28 09:10:41 -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#48740