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[patch] get output_type when using with_structured_output #26307

Merged
merged 10 commits into from
Sep 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update base.py
Fix type checking errors by declaring that the schema is a Pydantic BaseModel at this point.
  • Loading branch information
liuhetian authored Sep 12, 2024
commit 8726283423c8610ae5cebaab64ad7fd088182696
3 changes: 2 additions & 1 deletion libs/partners/openai/langchain_openai/chat_models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,10 +1416,11 @@ class AnswerWithJustification(BaseModel):
strict = strict if strict is not None else True
response_format = _convert_to_openai_response_format(schema, strict=strict)
llm = self.bind(response_format=response_format)
pydantic_schema = cast(PydanticBaseModel, schema)
output_parser = (
cast(
Runnable,
_oai_structured_outputs_parser.with_types(output_type=schema),
_oai_structured_outputs_parser.with_types(output_type=pydantic_schema),
)
if is_pydantic_schema
else JsonOutputParser()
Expand Down