Skip to content

feat(server): add a default completion grammar - #2455

Open
original4422 wants to merge 2 commits into
abetlen:mainfrom
original4422:feat/server-default-grammar
Open

original4422 wants to merge 2 commits into
abetlen:mainfrom
original4422:feat/server-default-grammar

Conversation

@original4422

Copy link
Copy Markdown

Summary

Add --grammar, GRAMMAR, and the top-level config grammar setting for ordinary /v1/completions requests. An explicit request grammar takes precedence.

completion grammar = request grammar, otherwise configured default

Refs #636. Chat completion grammar and response-format handling stay request-specific.

Evidence

  • Before: the original CLI rejects --grammar with 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 test with LLAMA_CPP_TEST_MODEL pointing to the local ggml-org stories15M-q4_0.gguf and PYTEST_ADDOPTS selecting test_server_grammar.py, test_llama_chat_format.py, test_llama_grammar.py and test_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-downloading test_llama.py suite, 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant