xiaolv commited on
Commit
7637c59
1 Parent(s): e6b8203

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -7
app.py CHANGED
@@ -8,6 +8,34 @@ def generate_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()
@@ -35,11 +63,11 @@ def create_new_chat(user_id,cookie):
35
  # Returns JSON of the newly created conversation information
36
  return response.json()
37
 
38
- def request_to_v2(message, cookie, user_id, channel_id,context=[]):
 
 
 
39
 
40
- datas = create_new_chat(user_id,cookie)
41
- print(datas)
42
- exit(0)
43
 
44
  timeout = 5*60 #5分钟不回复,显示超时
45
  context = [message]
@@ -107,6 +135,13 @@ def request_to_v2(message, cookie, user_id, channel_id,context=[]):
107
 
108
  return responses, context
109
 
 
 
 
 
 
 
 
110
 
111
 
112
  with gr.Blocks() as dialog_app:
@@ -123,7 +158,7 @@ with gr.Blocks() as dialog_app:
123
  with gr.Column(scale=0.4):
124
  cookies = gr.Textbox(lines=2, label="输入cookies")
125
  user_id = gr.Textbox(lines=2, label="输入user_id/organization_uuid")
126
- channel_id = gr.Textbox(lines=2, label="输入channel_id/conversation_uuid")
127
  # chatbot = gr.Chatbot()
128
  with gr.Column(scale=0.6):
129
  chatbot = gr.Chatbot([])
@@ -135,9 +170,9 @@ with gr.Blocks() as dialog_app:
135
  label="输入问题",
136
  placeholder="请输入你的文本,确保已经正确填入cookies、user_id、channel_id"
137
  )
138
- inputs.submit(request_to_v2, [inputs, cookies, user_id,channel_id,state], [chatbot, state])
139
  send = gr.Button("发送请求.....")
140
- send.click(request_to_v2, [inputs, cookies, user_id,channel_id,state], [chatbot, state], api_name="xiaolvgpt", show_progress=True)
141
 
142
 
143
  gr.Markdown("""
 
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
+
12
+ # Deletes the conversation
13
+ def delete_conversation(user_id,channel_id,cookie):
14
+ url = f"https://claude.ai/api/organizations/{user_id}/chat_conversations/{channel_id}"
15
+
16
+ payload = json.dumps(f"{channel_id}")
17
+ headers = {
18
+ 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.82',
19
+ 'Accept-Language': 'en-US,en;q=0.5',
20
+ 'Content-Type': 'application/json',
21
+ 'Content-Length': '38',
22
+ 'Referer': 'https://claude.ai/chats',
23
+ 'Origin': 'https://claude.ai',
24
+ 'Sec-Fetch-Dest': 'empty',
25
+ 'Sec-Fetch-Mode': 'cors',
26
+ 'Sec-Fetch-Site': 'same-origin',
27
+ 'Connection': 'keep-alive',
28
+ 'Cookie': f'{cookie}',
29
+ 'TE': 'trailers'
30
+ }
31
+
32
+ response = requests.delete(url, headers=headers, data=payload)
33
+ # Returns True if deleted or False if any error in deleting
34
+ if response.status_code == 204:
35
+ return True
36
+ else:
37
+ return False
38
+
39
  def create_new_chat(user_id,cookie):
40
  url = f"https://claude.ai/api/organizations/{user_id}/chat_conversations"
41
  uuid = generate_uuid()
 
63
  # Returns JSON of the newly created conversation information
64
  return response.json()
65
 
66
+ def request_to_v2(message, cookie, user_id,context=[]):
67
+
68
+ channel_id = create_new_chat(user_id,cookie)
69
+ print(channel_id)
70
 
 
 
 
71
 
72
  timeout = 5*60 #5分钟不回复,显示超时
73
  context = [message]
 
135
 
136
  return responses, context
137
 
138
+ finally:
139
+ ds = delete_conversation(user_id,channel_id,cookie)
140
+ if ds:
141
+ print(f"成功删除")
142
+ else:
143
+ print(f"删除失败")
144
+
145
 
146
 
147
  with gr.Blocks() as dialog_app:
 
158
  with gr.Column(scale=0.4):
159
  cookies = gr.Textbox(lines=2, label="输入cookies")
160
  user_id = gr.Textbox(lines=2, label="输入user_id/organization_uuid")
161
+ # channel_id = gr.Textbox(lines=2, label="输入channel_id/conversation_uuid")
162
  # chatbot = gr.Chatbot()
163
  with gr.Column(scale=0.6):
164
  chatbot = gr.Chatbot([])
 
170
  label="输入问题",
171
  placeholder="请输入你的文本,确保已经正确填入cookies、user_id、channel_id"
172
  )
173
+ inputs.submit(request_to_v2, [inputs, cookies, user_id,state], [chatbot, state])
174
  send = gr.Button("发送请求.....")
175
+ send.click(request_to_v2, [inputs, cookies, user_id,state], [chatbot, state], api_name="xiaolvgpt", show_progress=True)
176
 
177
 
178
  gr.Markdown("""