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

feat(openai): Update with_structured_output default for OpenAI #28947

Open
wants to merge 17 commits into
base: openai_v0.3
Choose a base branch
from

Conversation

jacoblee93
Copy link
Contributor

@jacoblee93 jacoblee93 commented Dec 27, 2024

Should be accompanied by a minor bump

Should we also set strict=True by default?

Copy link

vercel bot commented Dec 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 4:42pm

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Dec 27, 2024
@jacoblee93 jacoblee93 requested a review from baskaryan December 27, 2024 23:36
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Dec 28, 2024
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Dec 28, 2024
@ccurme ccurme changed the base branch from master to openai_v0.3 January 8, 2025 16:26
@@ -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
Copy link
Collaborator

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).

Comment on lines +58 to +60
@property
def structured_output_kwargs(self) -> dict:
return {"method": "function_calling"}
Copy link
Collaborator

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".

Copy link
Member

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?

Copy link
Collaborator

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.

@ccurme
Copy link
Collaborator

ccurme commented Jan 8, 2025

Comment on lines +58 to +60
@property
def structured_output_kwargs(self) -> dict:
return {"method": "function_calling"}
Copy link
Member

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")],
Copy link
Member

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?

Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
Status: Internal
Development

Successfully merging this pull request may close these issues.

4 participants