[PR #12055] GBNF format and grammar parameter #13699

Open
opened 2026-04-13 00:33:10 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/12055
Author: @sjsone
Created: 8/23/2025
Status: 🔄 Open

Base: mainHead: gbnf


📝 Commits (2)

  • 61705c5 gbnf: Added support for GBNF grammars in cli and server
  • a0747f2 Merge branch 'ollama:main' into gbnf

📊 Changes

4 files changed (+37 additions, -2 deletions)

View changed files

📝 api/types.go (+7 -1)
📝 cmd/cmd.go (+24 -1)
📝 llm/server.go (+4 -0)
📝 server/routes.go (+2 -0)

📄 Description

This change introduces a new request format GBNF so users can provide their own grammar to ollama.

Complementary to the new format the user has to provide the grammar. Either via a file when running ollama run or as a new parameter when issuing a server request.

CLI

ollama run --format GBNF --grammarfile test.gbnf qwen3:1.7b

Request

curl -X "POST" "http://localhost:11434/api/generate" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "model": "qwen3:1.7b",
  "prompt": "Hi",
  "grammar": "root ::= think-block \\"\\\\n\\\\n\\" answer-block\\n\\nthink-block ::= \\"<think>\\\\n\\" think-content \\"\\\\n</think>\\"\\n\\nanswer-block ::= \\"<answer>\\\\n\\" answer-content \\"\\\\n</answer>\\"\\nanswer-content ::= [^\\\\n]+ (\\"\\\\n\\" [^\\\\n]+)*\\n\\nthink-content ::= [^\\\\n]+ (\\"\\\\n\\" [^\\\\n]+)*",
  "format": "GBNF"
}'

🔄 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/12055 **Author:** [@sjsone](https://github.com/sjsone) **Created:** 8/23/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `gbnf` --- ### 📝 Commits (2) - [`61705c5`](https://github.com/ollama/ollama/commit/61705c5ef269201479771f226c4a8e35ac6cf868) gbnf: Added support for GBNF grammars in cli and server - [`a0747f2`](https://github.com/ollama/ollama/commit/a0747f2063348f9955614b3e6482e97a69d174d9) Merge branch 'ollama:main' into gbnf ### 📊 Changes **4 files changed** (+37 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `api/types.go` (+7 -1) 📝 `cmd/cmd.go` (+24 -1) 📝 `llm/server.go` (+4 -0) 📝 `server/routes.go` (+2 -0) </details> ### 📄 Description This change introduces a new request format `GBNF` so users can provide their own grammar to ollama. Complementary to the new format the user has to provide the grammar. Either via a file when running `ollama run` or as a new parameter when issuing a server request. ### CLI ```bash ollama run --format GBNF --grammarfile test.gbnf qwen3:1.7b ``` ### Request ```bash curl -X "POST" "http://localhost:11434/api/generate" \ -H 'Content-Type: application/json; charset=utf-8' \ -d $'{ "model": "qwen3:1.7b", "prompt": "Hi", "grammar": "root ::= think-block \\"\\\\n\\\\n\\" answer-block\\n\\nthink-block ::= \\"<think>\\\\n\\" think-content \\"\\\\n</think>\\"\\n\\nanswer-block ::= \\"<answer>\\\\n\\" answer-content \\"\\\\n</answer>\\"\\nanswer-content ::= [^\\\\n]+ (\\"\\\\n\\" [^\\\\n]+)*\\n\\nthink-content ::= [^\\\\n]+ (\\"\\\\n\\" [^\\\\n]+)*", "format": "GBNF" }' ``` --- <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-13 00:33:10 -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#13699