CORVO-AI commited on
Commit
11f6cf9
·
verified ·
1 Parent(s): 5b0931e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -47
app.py CHANGED
@@ -1,69 +1,57 @@
1
  from flask import Flask, request, jsonify
2
  import requests
3
- import json
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": "deepseek-chat",
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
67
 
68
  if __name__ == "__main__":
69
  app.run(host="0.0.0.0", port=7860)
 
1
  from flask import Flask, request, jsonify
2
  import requests
 
3
 
4
  app = Flask(__name__)
5
 
6
+ # Define the URL and headers for the external API
7
+ EXTERNAL_API_URL = "https://api.botpress.cloud/v1/cognitive/chat-gpt/query"
8
+ HEADERS = {
 
 
 
9
  "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",
10
+ "x-bot-id": "fbe047bc-06fb-44c1-9672-342fe1a2e506",
11
+ "Content-Type": "application/json",
12
+ "Cookie": "YOUR_COOKIES_HERE", # Replace with actual cookie value
 
 
 
13
  }
14
 
15
+ @app.route('/query', methods=['POST'])
16
+ def query():
17
  try:
18
+ # Get the JSON payload from the request
19
  data = request.get_json()
20
  question = data.get('question', '')
21
  history = data.get('history', [])
22
 
23
+ # Construct the payload for the external API
24
  payload = {
25
+ "prompt": {
26
+ "messages": history + [
27
+ {"role": "user", "content": question}
28
+ ],
29
+ "model": "gpt-4o",
30
+ "temperature": 0.9,
31
+ "signatureVersion": "Jan-2024",
32
+ },
33
+ "variables": {
34
+ "TASK_INPUT": ""
35
+ },
36
+ "options": {
37
+ "origin": "cards/ai-task",
38
+ },
39
+ "origin": "cards/ai-task",
 
 
 
 
40
  }
41
 
42
+ # Send the POST request to the external API
43
+ response = requests.post(EXTERNAL_API_URL, json=payload, headers=HEADERS)
 
 
 
 
 
 
 
44
 
45
+ # Check the response status
46
+ if response.status_code == 200:
47
+ response_json = response.json()
48
+ assistant_content = response_json.get('choices', [{}])[0].get('message', {}).get('content', '')
49
+ return jsonify({"success": True, "response": assistant_content})
50
+ else:
51
+ return jsonify({"success": False, "error": response.text}), response.status_code
52
 
53
  except Exception as e:
54
+ return jsonify({"success": False, "error": str(e)}), 500
55
 
56
  if __name__ == "__main__":
57
  app.run(host="0.0.0.0", port=7860)