by Yanael · 2y ago · 0 comments
To solve this problem I tried to define a spec and built a lib for it:
- [lib] https://github.com/st3w4r/openai-partial-stream/tree/main
- [spec] https://github.com/st3w4r/openai-partial-stream/blob/main/sp...
Why do you wait for the entire stream to be complete? Some objects in the JSON structure can be shown to be complete before the stream ends.
from pydantic_core import from_json
partial_json_data = '["aa", "bb", "c'
result = from_json(partial_json_data, allow_partial=True)
print(result)
#> ['aa', 'bb']
You can also use their `jiter` package directly if you don't otherwise use pydantic. https://github.com/pydantic/jiter/tree/main/crates/jiter-pyt...