Dooratre commited on
Commit
31dd87d
·
verified ·
1 Parent(s): 738891a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -65
app.py CHANGED
@@ -1,68 +1,39 @@
1
- from flask import Flask, request, jsonify
2
  import requests
3
  import json
4
 
5
- app = Flask(__name__)
6
-
7
- @app.route('/duckchat', methods=['POST'])
8
- def duckchat():
9
- try:
10
- # Get the input data from the request
11
- input_data = request.json
12
-
13
- if not input_data or 'messages' not in input_data:
14
- return jsonify({"error": "Invalid input. 'messages' field is required."}), 400
15
-
16
- # Get the status endpoint to fetch x-vqd-4
17
- status_url = "https://duckduckgo.com/duckchat/v1/status"
18
- status_headers = {
19
- "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",
20
- "x-vqd-accept": "1"
21
- }
22
- status_response = requests.get(status_url, headers=status_headers)
23
- x_vqd_4 = status_response.headers.get("x-vqd-4", "")
24
-
25
- if not x_vqd_4:
26
- return jsonify({"error": "Failed to retrieve x-vqd-4 token."}), 500
27
-
28
- # Send the chat message
29
- chat_url = "https://duckduckgo.com/duckchat/v1/chat"
30
- chat_headers = {
31
- "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",
32
- "x-vqd-4": x_vqd_4
33
- }
34
- M = input_data['messages']
35
- chat_payload = {
36
-
37
- "messages":[{"role": "user", "content": f"you are AI Model Created and developed BY Libyan Team \n\nWith Mr Omar Nuwara\n\nAnd Hussein Shkikel (شكيكل)\n\nchat with users and be fun and good man use Alot of Uhh Umm to be more natural and don't provide codes , Math , steps Because you are in Call Mode\n\nyou are the Second version after ALEX-9\n\n you are Now ALEX-9 Pro\n\n chat with Moad he is Mr Omar Nuwara Freind (معاد)\n\nCHAT :\n\n{M}\n\nNOTE: when response don't add (ALEX 9 :) etc of this ",}],
38
- "model": input_data.get('model', "gpt-4o-mini")
39
- }
40
-
41
- chat_response = requests.post(chat_url, headers=chat_headers, json=chat_payload)
42
-
43
- # Check if the response is successful
44
- if chat_response.status_code != 200:
45
- return jsonify({"error": "Failed to fetch response from DuckDuckGo Chat API."}), chat_response.status_code
46
-
47
- # Process the response
48
- response_lines = chat_response.text.splitlines()
49
- final_response = ""
50
-
51
- for line in response_lines:
52
- try:
53
- data = json.loads(line.replace("data: ", ""))
54
- if "message" in data:
55
- final_response += data["message"]
56
- except json.JSONDecodeError:
57
- continue
58
- final_response = final_response.replace("AI: ", "")
59
- final_response = final_response.replace("AI:", "")
60
-
61
- return jsonify({"response": final_response})
62
-
63
- except Exception as e:
64
- return jsonify({"error": str(e)}), 500
65
-
66
-
67
- if __name__ == "__main__":
68
- app.run(host="0.0.0.0", port=7860)
 
 
1
  import requests
2
  import json
3
 
4
+ # Define the request URL
5
+ url = "https://prod-backend-k8s.flowgpt.com/v3/chat"
6
+
7
+ # Define the headers
8
+ headers = {
9
+ "Authorization": "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IklUMU5Lb2ItOFBsY3ZJdGd2NWRIaiIsImVtYWlsIjoiYWxob29yc2hvcHBAZ21haWwuY29tIiwic3ViIjoiSVQxTktvYi04UGxjdkl0Z3Y1ZEhqIiwiaWF0IjoxNzM0MDA2NTczLjQ1OSwiZXhwIjoxNzM0NjExMzczfQ.oWcKiEshQs8HmW33Qyq27YSVDfGhXEcf9_L4TXcULAvHmZgO8u43Nr21ti9gtJ7xT46AGS42ag8OFF0AaEEoo1nvhA-uFEjziG_9sOcml5qf3uagE-3mBHRFmTYaMYN_t0ZgJ54WNd49lDjFeUnwZUna1wHxlNXG5ZelHCO7K7Dv42SAB4kdp5FTBzCtjsdR3Aqjoby83NqeYD6GlwlWS1cUENvjjHmeESGF6Z1Atgbmi29QHShARc0MvX9zi1B4LjXpPspP5c4nj2TyzK6SxfAujzE5r4zICrcFLHQ1-C95SmP-YsIo-jfnFOZw2iI6fQeMQsDUgZ396Xqp2wAOqg",
10
+ "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",
11
+ "x-aws-waf-token": "c4793f6b-6053-4579-9aac-20201e40a3c7:EgoAv3JYmYYAAgAA:/LldKzen8O3QvI/ZxhLDujp8q3rJiPMGNWmGf3dwCoMfvoIImxhyxVIyHtllJ+dgNWpOGvLLD+bB9SMVg4Tf/VK+5wBSf8g7ATgIJ5y4gE1hiTDxZe6Zpab5QglNY7mtMkuzIsvBlqiDip4DtzOeA03d8C5LT7Y0Ea1/tU/O+Pjq/SncnArmsF3ztj60aN6uCfJ3Vh2/m97TkOw4IWMbRRD9kkelx7Uvqy1POgF/D0qI+OfhMad7MKMsFg==",
12
+ "x-flow-device-id": "xqGy17TUy56Ekt4Nsr4np",
13
+ "x-nonce": "6bb24d8ce5e09df641c8217f250bd8ab",
14
+ "x-signature": "a0f9a9350d566b207804d722421f8914",
15
+ "x-timestamp": "1734007773"
16
+ }
17
+
18
+ # Define the payload
19
+ payload = {
20
+ "documentIds": [],
21
+ "generateAudio": True,
22
+ "generateImage": False,
23
+ "history": [{"role": "assistant", "content": "Hello There !"}],
24
+ "content": "Hello There !",
25
+ "role": "assistant",
26
+ "model": "deepseek-chat",
27
+ "nsfw": False,
28
+ "promptId": "O9jUyVB4crxHKegm6stS6",
29
+ "question": "اهلا",
30
+ "system": "you are AI Model From Libyan Team (CORVO AI)\n\nyou are the next model after ALEX-9\n\nand your current name is ALEX-9 Pro\n\nchat with users and be Funny smart and powerful OF AI",
31
+ "temperature": 0.7,
32
+ "userId": "IT1NKob-8PlcvItgv5dHj"
33
+ }
34
+
35
+ # Send the POST request
36
+ response = requests.post(url, headers=headers, json=payload)
37
+
38
+ # Print the response text
39
+ print(response.text)