fix: 过滤 sse_starlette 返回的 ping 包,避免 `JSON Decoder error : ping -...` (#2585)
This commit is contained in:
parent
6f85119f03
commit
448c99f969
|
|
@ -73,7 +73,7 @@ class MiniMaxWorker(ApiModelWorker):
|
||||||
with response as r:
|
with response as r:
|
||||||
text = ""
|
text = ""
|
||||||
for e in r.iter_text():
|
for e in r.iter_text():
|
||||||
if not e.startswith("data: "): # 真是优秀的返回
|
if not e.startswith("data: "):
|
||||||
data = {
|
data = {
|
||||||
"error_code": 500,
|
"error_code": 500,
|
||||||
"text": f"minimax返回错误的结果:{e}",
|
"text": f"minimax返回错误的结果:{e}",
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,8 @@ class ApiRequest:
|
||||||
try:
|
try:
|
||||||
if chunk.startswith("data: "):
|
if chunk.startswith("data: "):
|
||||||
data = json.loads(chunk[6:-2])
|
data = json.loads(chunk[6:-2])
|
||||||
|
elif chunk.startswith(":"): # skip sse comment line
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
data = json.loads(chunk)
|
data = json.loads(chunk)
|
||||||
yield data
|
yield data
|
||||||
|
|
@ -169,6 +171,8 @@ class ApiRequest:
|
||||||
try:
|
try:
|
||||||
if chunk.startswith("data: "):
|
if chunk.startswith("data: "):
|
||||||
data = json.loads(chunk[6:-2])
|
data = json.loads(chunk[6:-2])
|
||||||
|
elif chunk.startswith(":"): # skip sse comment line
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
data = json.loads(chunk)
|
data = json.loads(chunk)
|
||||||
yield data
|
yield data
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue