[PR #3784] [CLOSED] Allow whitespace within objects and arrays, but remove trailing possibly infinite whitespace #11277

Closed
opened 2026-04-12 23:26:26 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/3784
Author: @hughescr
Created: 4/20/2024
Status: Closed

Base: mainHead: bugfix/disallow-possibly-infinite-trailing-whitespace-in-json


📝 Commits (1)

  • 74f10db Allow whitespace within objects and arrays, but remove trailing possibly infinite whitespace

📊 Changes

1 file changed (+5 additions, -5 deletions)

View changed files

📝 llm/server.go (+5 -5)

📄 Description

The PR tweaks the JSON grammar to improve use of whitespace (though doesn't remove it entirely); it prevents trailing whitespace on grammatical elements, but does allow whitespace inside of {} or []. This reduces the likelihood that a model might spit out a complete JSON object/array/primitive/literal, and then append a whole bunch of useless whitespace, consuming time and money and churning more CO2 into the atmosphere.

There's still a chance with the definition of ws that it could do this within objects/arrays, but from anecdotal testing on my machine with various models, this seems way way less common than trailing whitespace at the end of the entire reponse.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/3784 **Author:** [@hughescr](https://github.com/hughescr) **Created:** 4/20/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `bugfix/disallow-possibly-infinite-trailing-whitespace-in-json` --- ### 📝 Commits (1) - [`74f10db`](https://github.com/ollama/ollama/commit/74f10dbb9ced192c249950cef5e2f713988f02eb) Allow whitespace within objects and arrays, but remove trailing possibly infinite whitespace ### 📊 Changes **1 file changed** (+5 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `llm/server.go` (+5 -5) </details> ### 📄 Description The PR tweaks the JSON grammar to improve use of whitespace (though doesn't remove it entirely); it prevents trailing whitespace on grammatical elements, but does allow whitespace inside of `{}` or `[]`. This reduces the likelihood that a model might spit out a complete JSON object/array/primitive/literal, and then append a whole bunch of useless whitespace, consuming time and money and churning more CO2 into the atmosphere. There's still a chance with the definition of `ws` that it could do this *within* objects/arrays, but from anecdotal testing on my machine with various models, this seems way way less common than trailing whitespace at the end of the entire reponse. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-12 23:26:26 -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#11277