-
Notifications
You must be signed in to change notification settings - Fork 19
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
Added the isjsonvalid() and the wordstream() functions #52
base: main
Are you sure you want to change the base?
Conversation
Hey Alex, thanks for the PR! I'm getting caught up after a hectic couple weeks. Will take a look by the end of today |
Out of curiousity, what is the use case here? What would be the advantages of implementing it? It seems that it basically parses JSON twice anyway, once inside a try-catch (in isvalidjson) and then when actually parsing. What is the advantage over just having the try-catch around the parsing itself? Side note: perhaps you could disable your formatter to only change the proposed functionality? There are a few places picked up by the diff where only spaces have changed. |
Thank you for the insight, @svilupp! I'm thinking of a "default" streamcallback function for word-by-word streaming that would be very useful for a user for a number of reasons. Crafting such a function is not straightforward, as the data stream isn't just a series of JSON-parsable objects prefixed with "Data:". The stream may split, with a packet starting mid-way through an object from the previous packet. You're correct about the double JSON parsing; there might indeed be a more efficient method to verify if the input is JSON before continuing with the wordstream() function. Also, I appreciate your feedback on the formatter—I'll definitely keep that in mind! |
Apologies for the slow response! Would you mind outlining some of the use cases for building JSONs on the fly as they are getting streamed? I lack imagination and I tend to associate streaming with nicer UX design for chat interfaces. Are you thinking of some other use case? I'm not very familiar with the functionality, so I'd appreciate if you could capture a few key test cases and codify them in the test set. It will help us prevent any future regressions and it will help with onboarding new devs, because they'll see a practical example. |
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.
I like the PR and think we should merge it in. I left two comments I hope we can incorporate to make it a little more obvious how this stuff works.
isvalidjson(str) = | ||
try | ||
JSON3.read(str) | ||
true | ||
catch | ||
false | ||
end |
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.
Minor note but I typically prefer function ... end
syntax for multiline functions.
isvalidjson(str) = | |
try | |
JSON3.read(str) | |
true | |
catch | |
false | |
end | |
function isvalidjson(str) | |
try | |
JSON3.read(str) | |
true | |
catch | |
false | |
end | |
end |
""" | ||
Default streamcallback function for create_<action> functions. | ||
""" |
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.
Could you add a little usage section here to show how people should use this?
Perhaps we should learn from what others are doing? Langchain:
|
Hi there!
You might want to consider adding a default wordstream() function. The function parses the stream and it seems to work as is. If you think it is ok, I could also contribute to the docu of the function.
Regards.
Alex