-
-
Notifications
You must be signed in to change notification settings - Fork 602
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
Labels
enhancement
New feature or request
Comments
Happy to take or for this in process response. |
@ADR-007 just pushed up a PR which introduces this. Is this what you had in mind for your use case? from typing_extensions import TypedDict
from openai import OpenAI
import instructor
class User(TypedDict):
name: str
age: int
client = instructor.from_openai(OpenAI())
print(
client.chat.completions.create(
model="gpt-3.5-turbo",
response_model=User,
messages=[
{
"role": "user",
"content": "Timothy is a man from New York who is turning 32 this year",
}
],
)
)
"""
name='Timothy' age=32
""" |
@ivanleomk yes, thank you! |
Oh. That PR is not yet merged, so I should leave this issue open |
I would really like to have this implemented. It is currently the only thing that blocks me from using this library :( |
we're close! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.:
It is very simple to implement in Pydantic V2:
The text was updated successfully, but these errors were encountered: