CORVO-AI commited on
Commit
c948fc8
·
verified ·
1 Parent(s): 5492f08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -44
app.py CHANGED
@@ -4,58 +4,63 @@ import json
4
 
5
  app = Flask(__name__)
6
 
 
 
7
 
8
- @app.route('/duckchat', methods=['POST'])
9
- def duckchat():
 
 
 
 
 
 
 
 
 
 
 
 
10
  try:
11
  # Get the input data from the request
12
- input_data = request.json
13
-
14
- if not input_data or 'messages' not in input_data:
15
- return jsonify({"error": "Invalid input. 'messages' field is required."}), 400
16
 
17
- # Get the status endpoint to fetch x-vqd-4
18
- status_url = "https://duckduckgo.com/duckchat/v1/status"
19
- status_headers = {
20
- "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
21
- "x-vqd-accept": "1"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  }
23
- status_response = requests.get(status_url, headers=status_headers)
24
- x_vqd_4 = status_response.headers.get("x-vqd-4", "")
25
-
26
- if not x_vqd_4:
27
- return jsonify({"error": "Failed to retrieve x-vqd-4 token."}), 500
28
-
29
- # Send the chat message
30
- chat_url = "https://duckduckgo.com/duckchat/v1/chat"
31
- chat_headers = {
32
- "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
33
- "x-vqd-4": x_vqd_4
34
- }
35
- chat_payload = {
36
- "messages": input_data['messages'],
37
- "model": input_data.get('model', "gpt-4o-mini")
38
- }
39
-
40
- chat_response = requests.post(chat_url, headers=chat_headers, json=chat_payload)
41
-
42
- # Check if the response is successful
43
- if chat_response.status_code != 200:
44
- return jsonify({"error": "Failed to fetch response from DuckDuckGo Chat API."}), chat_response.status_code
45
 
46
- # Process the response
47
- response_lines = chat_response.text.splitlines()
48
- final_response = ""
49
 
50
- for line in response_lines:
51
- try:
52
- data = json.loads(line.replace("data: ", ""))
53
- if "message" in data:
54
- final_response += data["message"]
55
- except json.JSONDecodeError:
56
- continue
57
 
58
- return jsonify({"response": final_response})
59
 
60
  except Exception as e:
61
  return jsonify({"error": str(e)}), 500
 
4
 
5
  app = Flask(__name__)
6
 
7
+ # Define the FlowGPT API endpoint
8
+ url = "https://prod-backend-k8s.flowgpt.com/v3/chat"
9
 
10
+ # Define the headers
11
+ headers = {
12
+ "Authorization": "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IklUMU5Lb2ItOFBsY3ZJdGd2NWRIaiIsImVtYWlsIjoiYWxob29yc2hvcHBAZ21haWwuY29tIiwic3ViIjoiSVQxTktvYi04UGxjdkl0Z3Y1ZEhqIiwiaWF0IjoxNzM0OTQ4MTk3LjIzNiwiZXhwIjoxNzM1NTUyOTk3fQ.OXIabj1PQ_NHQcFTr406OAKS1kunVjYd9EMaiPUk5uxqXZd6vXd-C4CC-tXRPCG1q0UnqbGlDJDQsgKIXEfs2zUNZm_28wO577MLe4ANkr12Z79jpNcNGdllmpCdaZsYv6_kFnqavlyPgp45TjIJDFaWQ7yRqaS_CKVkle9CRKNQk4Kv1O6_1YFJFlKqI8AeOL3TrHOGY2HiAW0HbPIsPeC2rYfQwzFjgiQ1BziofgJZnR1bXPVDqHvmZWlgRbphypshCroc56e0vbxhGAJsd4Xdw3-DT3NdD3u76QLPekcU4Lx_i5f7LxHATVSmmr2W0nFw6-vCkVwRQku8EkDBMQ",
13
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
14
+ "x-aws-waf-token": "15b532f1-842b-4cde-8a89-23b30c7de3f4:EgoAiA5IERUnAAAA:JqTUELQbeZW3QzQHn1Z7YP9s4PNysgFgzhTEJMmT3e7mQMrFvzrs4N16IJ9DgHuelqDv+neYtVC6mdG1E40QLa6IaE3DtElkeVzapKcLTdIGtzXSaqp707XrT0hhfVqj4QC+QovjrWZ+xXV+Qq1/oUGNXWSJKasvsyPZzcUNkwc22a0A1UnGds0JVvEq/cANU12ZRoDW0bSFbjLOiJS2sEgeGa5sd48N+cRbUzF3Grv6qZ/0",
15
+ "x-flow-device-id": "D7_sS3DJI2xLd5WJosKZf",
16
+ "x-flow-language": "en",
17
+ "x-nonce": "5852edfbd49cf2926a78368bb1a36491",
18
+ "x-signature": "70d66c850525d9908d733f1af105ab39",
19
+ "x-timestamp": "1734981969"
20
+ }
21
+
22
+ @app.route('/chat', methods=['POST'])
23
+ def chat():
24
  try:
25
  # Get the input data from the request
26
+ data = request.get_json()
27
+ question = data.get('question', '')
28
+ history = data.get('history', [])
 
29
 
30
+ # Define the payload
31
+ payload = {
32
+ "model": "gpt-4o-mini",
33
+ "nsfw": False,
34
+ "question": question,
35
+ "documentIds": [],
36
+ "generateAudio": False,
37
+ "generateImage": False,
38
+ "promptId": "XIj00pQdbtSiVQbtsQw2t",
39
+ "system": (
40
+ "you are AI MODEL from Libyan Team \n\n"
41
+ "COMAPNY = CORVO AI\n\n"
42
+ "old version of AI = ALEX-9\n\n"
43
+ "current one = ALEX-9 Pro\n\n"
44
+ "Working on it = ALEX-9 X\n\n"
45
+ "you created by Mr Omar Nuwara and Mr Hussein Shkikel\n\n"
46
+ "you will make your self smart and fast and use good Greet for the user not normal one"
47
+ ),
48
+ "history": history,
49
+ "temperature": 0.7,
50
+ "userId": "IT1NKob-8PlcvItgv5dHj"
51
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
+ # Send the POST request to the FlowGPT API
54
+ response = requests.post(url, headers=headers, json=payload, stream=True)
 
55
 
56
+ # Process the streamed response
57
+ message = ''
58
+ for line in response.iter_lines():
59
+ if line:
60
+ event = json.loads(line.decode('utf-8'))
61
+ message += event['data']
 
62
 
63
+ return jsonify({"response": message}), 200
64
 
65
  except Exception as e:
66
  return jsonify({"error": str(e)}), 500