File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -188,18 +188,20 @@ def extract_chunk_str(self, chunk_str):
188
188
if chunk_str == "data: [DONE]\n \n " :
189
189
return ""
190
190
prefix = "data: b'"
191
+ prefix_2 = 'data: b"'
191
192
suffix = "'\n \n "
192
- if chunk_str .startswith (prefix ):
193
+ suffix_2 = '"\n \n '
194
+ if chunk_str .startswith (prefix ) or chunk_str .startswith (prefix_2 ):
193
195
chunk_str = chunk_str [len (prefix ) :]
194
- if chunk_str .endswith (suffix ):
196
+ if chunk_str .endswith (suffix ) or chunk_str . endswith ( suffix_2 ) :
195
197
chunk_str = chunk_str [: - len (suffix )]
196
198
return chunk_str
197
199
198
200
def token_generator (self , sentence , is_last = False ):
199
201
prefix = "data: "
200
202
suffix = "\n \n "
201
- tokens = re .findall (r"\S+\s?" , sentence , re .UNICODE )
203
+ tokens = re .findall (r"\s?\ S+\s?" , sentence , re .UNICODE )
202
204
for token in tokens :
203
- yield prefix + repr (token .encode ("utf-8" )) + suffix
205
+ yield prefix + repr (token .replace ( " \\ n" , " \n " ). encode ("utf-8" )) + suffix
204
206
if is_last :
205
207
yield "data: [DONE]\n \n "
You can’t perform that action at this time.
0 commit comments