Repository navigation
feat(server): add a default completion grammar - #2455
Open
original4422 wants to merge 2 commits into
Open
original4422 wants to merge 2 commits into
original4422 wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
--grammar,GRAMMAR, and the top-level configgrammarsetting for ordinary/v1/completionsrequests. An explicit request grammar takes precedence.Refs #636. Chat completion grammar and response-format handling stay request-specific.
Evidence
--grammarwith exit 2. Original per-request native grammar controls already work.After: actual CLI, environment and JSON-config servers apply the default; explicit request overrides, no-default behavior and SSE output pass eight real HTTP/native cases.
make testwithLLAMA_CPP_TEST_MODELpointing to the local ggml-orgstories15M-q4_0.ggufandPYTEST_ADDOPTSselectingtest_server_grammar.py,test_llama_chat_format.py,test_llama_grammar.pyandtest_llama_speculative.py: 17 passed, no skips. The new suite contributes 11 cases; native cases opt in through that environment variable and never download weights.make lint: Ruff checks and formatting pass for all 30 Python source/test files.Validated on macOS arm64, Python 3.12.14, vendored llama.cpp
f5e6915c2,n_gpu_layers=0, using real model execution without constructor/request mocks. The model-downloadingtest_llama.pysuite, GPU platforms and performance were not tested.Implemented and reviewed by Codex as the author's authorized agent.
Merge Danger
Door: two-way
Blast Radius: server
The setting is optional and only affects ordinary completions when their request omits a grammar.