Tolerate common malformed VLM inventory JSON
This commit is contained in:
@@ -27,6 +27,20 @@ class ClothingLayoutPlannerTests(unittest.TestCase):
|
||||
}) + "\n```")
|
||||
self.assertEqual(items[0]["description"], "blue linen")
|
||||
|
||||
def test_repairs_literal_newlines_and_unescaped_prose_quotes(self):
|
||||
raw = '{"items":[{"id":"shirt","name":"shirt","description":"Blue shirt\nwith a "soft" collar"}]}'
|
||||
items = PLANNER.normalize_inventory(raw)
|
||||
self.assertEqual(items[0]["description"], 'Blue shirt\nwith a "soft" collar')
|
||||
|
||||
def test_repairs_truncated_vlm_json_by_closing_open_containers(self):
|
||||
raw = '{"items":[{"id":"shoe","name":"shoe","description":"Black leather'
|
||||
items = PLANNER.normalize_inventory(raw)
|
||||
self.assertEqual(items[0]["description"], "Black leather")
|
||||
|
||||
def test_ignores_vlm_prose_after_json_object(self):
|
||||
raw = inventory({"id": "hat", "name": "hat"}) + "\nHere is the inventory."
|
||||
self.assertEqual(PLANNER.normalize_inventory(raw)[0]["id"], "hat")
|
||||
|
||||
def test_quantities_and_pairs_create_deterministic_instances(self):
|
||||
plan = PLANNER.plan_layout(inventory(
|
||||
{"id": "sock", "name": "sock", "quantity": 3},
|
||||
|
||||
Reference in New Issue
Block a user