-
Notifications
You must be signed in to change notification settings - Fork 15.9k
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
feat(openai): Update with_structured_output default for OpenAI #28947
base: openai_v0.3
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -1310,6 +1325,24 @@ class Joke(BaseModel): | |||
joke_result = chat.invoke("Give me a joke about cats, include the punchline.") | |||
assert isinstance(joke_result, Joke) | |||
|
|||
# Schema |
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.
These new tests fail unless strict
is False.
#29075 is a hack (?) that will pass them if strict
is True. But strict=True
will break things in other ways (e.g., schemas with nested TypedDicts).
@property | ||
def structured_output_kwargs(self) -> dict: | ||
return {"method": "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.
Added this property to chat model standard tests. Azure legacy model tests don't support method="json_schema"
.
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 we actually want this to be configurable, or should we just have standard tests test the default?
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.
TestAzureOpenAIStandardLegacy
breaks with default. Seems wasteful to xfail its structured output tests instead of running them with the supported method. Can also delete TestAzureOpenAIStandardLegacy
but that didn't feel great either. lmk if there are other options.
Integration tests pass: https://github.com/langchain-ai/langchain/actions/runs/12678107252 |
@property | ||
def structured_output_kwargs(self) -> dict: | ||
return {"method": "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 we actually want this to be configurable, or should we just have standard tests test the default?
("model", "method", "strict"), | ||
[("gpt-4o", "function_calling", True), ("gpt-4o-2024-08-06", "json_schema", None)], | ||
("model", "method"), | ||
[("gpt-4o", "function_calling"), ("gpt-4o-2024-08-06", "json_schema")], |
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.
given strict is passed in should this still test both?
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.
strict
defaults to False, so most other tests cover it. I added some "invalid" schemas to the standard test as well (test_structured_output_optional_param
) to add coverage there.
Should be accompanied by a minor bump
Should we also set
strict=True
by default?