Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Indeed.

Use trie constraint for quotes.

Use BNF for grammar languages (json, python etc).

Projects like llama.cpp/ollama should make it automatic/dynamic, just rely on triple quote sections where you enter those constraint modes automatically.

Ie. every time you enter into section starting with "```json" you automatically switch to JSON BNF.

Every time you enter into "```json:Foo" you enter JSON BNF + JSON-SCHEMA for Foo object definition.

"```python" for python grammar etc.

"```quote:documentRef" you enter trie based constraints.

"```llm:otherllm" you enter other llm.

"```whatever:whatever" you enter whatever you want.

If you want just json output you start output with "```json" and that's it.

As its all inference time it could be plugin based, ie:

1. character based - given input (from the start of opening "```foo") it returns allowed next characters, or

2. token based - same as above but returns allowed native tokens (not sure how performance would behave here, would it be acceptable?)

IMHO also very interesting area would be exploring stable AST representations for programming languages (a'la darklang I believe?) – where variable names are detached from AST itself, ie. differently named functions that otherwise have the same structure have precisely the same AST representation. This would dramatically reduce space to navigate around.

ps. [0] in case somebody else is interested

[0] https://github.com/ollama/ollama/issues/3019



Why have that issue on ollama instead of llama.cpp?


Because it's easier to pull off and experiment with it from ollama (ollama is just go wrapper around llama.cpp).

Llama.cpp could have upstream support for it but for them to consider it will have to be ironed out idea.

In llama.cpp support may have some different, more low level kind of support, I don't think it makes sense to attach state logic to text input there.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: