simthneoshj commited on
Commit
019e18b
1 Parent(s): 39181a1

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +17 -0
  2. app.py +126 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用官方Python镜像作为基础镜像
2
+ FROM python:3.9
3
+
4
+ # 设置工作目录为/app
5
+ WORKDIR /app
6
+
7
+ # 将当前目录下的文件复制到工作目录中
8
+ COPY . /app
9
+
10
+ # 使用pip安装依赖
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ # 告诉Docker容器在运行时监听哪个端口
14
+ EXPOSE 8080
15
+
16
+ # 运行app.py当容器启动时
17
+ CMD ["python", "./app.py"]
app.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from concurrent.futures import ThreadPoolExecutor
3
+ import json
4
+ import urllib3
5
+ import requests
6
+
7
+ urllib3.disable_warnings()
8
+
9
+ app = Flask(__name__)
10
+
11
+
12
+ class SimpleConversationVerifier:
13
+ def __init__(self, url):
14
+ self.url = url
15
+ self.email = 'zsdjhhfjfdgb@gamil.com'
16
+ self.password = 'zxc1234d'
17
+ self.token = None
18
+ self.login()
19
+
20
+ def login(self):
21
+ headers = {
22
+ 'Accept': 'application/json, text/plain, */*',
23
+ 'Accept-Language': 'zh-CN,zh;q=0.9',
24
+ 'Authorization': 'Bearer undefined',
25
+ 'Cache-Control': 'no-cache',
26
+ 'Origin': self.url,
27
+ 'Pragma': 'no-cache',
28
+ 'Proxy-Connection': 'keep-alive',
29
+ 'Referer': f'{self.url}/login',
30
+ 'User-Agent': 'Mozilla/5.0',
31
+ }
32
+
33
+ json_data = {
34
+ 'email': self.email,
35
+ 'password': self.password,
36
+ }
37
+
38
+ response = requests.post(f'{self.url}/api/auth/login', headers=headers, json=json_data, verify=False)
39
+ response_dict = json.loads(response.text)
40
+ if 'token' in response_dict:
41
+ self.token = response_dict["token"]
42
+ return "Login successful."
43
+ else:
44
+ return "Login failed."
45
+
46
+ def verify_conversation(self):
47
+ if self.token is None:
48
+ print("Login is required before verifying conversation.")
49
+ return False
50
+
51
+ headers = {
52
+ 'Accept': '*/*',
53
+ 'Accept-Language': 'zh-CN,zh;q=0.9',
54
+ 'Authorization': f'Bearer {self.token}',
55
+ 'Cache-Control': 'no-cache',
56
+ 'Origin': 'http://67.205.142.90',
57
+ 'Pragma': 'no-cache',
58
+ 'Proxy-Connection': 'keep-alive',
59
+ 'Referer': 'http://67.205.142.90/c/new',
60
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
61
+ }
62
+ json_data = {
63
+ 'text': 'hi',
64
+ 'sender': 'User',
65
+ 'isCreatedByUser': True,
66
+ 'parentMessageId': '00000000-0000-0000-0000-000000000000',
67
+ 'conversationId': None,
68
+ 'messageId': '9a691d91-81c1-40bc-848b-6a45530e674b',
69
+ 'error': False,
70
+ 'generation': '',
71
+ 'responseMessageId': None,
72
+ 'overrideParentMessageId': None,
73
+ 'model': 'gpt-4',
74
+ 'endpoint': 'openAI',
75
+ 'key': None,
76
+ 'isContinued': False,
77
+ }
78
+
79
+ try:
80
+ response = requests.post(f'{self.url}/api/ask/openAI', headers=headers, json=json_data, verify=False)
81
+
82
+ if response.status_code == 200:
83
+ response.encoding = 'utf-8'
84
+ response_text = response.text
85
+ lines = response_text.split('\n')
86
+
87
+ title_found = False
88
+
89
+ for line in lines:
90
+ if 'title' in line:
91
+ title_found = True
92
+ last_line = line.split(':', 1)[1].strip()
93
+ last_line_dict = json.loads(last_line)
94
+ text = last_line_dict['responseMessage']['text']
95
+ print(text)
96
+ return True, text
97
+
98
+ if not title_found:
99
+ print(response.status_code)
100
+ print(response.text)
101
+ return False
102
+ else:
103
+ print("Verification failed.")
104
+ return False
105
+ except requests.exceptions.RequestException as err:
106
+ print("Something went wrong: ", err)
107
+ return False
108
+
109
+
110
+ @app.route('/', methods=['POST'])
111
+ def verify_conversation():
112
+ req_data = request.get_json()
113
+ url = req_data.get('url')
114
+ verifier = SimpleConversationVerifier(url)
115
+ conversation = verifier.verify_conversation()
116
+ login = verifier.login()
117
+ # return jsonify({'Conversation status': conversation})
118
+ verifier_data = {
119
+ 'login': login,
120
+ 'conversation':conversation,
121
+ }
122
+ return jsonify(verifier_data)
123
+
124
+
125
+ if __name__ == "__main__":
126
+ app.run(host='0.0.0.0', port=8080, debug=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ Flask
2
+ requests
3
+ filelock