xiaolv commited on
Commit
9f5e7e6
0 Parent(s):

Duplicate from xiaolv/claude2_xiaolv_api

Browse files
Files changed (5) hide show
  1. .gitattributes +34 -0
  2. README.md +14 -0
  3. app.py +114 -0
  4. gitattributes.txt +34 -0
  5. requirements.txt +13 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: New-Bing-with Your Cookies
3
+ emoji: 🐨
4
+ colorFrom: green
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 3.23.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: other
11
+ duplicated_from: xiaolv/claude2_xiaolv_api
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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]
8
+ headers = {
9
+ # ':Authority': 'claude.ai',
10
+ # ':Method': 'POST',
11
+ # ':Path': '/api/append_message',
12
+ # ':Scheme': 'https',
13
+ 'Content-Type': 'application/json',
14
+ 'Origin': 'https://claude.ai',
15
+ 'Referer': f'https://claude.ai/chat/{channel_id}',
16
+ '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',
17
+ 'Cookie': cookie,
18
+ 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
19
+ # 'Accept-Encoding': 'gzip, deflate, br',
20
+ 'Accept': 'text/event-stream, text/event-stream',
21
+ 'Sec-Ch-Ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
22
+ 'Sec-Ch-Ua-Mobile': '?0',
23
+ 'Sec-Ch-Ua-Platform': '"Windows"',
24
+ 'Sec-Fetch-Dest': 'empty',
25
+ 'Sec-Fetch-Mode': 'cors',
26
+ 'Sec-Fetch-Site': 'same-origin',
27
+ 'Connection': 'keep-alive',
28
+ }
29
+ post_msg_url = 'https://claude.ai/api/append_message'
30
+ post_msg_data = {
31
+ "completion":{
32
+ "incremental":True,
33
+ "prompt": message,
34
+ "timezone":"Asia/Shanghai",
35
+ "model":"claude-2"
36
+ },
37
+ "organization_uuid": user_id,
38
+ "conversation_uuid": channel_id,
39
+ "text": message,
40
+ "attachments": []
41
+ }
42
+ post_msg_data = json.dumps(post_msg_data)
43
+ # print(post_msg_data)
44
+
45
+ try:
46
+ response = requests.post(post_msg_url, headers=headers, data=post_msg_data, verify=False, stream=False,timeout = timeout)
47
+ bots = ""
48
+ print("a"*100)
49
+ for data in response.iter_lines():
50
+ if data:
51
+ # 将字节字符串转换为字符串
52
+ data_str = data.decode('utf-8')
53
+ # 删除开头的 "data: " 部分
54
+ data_str = data_str.replace("data: ", "")
55
+ data_json = json.loads(data_str)
56
+ # print(data_json)
57
+ bots += data_json["completion"]
58
+ print(bots)
59
+ context += [bots]
60
+ responses = [(u, b) for u, b in zip(context[::2], context[1::2])]
61
+ return responses, context
62
+
63
+ except Exception as e:
64
+ print(">>>>>> 查询失败")
65
+ print(e)
66
+ response =">>>>>> 查询失败\n报错信息为:"+ str(e)
67
+ context += [response]
68
+ responses = [(u, b) for u, b in zip(context[::2], context[1::2])]
69
+
70
+ return responses, context
71
+
72
+
73
+
74
+ with gr.Blocks() as dialog_app:
75
+ gr.HTML("""<h1 align="center">Claude2-API-xiaolv</h1>""")
76
+ with gr.Tab("Claude2 API xiaolv"):
77
+ gr.Markdown("""
78
+ ## 需要传入的参数有:
79
+ 1.cookie:intercom-device-id-lupk8zyo=.......
80
+ 2.user_id:对应 organization_uuid
81
+ 3.channel_id:对应 conversation_uuid
82
+ """)
83
+
84
+ with gr.Row():
85
+ with gr.Column(scale=0.4):
86
+ cookies = gr.Textbox(lines=2, label="输入cookies")
87
+ user_id = gr.Textbox(lines=2, label="输入user_id/organization_uuid")
88
+ channel_id = gr.Textbox(lines=2, label="输入channel_id/conversation_uuid")
89
+ # chatbot = gr.Chatbot()
90
+ with gr.Column(scale=0.6):
91
+ chatbot = gr.Chatbot([])
92
+
93
+ state = gr.State([])
94
+
95
+ with gr.Row():
96
+ inputs = gr.Textbox(
97
+ label="输入问题",
98
+ placeholder="请输入你的文本,确保已经正确填入cookies、user_id、channel_id"
99
+ )
100
+ inputs.submit(request_to_v2, [inputs, cookies, user_id,channel_id,state], [chatbot, state])
101
+ send = gr.Button("发送请求.....")
102
+ send.click(request_to_v2, [inputs, cookies, user_id,channel_id,state], [chatbot, state], api_name="xiaolvgpt", show_progress=True)
103
+
104
+
105
+ gr.Markdown("""
106
+ 清除历史记录是,请输入:```/resrt```""")
107
+
108
+ # 为网站设置密码防止滥用
109
+ # dialog_app.launch(auth=("admin", "2240560729"),show_error=True,show_api=True,share=True)
110
+ # dialog_app.launch(auth=("admin", "2240560729"),show_error=True)
111
+ dialog_app.launch(show_error=True)
112
+ # dialog_app.launch(show_error=True,show_api=True,share=True)
113
+
114
+
gitattributes.txt ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
requirements.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiohttp
2
+ BingImageCreator
3
+ certifi
4
+ httpx
5
+ prompt_toolkit
6
+ requests
7
+ rich
8
+ gradio
9
+ requests
10
+ websockets
11
+ log2d
12
+
13
+