Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
修复bug:bing回复长信息消失
  • Loading branch information
xbzstudio committed Aug 17, 2023
1 parent bd625e5 commit 27851f7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ async def wsStream(ws: WebSocket):
response['error'] = '已到达一天的最大聊天次数,无法继续聊天'
await ws.send_text(json.dumps(response))
if ans.get('item').get('result').get('value') == 'Success':
response['answer'] = [ans.get('item').get('messages')[1].get('adaptiveCards')[0].get('body')[i].get('text') for i in range(len(ans.get('item').get('messages')[1].get('adaptiveCards')[0].get('body')))][0] if [ans.get('item').get('messages')[1].get('adaptiveCards')[0].get('body')[i].get('text') for i in range(len(ans.get('item').get('messages')[1].get('adaptiveCards')[0].get('body')))]!=None else None
response['suggested'] = [i.get('text') for i in ans.get('item').get('messages')[1].get('suggestedResponses')]
if len(ans.get('item').get('messages')[1].get('sourceAttributions')) != 0:
response['urls'] = [{'name' : i.get('providerDisplayName'), 'url' : i.get('seeMoreUrl')} for i in ans.get('item').get('messages')[1].get('sourceAttributions')]
response['answer'] = ans['item']['messages'][-1]['adaptiveCards'][0]['body'][0]['text']
response['suggested'] = [i['text'] for i in ans['item']['messages'][-1]['suggestedResponses']]
response['urls'] = [{'name' : i['providerDisplayName'], 'url' : i['seeMoreUrl']} for i in ans['item']['messages'][-1]['sourceAttributions']]
await ws.send_text(json.dumps(response))
else:
response['error'] = '未知错误,value:' + str(ans.get('item').get('result').get('value'))
await ws.send_text(json.dumps(response))
except Exception as e:
if e.args[0] == "adaptiveCards" or e.args[0] == "'NoneType' object is not subscriptable":
if e.args[0] == "adaptiveCards":
response['answer'] = imageInfo
response['done'] = True
await ws.send_text(json.dumps(response))
Expand Down

0 comments on commit 27851f7

Please sign in to comment.