Spaces:
Paused
Paused
Update app.py
Browse files4 unmodified lines5678910112 unmodified lines1415161718192021222324252627282930313233343536373839404142434445464748495051524 unmodified linesapp = Flask(__name__)CORS(app)# 🔱 ඔබ ලබා දුන් API KeysAPI_KEYS = ["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","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",2 unmodified lines"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"]@app.route('/api/chat', methods=['POST'])def chat():try:data = request.jsonuser_msg = data.get("message", "")headers = {"Authorization": f"Bearer {random.choice(API_KEYS)}","Content-Type": "application/json"}payload = {"model": "minimax/minimax-m2.5:free","messages": [{"role": "system", "content": "You are Elephant AI created by MINZO-PRIME. Be helpful and professional."},{"role": "user", "content": user_msg}],"stream": False # 🔱 ස්ථාවරත්වය සඳහා Streaming අක්රීය කළා}resp = requests.post("https://openrouter.ai/api/v1/chat/completions", headers=headers, json=payload)res_data = resp.json()# පිළිතුර ලබා ගැනීමai_reply = res_data['choices'][0]['message']['content']return jsonify({"reply": ai_reply})except Exception as e:return jsonify({"reply": f"Core Error: {str(e)}"}), 500@app.route('/')def health():return "🐘 Elephant AI Core: ONLINE"if __name__ == "__main__":app.run(host='0.0.0.0', port=7860)4 unmodified lines5678910112 unmodified lines141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485864 unmodified linesapp = Flask(__name__)CORS(app)# 🔱 AUTHORIZED API KEYSAPI_KEYS = ["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","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",2 unmodified lines"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"]def fetch_web_intel(query):"""අන්තර්ජාලයෙන් නවතම තොරතුරු ලබා ගැනීම (RSS Intelligence)"""intel = ""try:# Google News RSS හරහා සෙවීමsearch_url = f'https://news.google.com/rss/search?q={query}&hl=en-US'feed = feedparser.parse(search_url)# මුල් ලිපි 3ක තොරතුරු එකතු කිරීමfor entry in feed.entries[:3]:intel += f"\n- Title: {entry.title} (Source: {entry.source.text if 'source' in entry else 'Web'})"except Exception as e:print(f"Web Intel Error: {e}")return intel@app.route('/api/chat', methods=['POST'])def chat():try:data = request.jsonuser_msg = data.get("message", "")# 1. 🔱 WEB SEARCH EXECUTION# පද්ධතිය බුද්ධිමත් ලෙස සෙවුම් වාරයක් ක්රියාත්මක කරයිweb_context = fetch_web_intel(user_msg)headers = {"Authorization": f"Bearer {random.choice(API_KEYS)}","Content-Type": "application/json","HTTP-Referer": "https://huggingface.co/spaces/minzo456/Elephant-AI-Core","X-Title": "Elephant AI Core"}# 2. 🔱 INTEGRATING INTEL INTO SYSTEM PROMPTsystem_prompt = f"""You are Elephant AI, an advanced intelligence created by MINZO-PRIME.You have access to real-time web information.If relevant, use this fresh data to answer: {web_context}Always prioritize accuracy and be professional."""payload = {"model": "minimax/minimax-m2.5:free","messages": [{"role": "system", "content": system_prompt},{"role": "user", "content": user_msg}],"stream": False}resp = requests.post("https://openrouter.ai/api/v1/chat/completions",headers=headers,json=payload,timeout=45)res_data = resp.json()if 'choices' in res_data:ai_reply = res_data['choices'][0]['message']['content']return jsonify({"reply": ai_reply})else:return jsonify({"reply": "Core Error: Failed to retrieve intelligence from OpenRouter."}), 500except Exception as e:return jsonify({"reply": f"Internal System Error: {str(e)}"}), 500@app.route('/')def health():return "🐘 Elephant AI Core: ONLINE | WEB INTEL: ACTIVE"if __name__ == "__main__":app.run(host='0.0.0.0', port=7860)
app.py+44-10