openai-python
openai-python copied to clipboard
Fixed CLI streamed chat completions.
Streamed chat completions use a different response structure vs non-streamed, i.e. deltas, which caused KeyError exceptions. Also these token deltas may have roles, and there may be empty deltas at the end of a completion. Handle these cases sensibly without breaking the non-streamed path.
I manually tested both the streamed and non-streamed paths, but no unit tests, sorry, was busy.