xiaolv commited on
Commit
6a7a9fa
1 Parent(s): 9fedc04

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -5
app.py CHANGED
@@ -3,6 +3,7 @@ import json
3
  import asyncio
4
  import os
5
  from EdgeGPT import Chatbot, ConversationStyle
 
6
 
7
  """
8
  参考资料:
@@ -25,13 +26,35 @@ async def get_model_reply(prompt,style,cookies,context=[]):
25
  raw_data = await bot.ask(prompt, conversation_style=style)
26
  await bot.close()
27
  #print(raw_data)
28
- response = raw_data["item"]["messages"][1]["text"]
29
- context += [response]
 
 
 
 
 
 
 
 
30
 
31
- # list of (user, bot) responses. We will use this format later
32
- responses = [(u, b) for u, b in zip(context[::2], context[1::2])]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
- return responses, context
35
 
36
  with gr.Blocks() as dialog_app:
37
 
 
3
  import asyncio
4
  import os
5
  from EdgeGPT import Chatbot, ConversationStyle
6
+ import re
7
 
8
  """
9
  参考资料:
 
26
  raw_data = await bot.ask(prompt, conversation_style=style)
27
  await bot.close()
28
  #print(raw_data)
29
+ try:
30
+ try:
31
+ response = raw_data["item"]["messages"][1]["text"]
32
+ except:
33
+ response = raw_data["item"]["messages"][1]["adaptiveCards"][0]["body"][0]["text"]
34
+ response = re.sub(r'\^', '', response)
35
+ response = response.rstrip()
36
+ context += [response]
37
+ responses = [(u, b) for u, b in zip(context[::2], context[1::2])]
38
+ return responses, context
39
 
40
+ except:
41
+ try:
42
+ if raw_data["item"]["throttling"]["numUserMessagesInConversation"] > raw_data["item"]["throttling"][
43
+ "maxNumUserMessagesInConversation"]:
44
+ response = ">>>请重新开启新的对话。"
45
+ print(response)
46
+ context += ["0"]
47
+ responses = [(u, b) for u, b in zip(context[::2], context[1::2])]
48
+ return responses, context
49
+
50
+ except:
51
+ if raw_data["item"]["result"]["value"] == "Throttled":
52
+ response = "> **错误: 我们很抱歉,但你已经达到了你在24小时内可以向Bing发送消息的最大数量。请稍后再查看!**"
53
+ print(response)
54
+ context += ["0"]
55
+ responses = [(u, b) for u, b in zip(context[::2], context[1::2])]
56
+ return responses, context
57
 
 
58
 
59
  with gr.Blocks() as dialog_app:
60