minzo456 commited on
Commit
6e608ad
·
verified ·
1 Parent(s): d81eced

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -6,11 +6,10 @@ from flask import Flask, request, jsonify
6
  from flask_cors import CORS
7
  from datetime import datetime
8
 
9
- # 🔱 DuckDuckGo Library එක Import කිරීමේදී සිදුවන Error එක වැළැක්වීමට
10
  try:
11
  from duckduckgo_search import DDGS
12
  except ImportError:
13
- # මෙය Hugging Face වලදී Module එක නැවත තහවුරු කිරීමටයි
14
  os.system('pip install duckduckgo_search')
15
  from duckduckgo_search import DDGS
16
 
@@ -29,14 +28,12 @@ API_KEYS = [
29
  def fetch_duckduckgo_intel(query):
30
  intel = ""
31
  try:
32
- # 🔱 Latest version logic
33
- with DDGS() as ddgs:
34
- results = ddgs.text(query, max_results=4)
35
- for r in results:
36
- intel += f"\n- {r['title']}: {r['body']}"
37
  except Exception as e:
38
- print(f"Search Warning: {e}")
39
- intel = "Global intelligence access restricted."
40
  return intel
41
 
42
  @app.route('/api/chat', methods=['POST'])
@@ -46,6 +43,7 @@ def chat():
46
  user_msg = data.get("message", "")
47
  tier = data.get("tier", "prime")
48
 
 
49
  model_map = {
50
  "prime": "minimax/minimax-m2.5:free",
51
  "nexus": "tencent/hy3-preview:free"
@@ -62,22 +60,29 @@ def chat():
62
  "X-Title": "Elephant AI Core"
63
  }
64
 
65
- system_prompt = f"You are {tier.upper()} mode of Elephant AI by MINZO-PRIME. Time: {current_time}. Data: {web_context}"
 
 
 
66
 
67
  payload = {
68
  "model": selected_model,
69
- "messages": [{"role": "system", "content": system_prompt}, {"role": "user", "content": user_msg}]
 
 
 
70
  }
71
 
72
  resp = requests.post("https://openrouter.ai/api/v1/chat/completions", headers=headers, json=payload, timeout=60)
73
- return jsonify({"reply": resp.json()['choices'][0]['message']['content']})
 
74
 
75
  except Exception as e:
76
  return jsonify({"reply": f"Core Disruption: {str(e)}"}), 500
77
 
78
  @app.route('/')
79
  def health():
80
- return "🐘 Elephant AI Core: ONLINE"
81
 
82
  if __name__ == "__main__":
83
  app.run(host='0.0.0.0', port=7860)
 
6
  from flask_cors import CORS
7
  from datetime import datetime
8
 
9
+ # 🔱 Stable DDGS Integration
10
  try:
11
  from duckduckgo_search import DDGS
12
  except ImportError:
 
13
  os.system('pip install duckduckgo_search')
14
  from duckduckgo_search import DDGS
15
 
 
28
  def fetch_duckduckgo_intel(query):
29
  intel = ""
30
  try:
31
+ ddgs = DDGS()
32
+ results = ddgs.text(query, max_results=4)
33
+ for r in results:
34
+ intel += f"\n- {r['title']}: {r['body']}"
 
35
  except Exception as e:
36
+ intel = "Web intelligence access limited."
 
37
  return intel
38
 
39
  @app.route('/api/chat', methods=['POST'])
 
43
  user_msg = data.get("message", "")
44
  tier = data.get("tier", "prime")
45
 
46
+ # 🔱 Prime: Minimax | Nexus: Tencent Hy3
47
  model_map = {
48
  "prime": "minimax/minimax-m2.5:free",
49
  "nexus": "tencent/hy3-preview:free"
 
60
  "X-Title": "Elephant AI Core"
61
  }
62
 
63
+ system_prompt = f"""You are {tier.upper()} mode of Elephant AI by MINZO-PRIME.
64
+ System Time: {current_time}.
65
+ Live Web Data: {web_context}
66
+ Always maintain your sovereign identity."""
67
 
68
  payload = {
69
  "model": selected_model,
70
+ "messages": [
71
+ {"role": "system", "content": system_prompt},
72
+ {"role": "user", "content": user_msg}
73
+ ]
74
  }
75
 
76
  resp = requests.post("https://openrouter.ai/api/v1/chat/completions", headers=headers, json=payload, timeout=60)
77
+ ai_reply = resp.json()['choices'][0]['message']['content']
78
+ return jsonify({"reply": ai_reply})
79
 
80
  except Exception as e:
81
  return jsonify({"reply": f"Core Disruption: {str(e)}"}), 500
82
 
83
  @app.route('/')
84
  def health():
85
+ return "🐘 Elephant AI Core: ONLINE | Operator: MINZO-PRIME"
86
 
87
  if __name__ == "__main__":
88
  app.run(host='0.0.0.0', port=7860)