simthneoshj's picture
Upload 3 files
019e18b verified
raw
history blame contribute delete
No virus
4.2 kB
from flask import Flask, request, jsonify
from concurrent.futures import ThreadPoolExecutor
import json
import urllib3
import requests
urllib3.disable_warnings()
app = Flask(__name__)
class SimpleConversationVerifier:
def __init__(self, url):
self.url = url
self.email = 'zsdjhhfjfdgb@gamil.com'
self.password = 'zxc1234d'
self.token = None
self.login()
def login(self):
headers = {
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Authorization': 'Bearer undefined',
'Cache-Control': 'no-cache',
'Origin': self.url,
'Pragma': 'no-cache',
'Proxy-Connection': 'keep-alive',
'Referer': f'{self.url}/login',
'User-Agent': 'Mozilla/5.0',
}
json_data = {
'email': self.email,
'password': self.password,
}
response = requests.post(f'{self.url}/api/auth/login', headers=headers, json=json_data, verify=False)
response_dict = json.loads(response.text)
if 'token' in response_dict:
self.token = response_dict["token"]
return "Login successful."
else:
return "Login failed."
def verify_conversation(self):
if self.token is None:
print("Login is required before verifying conversation.")
return False
headers = {
'Accept': '*/*',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Authorization': f'Bearer {self.token}',
'Cache-Control': 'no-cache',
'Origin': 'http://67.205.142.90',
'Pragma': 'no-cache',
'Proxy-Connection': 'keep-alive',
'Referer': 'http://67.205.142.90/c/new',
'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',
}
json_data = {
'text': 'hi',
'sender': 'User',
'isCreatedByUser': True,
'parentMessageId': '00000000-0000-0000-0000-000000000000',
'conversationId': None,
'messageId': '9a691d91-81c1-40bc-848b-6a45530e674b',
'error': False,
'generation': '',
'responseMessageId': None,
'overrideParentMessageId': None,
'model': 'gpt-4',
'endpoint': 'openAI',
'key': None,
'isContinued': False,
}
try:
response = requests.post(f'{self.url}/api/ask/openAI', headers=headers, json=json_data, verify=False)
if response.status_code == 200:
response.encoding = 'utf-8'
response_text = response.text
lines = response_text.split('\n')
title_found = False
for line in lines:
if 'title' in line:
title_found = True
last_line = line.split(':', 1)[1].strip()
last_line_dict = json.loads(last_line)
text = last_line_dict['responseMessage']['text']
print(text)
return True, text
if not title_found:
print(response.status_code)
print(response.text)
return False
else:
print("Verification failed.")
return False
except requests.exceptions.RequestException as err:
print("Something went wrong: ", err)
return False
@app.route('/', methods=['POST'])
def verify_conversation():
req_data = request.get_json()
url = req_data.get('url')
verifier = SimpleConversationVerifier(url)
conversation = verifier.verify_conversation()
login = verifier.login()
# return jsonify({'Conversation status': conversation})
verifier_data = {
'login': login,
'conversation':conversation,
}
return jsonify(verifier_data)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080, debug=True)