acsresearch / interlab

MIT License
17 stars 3 forks source link

DRAFT First try (NOW WORKING!) to migrate to Pydantic v2 #67

Open spirali opened 5 months ago

spirali commented 5 months ago

This is my try to migrate to Pydantic v2 API.

I am now able to create a JSON schema from dataclasses but schema did not pass the tests (because of JSON reference solving?) and it is not clear to me what it should exactly do. @gavento can you check this please?

spirali commented 5 months ago

This relates to #66

gavento commented 5 months ago

Thanks for the PR! I won't be able to dig in into the code in the next few days.

Some quick guesses based on the failed tests, though:

Based on the error:

>       assert sch == json.loads(B_SCHEMA_DEREF_FULL)
E       AssertionError: assert {'$defs': {'A...pe': 'object'} == {'properties'...pe': 'object'}

... it seems that json_schema.get_json_schema does not produce a "clean" json schema, but leaves some $defs and references. In my experience, LLMs are best at answering "dereferenced" JSON schemas. Maybe check what happens in deref_jsonref?

But based on the next error:

>       assert query_for_json_ex(test_model, Foo, "TEST_A") == Foo(z=False)
E       AssertionError: assert Foo(z='0', x=0, y=None) == Foo(z=False, x=0, y=None)

... something else may be going on as well with pydantic, as Foo.z is declared as having type bool in the dataclass, so it should never come out as str here.