Skip to content

how to write a dynamic json output parser chain #439

Answered by eyurtsev
shaojun asked this question in Q&A
Discussion options

You must be logged in to vote

You can do something like this for streaming support. Things might not be rendered nicely in the playground (not sure).

Alternatively, you can use APIHandler directly (see those examples) to create a runnable and then stream from it.

I don't believe that this will stream well because it uses a pydantic parser which doesn't operate on input stream. See details here: https://python.langchain.com/docs/expression_language/streaming.

Your options are to do something with stream_events endpoint instead which will yield chunks from the model.

Another option is to try to use JSONParser and then follow up with a custom parser that uses the pydantic model to parse the json once its complete.

import j…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@shaojun
Comment options

@eyurtsev
Comment options

@shaojun
Comment options

@shaojun
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by eyurtsev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #438 on February 02, 2024 21:06.