microsoft / TypeChat

TypeChat is a library that makes it easy to build natural language interfaces using types.
https://microsoft.github.io/TypeChat/
MIT License
8.25k stars 391 forks source link

Python usability -- plain classes instead of TypedDict #243

Closed gvanrossum closed 7 months ago

gvanrossum commented 7 months ago

It's inconvenient and un-Pythonic to have to make everything a TypedDict. The natural way to describe a Python schema would be to use a plain class or a dataclass. Pydantic classes should also work. All these have in common that the data, when being manipulated by a Python program, looks and feels like a Python object rather than a Python dict. For example, to construct an object, you would write something like

p = Point(x=10, y=42)

instead of

p = {'type': 'Point', 'x': 10, 'y': 42}

I believe that Pydantic is able to take in JSON and turn it into a Python object for consumption by Python code, and it does the validation as it is doing the conversion.

I would also like not to have to explicitly add the

    type: Literal["Point"]

declaration to the Point class.

gvanrossum commented 7 months ago

I withdraw this. It seems you can use dataclasses just fine.