-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TypeAdapter support for JSON #1308
base: main
Are you sure you want to change the base?
Conversation
Thank you! Could you add some tests? |
I actually looked into adding a test, but found that the relevant test is skipped. So what would you suggest here? |
BTW, I guess this could also replace the recently added enum support from #1277, as you can just do something like: class Color(Enum):
RED = 1
BLUE = 2
generator = outlines.generate.json(model, TypeAdapter(Color)) |
Could you give me an example of how you would use this? |
My motivation was to generate a list of objects: class Transaction(BaseModel):
...
generator = outlines.generate.json(model, TypeAdapter(List[Transaction])) But one could use it for primitives as well. See for example the comment above for Enums. |
I wonder if there is a way to let users pass |
Sure, I could do that. But I don’t know if I would recommend it. While convenient, the function might become a bit hard to extend in the future or simply complex to define. Maybe there will be types you want to handle differently, maybe another library other than Pydantic will be added… But in the end it’s your decision.
|
You're probably right, we'll leave it as is for now. We just need to get to full coverage before merging! |
Happy to add tests, but please give me some guidance here. And should I remove the specific handling of the Enum type in favor of the TypeAdapter? |
Add support for pydantic TypeAdapter to allow schema objects to be generated from primitive types or lists for example (e.g.
TypeAdapter(List[Transaction])
).