-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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
core: pydantic output parser streaming fix #24415
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
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.
moved to core tests
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), | ||
] |
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.
this is the new case
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.
lgtm
assert stream_result == [ | ||
Person(name="King Louis XVI", age=3), | ||
Person(name="King Louis XVI", age=38), | ||
] |
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.
why isn't name streamed
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.
because before there's any age, it doesn't comply to pydantic schema (requires int age)
No description provided.