fix unpacking
This commit is contained in:
@@ -40,8 +40,8 @@ def decode_chunk(chunk):
|
|||||||
"""
|
"""
|
||||||
chunk = chunk.decode()
|
chunk = chunk.decode()
|
||||||
respose = ""
|
respose = ""
|
||||||
finish_reason = "False"
|
|
||||||
reasoning_content = ""
|
reasoning_content = ""
|
||||||
|
finish_reason = "False"
|
||||||
try:
|
try:
|
||||||
chunk = json.loads(chunk[6:])
|
chunk = json.loads(chunk[6:])
|
||||||
except:
|
except:
|
||||||
@@ -62,16 +62,16 @@ def decode_chunk(chunk):
|
|||||||
respose = chunk["choices"][0]["delta"]["content"]
|
respose = chunk["choices"][0]["delta"]["content"]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
try:
|
|
||||||
finish_reason = chunk["choices"][0]["finish_reason"]
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
try:
|
try:
|
||||||
if chunk["choices"][0]["delta"]["reasoning_content"] is not None:
|
if chunk["choices"][0]["delta"]["reasoning_content"] is not None:
|
||||||
reasoning_content = chunk["choices"][0]["delta"]["reasoning_content"]
|
reasoning_content = chunk["choices"][0]["delta"]["reasoning_content"]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return respose, finish_reason, reasoning_content
|
try:
|
||||||
|
finish_reason = chunk["choices"][0]["finish_reason"]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return respose, reasoning_content, finish_reason
|
||||||
|
|
||||||
|
|
||||||
def generate_message(input, model, key, history, max_output_token, system_prompt, temperature):
|
def generate_message(input, model, key, history, max_output_token, system_prompt, temperature):
|
||||||
@@ -211,10 +211,7 @@ def get_predict_function(
|
|||||||
break
|
break
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
chunk = next(stream_response) # 失败了,重试一次?再失败就没办法了。
|
chunk = next(stream_response) # 失败了,重试一次?再失败就没办法了。
|
||||||
if reasoning:
|
response_text, reasoning_content, finish_reason = decode_chunk(chunk)
|
||||||
response_text, finish_reason, reasoning_content = decode_chunk(chunk)
|
|
||||||
else:
|
|
||||||
response_text, finish_reason = decode_chunk(chunk)
|
|
||||||
# 返回的数据流第一次为空,继续等待
|
# 返回的数据流第一次为空,继续等待
|
||||||
if response_text == "" and (reasoning == False or reasoning_content == "") and finish_reason != "False":
|
if response_text == "" and (reasoning == False or reasoning_content == "") and finish_reason != "False":
|
||||||
continue
|
continue
|
||||||
@@ -353,10 +350,7 @@ def get_predict_function(
|
|||||||
break
|
break
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
chunk = next(stream_response) # 失败了,重试一次?再失败就没办法了。
|
chunk = next(stream_response) # 失败了,重试一次?再失败就没办法了。
|
||||||
if reasoning:
|
response_text, reasoning_content, finish_reason = decode_chunk(chunk)
|
||||||
response_text, finish_reason, reasoning_content = decode_chunk(chunk)
|
|
||||||
else:
|
|
||||||
response_text, finish_reason = decode_chunk(chunk)
|
|
||||||
# 返回的数据流第一次为空,继续等待
|
# 返回的数据流第一次为空,继续等待
|
||||||
if response_text == "" and (reasoning == False or reasoning_content == "") and finish_reason != "False":
|
if response_text == "" and (reasoning == False or reasoning_content == "") and finish_reason != "False":
|
||||||
status_text = f"finish_reason: {finish_reason}"
|
status_text = f"finish_reason: {finish_reason}"
|
||||||
|
|||||||
Reference in New Issue
Block a user