You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Concerning the TypeAdapter constrained generation, here are some example of the issue mentioned here:
fromguidanceimportmodels, capturefromguidanceimportjsonasjjfrompydanticimportBaseModel, TypeAdapterimportjsonfromNoema.cfgimport*lm=models.LlamaCpp(
"../Models/Mistral-NeMo-Minitron-8B-Instruct.Q4_K_M.gguf",
n_gpu_layers=99,
n_ctx=512*8,
echo=False
)
lm.reset()
lm+="Generate a list of 3 integers between 1 and 4: "+capture(G.arrayOf(G.num()), name="generated_object")
print(lm["generated_object"])
# Output: ["1", "2", "3"]lm.reset()
schema=TypeAdapter(list[int])
lm+="Generate a list of 3 integers between 0 and 4: "+jj(name="generated_object", schema=schema)
print(json.loads(lm["generated_object"]))
# Output: []lm.reset()
lm+="Créé une liste des différentes étapes décrites ici: Ce matin je suis parti tot, puis j'ai acheté des pommes et enfin je suis allé au restaurant."+capture(G.arrayOf(G.sentence()), name="generated_object")
print(lm["generated_object"])
# Output: ["Ce matin je suis parti tot, puis j'ai acheté des pommes et enfin je suis allé au restaurant."]lm.reset()
schema=TypeAdapter(list[str])
lm+="Créé une liste des différentes étapes décrites ici: Ce matin je suis parti tot, puis j'ai acheté des pommes et enfin je suis allé au restaurant."+jj(name="generated_object", schema=schema)
print(json.loads(lm["generated_object"]))
# Output: []
I think that part of what you are encountering here is that lists aren't forced to be non-empty by default (I think your custom grammar definitions enforce a minimum length of one). If you want to enforce this behavior with TypeAdapters, you can use typing.Annotated and annotated_types.MinLen like so:
You can of course get this behavior by just writing the JSON schema directly, or if you're using a pydantic.BaseModel, you can do these annotations a bit more ergonomically with the pydantic.Field descriptor.
If this doesn't address the core issue you're seeing, just let me know and we can figure it out :)
Hi @hudson-ai!
Concerning the TypeAdapter constrained generation, here are some example of the issue mentioned here:
The file containing custom CFG is here.
This is just a workaround but it helps to produce a non empty list.
Concerning the JSON:
I'm not sure to understand what the expected generation is, but it seems that characters from the format are interfering with the generated content.
The text was updated successfully, but these errors were encountered: