Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,48 @@
|
|
1 |
import json, requests
|
2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
def request_to_v2(message, cookie, user_id, channel_id,context=[]):
|
|
|
|
|
|
|
|
|
5 |
|
6 |
timeout = 5*60 #5分钟不回复,显示超时
|
7 |
context = [message]
|
|
|
1 |
import json, requests
|
2 |
import gradio as gr
|
3 |
+
import uuid
|
4 |
+
|
5 |
+
def generate_uuid():
|
6 |
+
random_uuid = uuid.uuid4()
|
7 |
+
random_uuid_str = str(random_uuid)
|
8 |
+
formatted_uuid = f"{random_uuid_str[0:8]}-{random_uuid_str[9:13]}-{random_uuid_str[14:18]}-{random_uuid_str[19:23]}-{random_uuid_str[24:]}"
|
9 |
+
return formatted_uuid
|
10 |
+
|
11 |
+
def create_new_chat(user_id,cookie):
|
12 |
+
url = f"https://claude.ai/api/organizations/{user_id}/chat_conversations"
|
13 |
+
uuid = generate_uuid()
|
14 |
+
|
15 |
+
payload = json.dumps({"uuid": uuid, "name": ""})
|
16 |
+
headers = {
|
17 |
+
'User-Agent':
|
18 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
|
19 |
+
'Accept-Language': 'en-US,en;q=0.5',
|
20 |
+
'Referer': 'https://claude.ai/chats',
|
21 |
+
'Content-Type': 'application/json',
|
22 |
+
'Origin': 'https://claude.ai',
|
23 |
+
'DNT': '1',
|
24 |
+
'Connection': 'keep-alive',
|
25 |
+
'Cookie': cookie,
|
26 |
+
'Sec-Fetch-Dest': 'empty',
|
27 |
+
'Sec-Fetch-Mode': 'cors',
|
28 |
+
'Sec-Fetch-Site': 'same-origin',
|
29 |
+
'TE': 'trailers'
|
30 |
+
}
|
31 |
+
|
32 |
+
# response = requests.request("POST", url, headers=headers, data=payload)
|
33 |
+
# 使用代理,解决国内网络不能访问问题
|
34 |
+
# response = request("POST", url, headers=headers, data=payload, proxies=proxies)
|
35 |
+
response = requests.post(url, headers=headers, data=payload)
|
36 |
+
print(f"新的对话页面:{response}")
|
37 |
+
|
38 |
+
# Returns JSON of the newly created conversation information
|
39 |
+
return response.json()
|
40 |
|
41 |
def request_to_v2(message, cookie, user_id, channel_id,context=[]):
|
42 |
+
|
43 |
+
datas = create_new_chat(user_id,cookie)
|
44 |
+
print(datas)
|
45 |
+
exit(0)
|
46 |
|
47 |
timeout = 5*60 #5分钟不回复,显示超时
|
48 |
context = [message]
|