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

openai[minor]: release 0.3 #29100

Merged
merged 8 commits into from
Jan 10, 2025
Merged

openai[minor]: release 0.3 #29100

merged 8 commits into from
Jan 10, 2025

Conversation

ccurme
Copy link
Collaborator

@ccurme ccurme commented Jan 8, 2025

Goal

Solve the following problems with langchain-openai:

Breaking changes:

  • Default method for structured output is changing to OpenAI’s dedicated structured output feature. For schemas specified via TypedDict or JSON schema, strict schema validation is disabled by default but can be enabled by specifying strict=True.
    • To recover previous default, pass method="function_calling" into with_structured_output.
  • Models that don’t support method="json_schema" (e.g., gpt-4 and gpt-3.5-turbo, currently the default model for ChatOpenAI) will raise an error unless method is explicitly specified.
    • To recover previous default, pass method="function_calling" into with_structured_output.
  • Schemas specified via Pydantic BaseModel that have fields with non-null defaults or metadata (like min/max constraints) will raise an error.
    • To recover previous default, pass method="function_calling" into with_structured_output.
  • strict now defaults to False for method="json_schema" when schemas are specified via TypedDict or JSON schema.
    • To recover previous behavior, use with_structured_output(schema, strict=True)
  • Schemas specified via Pydantic V1 will raise a warning (and use method="function_calling") unless method is explicitly specified.
    • To remove the warning, pass method="function_calling" into with_structured_output.
  • Streaming with default structured output method / Pydantic schema no longer generates intermediate streamed chunks.
    • To recover previous behavior, pass method="function_calling" into with_structured_output.
  • We no longer override default temperature (was 0.7 in LangChain, now will follow OpenAI, currently 1.0).
    • To recover previous behavior, initialize ChatOpenAI or AzureChatOpenAI with temperature=0.7.
  • Note: conceptually there is a difference between forcing a tool call and forcing a response format. Tool calls may have more concise arguments vs. generating content adhering to a schema. Prompts may need to be adjusted to recover desired behavior.

Copy link

vercel bot commented Jan 8, 2025

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

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Jan 10, 2025 3:17pm

ccurme and others added 3 commits January 9, 2025 10:33
Should be accompanied by a minor bump

Should we also set `strict=True` by default?

---------

Co-authored-by: Bagatur <[email protected]>
Co-authored-by: ccurme <[email protected]>
@ccurme ccurme marked this pull request as ready for review January 9, 2025 19:43
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. 🤖:release Bumping package version for release labels Jan 9, 2025
Comment on lines +704 to +705
try:
with context_manager as response:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrapping this in try/except lets us catch errors from OpenAI SDK and make them more informative for langchain users

raise ValueError(
"This model does not support OpenAI's structured output "
"feature, which is the default method for "
"`with_structured_output` as of langchain-openai==0.3. To use "
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be raised without ever using with_structured_output, but afaik that is the only existing usage pattern that will raise it (I expect that most users of with_structured_output using default model will run into this).

@ccurme ccurme merged commit 6e63ccb into master Jan 10, 2025
115 checks passed
@ccurme ccurme deleted the openai_v0.3 branch January 10, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:release Bumping package version for release size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants