ChuanhuChatGPT icon indicating copy to clipboard operation
ChuanhuChatGPT copied to clipboard

Json解析错误解决方法

Open lthero-big opened this issue 1 year ago • 7 comments

代码
if chunklength > 6 and "delta" in chunk['choices'][0]: finish_reason = chunk['choices'][0]['finish_reason'] if finish_reason == "stop": yield get_return_value() break partial_words = partial_words + chunk['choices'][0]["delta"]["content"]

将代码中delta替换成message可以解决,response中已经不包含delta,而使用message

lthero-big avatar Mar 15 '23 15:03 lthero-big

另外,在上述代码前面chunk = json.loads(chunk[6:]),也得换成chunk = json.loads(chunk)

lthero-big avatar Mar 15 '23 15:03 lthero-big

json解析错误还可能是api不对,或者token数超过了限制,还有可能是apiHost被墙墙了

lthero-big avatar Mar 15 '23 15:03 lthero-big

所以解决了吗

KingkingLiu avatar Mar 15 '23 16:03 KingkingLiu

所以解决了吗 归这样修改后解决了,可以将chunck信息输出,也能提取出回复的message

lthero-big avatar Mar 16 '23 02:03 lthero-big

我这样改了怎么还不行

1205129045x avatar Mar 16 '23 04:03 1205129045x

uture: <Task finished name='1ant4ow5w3k_0' coro=<Queue.process_events() done, defined at /usr/local/lib/python3.9/site-packages/gradio/queueing.py:343> exception=AttributeError("'AsyncRequest' object has no attribute '_json_response_data'")> Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/gradio/queueing.py", line 370, in process_events while response.json.get("is_generating", False): File "/usr/local/lib/python3.9/site-packages/gradio/utils.py", line 759, in json return self._json_response_data AttributeError: 'AsyncRequest' object has no attribute '_json_response_data' ^CKeyboard interruption in main thread

这个报错是啥意思

KingkingLiu avatar Mar 16 '23 16:03 KingkingLiu

代码 if chunklength > 6 and " delta " in chunk['choices'][0]: finish_reason = chunk['choices'][0]['finish_reason'] if finish_reason == "stop": yield get_return_value() break partial_words = partial_words + chunk['choices'][0][" delta "]["content"]

将代号中delta替换成message可以解决,response中已不包含delta,并使用message

不行哦,都改了,api是我自己用的,还有额度的,但是Json解析还是错的

bai408 avatar Mar 23 '23 12:03 bai408