Open donren-leung opened 9 months ago
Well half of the problem is that type_schema(t)
in lib/types.py is looking for the built-in str
and int
- if you want to evaluate types agnostic of built-in vs forward references, try typing.get_type_hints
instead?
But on the problem of recursive objects, I think with the way type_schema(t) in lib/types.py is written which only stops at int
, str
or a dict/list of these, any recursive typing will loop infinitely. Maybe (G)BNF is the way to go, like what llama cpp has done? https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md
Thanks for reporting this, the resources and pointers. Types are currently in preview, so we are definitely not fully there yet, with respect to reliability and features. Indeed non-deterministic branching as enabled by BNF grammars is something that could help here. I will try to have a closer look soon.
On both lmql versions 0.7b3 and commit 3555b, (with python 3.10.9 and WSL2 linux) I can't get recursive objects to work, i.e. when the type of one of the properties is itself. Is this issue known, and are there any plans?
I took inspiration from the regex demo on the latest build playground regarding Alice working at a company. I want the LLM to describe a person in JSON form - not only that but also contrained to the Person dataclass, which also has property children that is a list of more Person objects. I'm sure you can see this has use cases for trees, graphs etc.
With children commented out, this can run fine.
But when I try to add the children property and query about it:
It says the type is not supported in any way I try to define children.
Here is the traceback for both versions in case you're interested
Version 0.7b3 w/ TypeVar('Person') ``` Traceback (most recent call last): File "/home/user/learn/Connections-LLM/lmlq/getting_started2.py", line 66, in