Open KristianMischke opened 11 months ago
I just pushed a fix to main
which resolves it. Thanks for reporting it, @dataclass
support is still in Preview, so this kind of feedback is very helpful.
@lbeurerkellner Awesome, thanks for that! Do you have an official ingress for feedback?
Because I think that @dataclass
support is super powerful, but could use some enhancements:
Optional[]
fields (not forcing the llm to generate the field)Literal[]
fields (especially literal of different string values to be able to have more control over the values of the fields, e.g. Literal["red", "blue", "yellow"]
)@lmql.field()
that could specify restrictions for the field in LMQL syntax, which would be very powerful as it could support the above examples plus regex, etcI could imagine something like this perhaps
@dataclass
class MyClass:
@lmql.field("""where classification in ["positive", "negative", "neutral"]""")
classification: str
All of these things can already be done if writing a prompt formatted in JSON for example, and then writing the python code to convert the JSON object to python. So using @dataclasses
is really convenient compared to writing a JSON prompt and doing the conversion because it's already in the target format
I've been loving the dataclass parsing features, but I ran into this issue where the library errors when parsing string values that contain double-quotes or newline characters
This is my dataclass and the query that is used:
This is an example culprit value for
card_text
:This was printed to the console. And you can see the newlines in the
rules
field that is likely the issue.Then this exception was thrown: