Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
| 1 |
-
import json
|
| 2 |
import gradio as gr
|
| 3 |
import uuid
|
| 4 |
import time
|
| 5 |
import random
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
# 创建新的聊天频道
|
|
@@ -33,7 +36,7 @@ def delete_conversation(user_id,channel_id,cookie):
|
|
| 33 |
'TE': 'trailers'
|
| 34 |
}
|
| 35 |
|
| 36 |
-
response = requests.delete(url, headers=headers, data=payload)
|
| 37 |
# Returns True if deleted or False if any error in deleting
|
| 38 |
if response.status_code == 204:
|
| 39 |
return True
|
|
@@ -58,10 +61,10 @@ def create_new_chat(user_id,cookie):
|
|
| 58 |
'Sec-Fetch-Site': 'same-origin',
|
| 59 |
}
|
| 60 |
|
| 61 |
-
# response = requests.request("POST", url, headers=headers, data=payload)
|
| 62 |
# 使用代理,解决国内网络不能访问问题
|
| 63 |
# response = request("POST", url, headers=headers, data=payload, proxies=proxies)
|
| 64 |
-
response = requests.post(url, headers=headers, data=payload)
|
| 65 |
print(f"新的对话页面:{response.json()}")
|
| 66 |
|
| 67 |
# Returns JSON of the newly created conversation information
|
|
@@ -120,21 +123,21 @@ def request_to_v2(message, cookie, user_id,context=[]):
|
|
| 120 |
|
| 121 |
try:
|
| 122 |
print(f"输入的问题:{message}")
|
| 123 |
-
response = requests.post(post_msg_url, headers=headers, data=post_msg_data, verify=False,
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
bots += data_json["completion"]
|
| 135 |
print(bots)
|
| 136 |
context += [bots]
|
| 137 |
responses = [(u, b) for u, b in zip(context[::2], context[1::2])]
|
|
|
|
| 138 |
return responses, context
|
| 139 |
|
| 140 |
except Exception as e:
|
|
|
|
| 1 |
+
import json
|
| 2 |
import gradio as gr
|
| 3 |
import uuid
|
| 4 |
import time
|
| 5 |
import random
|
| 6 |
+
import os
|
| 7 |
+
from curl_cffi import requests
|
| 8 |
+
import re
|
| 9 |
|
| 10 |
|
| 11 |
# 创建新的聊天频道
|
|
|
|
| 36 |
'TE': 'trailers'
|
| 37 |
}
|
| 38 |
|
| 39 |
+
response = requests.delete(url, headers=headers, data=payload,impersonate="chrome110")
|
| 40 |
# Returns True if deleted or False if any error in deleting
|
| 41 |
if response.status_code == 204:
|
| 42 |
return True
|
|
|
|
| 61 |
'Sec-Fetch-Site': 'same-origin',
|
| 62 |
}
|
| 63 |
|
| 64 |
+
# response = requests.request("POST", url, headers=headers, data=payload,impersonate="chrome110")
|
| 65 |
# 使用代理,解决国内网络不能访问问题
|
| 66 |
# response = request("POST", url, headers=headers, data=payload, proxies=proxies)
|
| 67 |
+
response = requests.post(url, headers=headers, data=payload,impersonate="chrome110")
|
| 68 |
print(f"新的对话页面:{response.json()}")
|
| 69 |
|
| 70 |
# Returns JSON of the newly created conversation information
|
|
|
|
| 123 |
|
| 124 |
try:
|
| 125 |
print(f"输入的问题:{message}")
|
| 126 |
+
response = requests.post(post_msg_url, headers=headers, data=post_msg_data, verify=False,timeout = timeout,impersonate="chrome110")
|
| 127 |
+
decoded_data = response.content.decode("utf-8")
|
| 128 |
+
decoded_data = re.sub('\n+', '\n', decoded_data).strip()
|
| 129 |
+
data_strings = decoded_data.split('\n')
|
| 130 |
+
completions = []
|
| 131 |
+
for data_string in data_strings:
|
| 132 |
+
json_str = data_string[6:].strip()
|
| 133 |
+
data = json.loads(json_str)
|
| 134 |
+
if 'completion' in data:
|
| 135 |
+
completions.append(data['completion'])
|
| 136 |
+
bots = ''.join(completions)
|
|
|
|
| 137 |
print(bots)
|
| 138 |
context += [bots]
|
| 139 |
responses = [(u, b) for u, b in zip(context[::2], context[1::2])]
|
| 140 |
+
print("a"*100)
|
| 141 |
return responses, context
|
| 142 |
|
| 143 |
except Exception as e:
|