[PR #8123] [CLOSED] llm/grammar: introduce new grammar package #74928

Closed
opened 2026-05-05 07:15:21 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/8123
Author: @bmizerany
Created: 12/16/2024
Status: Closed

Base: mainHead: bmizerany/grammers


📝 Commits (1)

  • 0de52bc grammar: introduce new grammar package

📊 Changes

5 files changed (+601 additions, -0 deletions)

View changed files

grammar/bench_test.go (+22 -0)
grammar/grammar.go (+219 -0)
grammar/grammar_test.go (+92 -0)
grammar/jsonschema/decode.go (+166 -0)
grammar/jsonschema/decode_test.go (+102 -0)

📄 Description

This package provides a way to convert JSON schemas to equivalent EBNF. It is intended to be a replacement to llama.cpp's schema_to_grammar.

This is still an early version and does not yet support all JSON schema features. The to-do list includes:

  • minumum/maximum constraints on integer types
  • minLength/maxLength constraints on string types
  • defs and refs
  • performance improvements once we're happy with correctness and feature set.

NOTE: This also fixes outstanding issues caused by llama.cpp's schema_to_grammer; specifically that it does not maintain order of object keys in the schema when producing the resulting ebnf.

Owning our own converter allows us to have more control over bug prevention, speed, and accuracy of conversions, and removes yet another C dependency.


🔄 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/8123 **Author:** [@bmizerany](https://github.com/bmizerany) **Created:** 12/16/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `bmizerany/grammers` --- ### 📝 Commits (1) - [`0de52bc`](https://github.com/ollama/ollama/commit/0de52bcde2e3227c4bb11ed8f794a71a8d8cb665) grammar: introduce new grammar package ### 📊 Changes **5 files changed** (+601 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `grammar/bench_test.go` (+22 -0) ➕ `grammar/grammar.go` (+219 -0) ➕ `grammar/grammar_test.go` (+92 -0) ➕ `grammar/jsonschema/decode.go` (+166 -0) ➕ `grammar/jsonschema/decode_test.go` (+102 -0) </details> ### 📄 Description This package provides a way to convert JSON schemas to equivalent EBNF. It is intended to be a replacement to llama.cpp's schema_to_grammar. This is still an early version and does not yet support all JSON schema features. The to-do list includes: - minumum/maximum constraints on integer types - minLength/maxLength constraints on string types - defs and refs - performance improvements once we're happy with correctness and feature set. NOTE: This also fixes outstanding issues caused by llama.cpp's schema_to_grammer; specifically that it does not maintain order of object keys in the schema when producing the resulting ebnf. Owning our own converter allows us to have more control over bug prevention, speed, and accuracy of conversions, and removes yet another C dependency. --- <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-05-05 07:15:21 -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#74928