Repository navigation
Keep declaration order in Foundation Models schemas - #337
Conversation
Foundation Models generates an object's properties in its schema's order. The conversion went through JSONValue and JSONSchema, whose decoding loses key order, so properties reached the model shuffled: a container's items could come before what the container is, and generation ran away nesting. Convert straight from GenerationSchema's nodes, which keep propertyOrder.
|
Thanks, @akbashev. Converting straight from the nodes makes sense to me. One catch: with this change, the Two smaller things:
|
Converting from GenerationSchema's nodes, a named definition that is only a reference, such as a one-choice anyOf, dropped its name as the JSONSchema path did before huggingface#332, so the references to it were undefined. It now stays a named schema whose one choice is the reference. An integer's bounds become the whole numbers within them, and a bound no Int holds, such as a non-finite or very large one, sets no guide instead of trapping. The unused appearInOrder test helper is gone.
The stand-in value for a number with no usable output took Int(minimum), which traps on a minimum that isn't finite or that Int can't hold. It's now the smallest whole number the minimum allows, or the nearest Int when there's none; a stand-in decimal ignores a minimum that isn't finite.
|
Thanks, @mattt.
One question: the |
# Conflicts: # Tests/AnyLanguageModelTests/DynamicSchemaConversionTests.swift
|
Merged |
|
@akbashev Let's do that in a follow-up, so this PR stays focused on the ordering. |
Foundation Models generates an object's properties in the order its schema lists them. The conversion went through
JSONValueandJSONSchema, whose decoding loses key order, so properties reached the model shuffled. A container's items could come before what the container is, and generation ran away nesting.The conversion now goes straight from
GenerationSchema's nodes, which keeppropertyOrder.