pytorch / serve

Serve, optimize and scale PyTorch models in production
https://pytorch.org/serve/
Apache License 2.0
4.15k stars 837 forks source link

Ability to return Pydantic Models #3255

Open mhashas opened 1 month ago

mhashas commented 1 month ago

🚀 The feature

It would be great for type-hints to be able to return pydantic models. It would just require a check in serializability, if instance pydantic model -> use pydantic function for serializing.

Motivation, pitch

Better type hints, cleaner code, solving hate in the world as we can all agree that pydantic data classes are vastly superior.

Alternatives

No response

Additional context

No response

mreso commented 3 weeks ago

Hi @mhashas sorry for not getting to this sooner. Could you please give a bit more details on how you image that integration? We're using pydantic dataclasses for our vllm engine integration here. I am not 100% what your proposal would mean. Do you mean we automatically serialize outside the handler if the return value is a pydantic dataclass?