Skip to content
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

Any valid Pydantic type should be supported (e.g. TypedDict) #627

Open
ADR-007 opened this issue Apr 24, 2024 · 1 comment
Open

Any valid Pydantic type should be supported (e.g. TypedDict) #627

ADR-007 opened this issue Apr 24, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@ADR-007
Copy link

ADR-007 commented Apr 24, 2024

Is your feature request related to a problem? Please describe.
Currently, only Pydantic models are supported as response_model.
But in some cases, I want to use TypedDict instead. For example, I don't want to do massive refactoring, so I just want to add response schema validation to an existing job.

Describe the solution you'd like
I would like to able to use TypedDict as response_model. E.g.:

class MyModel(TypedDict):
    my_key: str

result = client.chat.completions.create(
    messages=[...],
    response_model=MyModel,
)

It is very simple to implement in Pydantic V2:

from pydantic import TypeAdapter

adapter = TypeAdapter(MyModel)
json_schema = adapter.json_schema()

result = prcess_llm(prompt, json_schema, ...)

my_model = adapter.validate_python(result)
@dosubot dosubot bot added the enhancement New feature or request label Apr 24, 2024
@jxnl
Copy link
Owner

jxnl commented Apr 24, 2024

Happy to take or for this in process response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants