File tree 1 file changed +8
-6
lines changed
1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -98,16 +98,18 @@ def _make_session() -> requests.Session:
98
98
99
99
100
100
def parse_stream_helper (line : bytes ) -> Optional [str ]:
101
- if line :
102
- if line .strip () == b"data: [DONE]" :
103
- # return here will cause GeneratorExit exception in urllib3
104
- # and it will close http connection with TCP Reset
105
- return None
101
+ if line and line .startswith (b"data:" ):
106
102
if line .startswith (b"data: " ):
103
+ # SSE event may be valid when it contain whitespace
107
104
line = line [len (b"data: " ):]
108
- return line .decode ("utf-8" )
109
105
else :
106
+ line = line [len (b"data:" ):]
107
+ if line .strip () == b"[DONE]" :
108
+ # return here will cause GeneratorExit exception in urllib3
109
+ # and it will close http connection with TCP Reset
110
110
return None
111
+ else :
112
+ return line .decode ("utf-8" )
111
113
return None
112
114
113
115
You can’t perform that action at this time.
0 commit comments