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

core: pydantic output parser streaming fix #24415

Merged
merged 15 commits into from
Aug 23, 2024

Conversation

efriis
Copy link
Member

@efriis efriis commented Jul 18, 2024

No description provided.

Copy link

vercel bot commented Jul 18, 2024

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 Aug 23, 2024 0:20am

@efriis efriis added the partner label Jul 18, 2024
@efriis efriis self-assigned this Jul 18, 2024
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. langchain Related to the langchain package Ɑ: parsing Related to output parser module 🤖:improvement Medium size change to existing code to handle new use-cases labels Jul 18, 2024
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to core tests

Comment on lines 161 to 186
def test_pydantic_output_parser_stream() -> None:
"""Test PydanticOutputParser in a streaming sequence."""

class Person(BaseModel):
name: str
age: int

def llm(input: Any) -> Iterable[str]:
yield from [
"{",
'"name": "',
"King",
" Louis",
' XVI"',
', "age": 3',
"8}",
]

parser = PydanticOutputParser(pydantic_object=Person)
chain = llm | parser
assert chain.invoke({}) == Person(name="King Louis XVI", age=38)
stream_result = list(chain.stream({}))
assert stream_result == [
Person(name="King Louis XVI", age=3),
Person(name="King Louis XVI", age=38),
]
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the new case

Copy link

Choose a reason for hiding this comment

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

lgtm

Comment on lines 183 to 186
assert stream_result == [
Person(name="King Louis XVI", age=3),
Person(name="King Louis XVI", age=38),
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

why isn't name streamed

Copy link
Member Author

Choose a reason for hiding this comment

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

because before there's any age, it doesn't comply to pydantic schema (requires int age)

@ccurme ccurme added Ɑ: core Related to langchain-core and removed langchain Related to the langchain package labels Jul 26, 2024
@efriis efriis merged commit 6096c80 into master Aug 23, 2024
96 checks passed
@efriis efriis deleted the erick/core-pydantic-output-parser-streaming-fix branch August 23, 2024 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: core Related to langchain-core 🤖:improvement Medium size change to existing code to handle new use-cases Ɑ: parsing Related to output parser module partner size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants