File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 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:
9898
9999
100100def 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:" ):
106102 if line .startswith (b"data: " ):
103+ # SSE event may be valid when it contain whitespace
107104 line = line [len (b"data: " ):]
108- return line .decode ("utf-8" )
109105 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
110110 return None
111+ else :
112+ return line .decode ("utf-8" )
111113 return None
112114
113115
You can’t perform that action at this time.
0 commit comments