ChuanhuChatGPT
ChuanhuChatGPT copied to clipboard
Json解析错误解决方法
代码
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
另外,在上述代码前面chunk = json.loads(chunk[6:]),也得换成chunk = json.loads(chunk)
json解析错误还可能是api不对,或者token数超过了限制,还有可能是apiHost被墙墙了
所以解决了吗
所以解决了吗 归这样修改后解决了,可以将chunck信息输出,也能提取出回复的message
我这样改了怎么还不行
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
这个报错是啥意思
代码 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解析还是错的