-
Notifications
You must be signed in to change notification settings - Fork 21
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 with_structured_output support for Pydantic models, dicts and Enum #79
Conversation
…ms (only include_raw=False)
*, | ||
method: Literal["function_calling", "json_mode"] = "function_calling", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand this correctly, and we decided to remove the ability to specify method?
https://python.langchain.com/v0.2/docs/how_to/structured_output/#advanced-specifying-the-method-for-structuring-outputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'method' parameter is unnecessary and is ignored. The appropriate method will be chosen automatically depending on the type of schema provided.
we could enhance this by letting users force a particular implementation, but not all implementations will work with all input types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be wrong, but specifying JSON mode should force it output JSON regardless. Also this would be consistent with broader lc usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the method
param effectively requires the user to pick the implementation that is used to achieve their desired outcome of json or pydantic responses from invoke
/stream
. we can do better than requiring the user to pick.
also, https://python.langchain.com/v0.2/docs/how_to/structured_output/#advanced-specifying-the-method-for-structuring-outputs
"JSON mode" asserts it will not pass the schema to the model, but we will pass the schema to the model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok sgtm!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mattf!
Bind a structured output schema to the model.
The schema can be -
0. a dictionary representing a JSON schema
1. a Pydantic object
2. an Enum
Example:
an Enum object. Example:
Note about streaming: Unlike other streaming responses, the streamed chunks
will be increasingly complete. They will not be deltas. The last chunk will
contain the complete response.
For instance with a dictionary schema, the chunks will be:
For instnace with a Pydantic schema, the chunks will be:
For Pydantic schema and Enum, the output will be None if the response is
insufficient to construct the object or otherwise invalid. For instance,