[PR #2404] [CLOSED] Add GBNF grammar support #10879

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

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/2404
Author: @jquesnelle
Created: 2/8/2024
Status: Closed

Base: mainHead: grammar


📝 Commits (1)

📊 Changes

4 files changed (+42 additions, -0 deletions)

View changed files

📝 api/types.go (+1 -0)
📝 docs/modelfile.md (+1 -0)
examples/grammar/Modelfile (+39 -0)
📝 llm/dyn_ext_server.go (+1 -0)

📄 Description

This is an updated version of #1606 that accounts for changes to the code since it was originally submitted.

Adds support for llama.cpp's GBNF grammars, which enable very specific steering of model outputs. This feature is already used on the backend by when the format option is set to json, but this allows any arbitrary grammar to be passed in. In the case where both grammar and format are specified, the format is preferred.


🔄 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/2404 **Author:** [@jquesnelle](https://github.com/jquesnelle) **Created:** 2/8/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `grammar` --- ### 📝 Commits (1) - [`bbc9b49`](https://github.com/ollama/ollama/commit/bbc9b49dd0dab2ddf08158989eeb747e6644d12a) add GBNF grammar support ### 📊 Changes **4 files changed** (+42 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `api/types.go` (+1 -0) 📝 `docs/modelfile.md` (+1 -0) ➕ `examples/grammar/Modelfile` (+39 -0) 📝 `llm/dyn_ext_server.go` (+1 -0) </details> ### 📄 Description This is an updated version of #1606 that accounts for changes to the code since it was originally submitted. Adds support for llama.cpp's GBNF grammars, which enable very specific steering of model outputs. This feature is already used on the backend by when the `format` option is set to `json`, but this allows any arbitrary grammar to be passed in. In the case where both `grammar` and `format` are specified, the `format` is preferred. --- <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:14:04 -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#10879