-
Notifications
You must be signed in to change notification settings - Fork 212
Open
Labels
Description
There is a number of issues when using a Dataclass type constraint with a List[str]
property.
Using this example:
@lmql.query(max_len=200)
async def example():
'''lmql
from dataclasses import dataclass
from typing import List
@dataclass
class State:
tasks: List[str]
role: str
argmax
"""
Goal: Produce a list of tasks to make a ham sandwich
The best role to solve this goal is [ROLE]
Give your answer in the following JSON format, the JSON must be parseable by Python json.loads(<json string>):
{{ "tasks" : [["task 1", "task 2", ... "task N" ]] }}
Answer:
[STATE]
"""
where
type(STATE) is State
and STOPS_BEFORE(ROLE, '\n')
# and STOPS_BEFORE(STATE, '\n')
'''
lmql will appear to hang until maximum tokens is reached, printing context.prompt
in the types.py stack pop while loop shows an output that looks like this:
Goal: Produce a list of tasks to make a ham sandwich
The best role to solve this goal is
Give your answer in the following JSON format, the JSON must be parseable by Python json.loads(<json string>):
{ "tasks" : ["task 1", "task 2", ... "task N" ] }
then
(continue in JSON) {"tasks":"Gather the ingredients: bread, ham, lettuce, tomato, mayonnaise, butter, knife.\nSpread butter on one side of each slice of bread.\nPlace the ham on one slice of bread.\nTop the ham with lettuce and tomato.\nSpread mayonnaise on the other slice of bread.\nPut the two slices of bread together.\nCut the sandwich in half.\nEnjoy!","}","","","","","","",
or
(continue in JSON) {"tasks":"Gather the ingredients: bread, ham, cheese, lettuce, tomato, mayonnaise, butter, knife.","Spread butter on one side of each slice of bread.","Lay one slice of bread, butter side down, on a plate.","Layer ham, cheese, lettuce, and tomato on the bread.","Spread mayonnaise on the other slice of bread.","Place the other slice of bread, mayonnaise side down, on top of the sandwich.","Cut the sandwich in half.","Enjoy!","","","","","","","","",
At this point I halt the program because:
"",
repeats indefinitely, until the max token length is reached.- the output misses the the square brackets for the array.
- sometimes the list is not separated by
","
and is instead encapsulated in a string and separated by\n
Other projects that solve JSON structure that lqml's dataclass type constraint requires are