Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,10 +24,11 @@ async def root():
|
|
| 24 |
<body style="background: #0e1117; color: white; font-family: sans-serif; text-align: center; padding-top: 50px;">
|
| 25 |
<h1 style="color: {status_color};">🛡️ Escudo Fortune Ativo</h1>
|
| 26 |
<p><b>{len(KEYS)}</b> chaves operacionais no sistema.</p>
|
| 27 |
-
<p style="color: #888;">Status:
|
| 28 |
</body>
|
| 29 |
"""
|
| 30 |
|
|
|
|
| 31 |
@app.post("/v1/chat/completions")
|
| 32 |
async def proxy(request: Request):
|
| 33 |
if not KEYS:
|
|
@@ -37,7 +38,7 @@ async def proxy(request: Request):
|
|
| 37 |
body = await request.json()
|
| 38 |
msg_content = str(body.get("messages", "")).lower()
|
| 39 |
|
| 40 |
-
# 🛰️ Roteador Inteligente de Projetos
|
| 41 |
target = MODEL_MAP["gpt-4o"]
|
| 42 |
if "vitalis" in msg_content:
|
| 43 |
target = MODEL_MAP["vitalis"]
|
|
@@ -48,7 +49,6 @@ async def proxy(request: Request):
|
|
| 48 |
|
| 49 |
body["model"] = target
|
| 50 |
|
| 51 |
-
# ⚡ Seleção de Chave com Limpeza de Caracteres Invisíveis
|
| 52 |
selected_key = random.choice(KEYS).strip()
|
| 53 |
|
| 54 |
headers = {
|
|
@@ -66,7 +66,7 @@ async def proxy(request: Request):
|
|
| 66 |
timeout=60.0
|
| 67 |
)
|
| 68 |
|
| 69 |
-
# 🚨 Modo de Emergência
|
| 70 |
if resp.status_code != 200:
|
| 71 |
print(f"⚠️ Erro {resp.status_code} na chave atual. Tentando emergência...")
|
| 72 |
body["model"] = "openrouter/free"
|
|
@@ -86,5 +86,22 @@ async def proxy(request: Request):
|
|
| 86 |
print(f"🔥 Erro Crítico: {str(e)}")
|
| 87 |
return Response(content=f'{{"error": "{str(e)}"}}', status_code=500)
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
if __name__ == "__main__":
|
| 90 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 24 |
<body style="background: #0e1117; color: white; font-family: sans-serif; text-align: center; padding-top: 50px;">
|
| 25 |
<h1 style="color: {status_color};">🛡️ Escudo Fortune Ativo</h1>
|
| 26 |
<p><b>{len(KEYS)}</b> chaves operacionais no sistema.</p>
|
| 27 |
+
<p style="color: #888;">Status: Roteador AI e Ponte Telegram Operacionais.</p>
|
| 28 |
</body>
|
| 29 |
"""
|
| 30 |
|
| 31 |
+
# 1️⃣ ROTA DO CÉREBRO (Modelos de IA)
|
| 32 |
@app.post("/v1/chat/completions")
|
| 33 |
async def proxy(request: Request):
|
| 34 |
if not KEYS:
|
|
|
|
| 38 |
body = await request.json()
|
| 39 |
msg_content = str(body.get("messages", "")).lower()
|
| 40 |
|
| 41 |
+
# 🛰️ Roteador Inteligente de Projetos
|
| 42 |
target = MODEL_MAP["gpt-4o"]
|
| 43 |
if "vitalis" in msg_content:
|
| 44 |
target = MODEL_MAP["vitalis"]
|
|
|
|
| 49 |
|
| 50 |
body["model"] = target
|
| 51 |
|
|
|
|
| 52 |
selected_key = random.choice(KEYS).strip()
|
| 53 |
|
| 54 |
headers = {
|
|
|
|
| 66 |
timeout=60.0
|
| 67 |
)
|
| 68 |
|
| 69 |
+
# 🚨 Modo de Emergência
|
| 70 |
if resp.status_code != 200:
|
| 71 |
print(f"⚠️ Erro {resp.status_code} na chave atual. Tentando emergência...")
|
| 72 |
body["model"] = "openrouter/free"
|
|
|
|
| 86 |
print(f"🔥 Erro Crítico: {str(e)}")
|
| 87 |
return Response(content=f'{{"error": "{str(e)}"}}', status_code=500)
|
| 88 |
|
| 89 |
+
# 2️⃣ ROTA DA BOCA/OUVIDOS (Ponte de Rede para o Telegram)
|
| 90 |
+
@app.api_route("/bot{token}/{method_name}", methods=["GET", "POST"])
|
| 91 |
+
async def telegram_proxy(request: Request, token: str, method_name: str):
|
| 92 |
+
target_url = f"https://api.telegram.org/bot{token}/{method_name}"
|
| 93 |
+
try:
|
| 94 |
+
async with httpx.AsyncClient() as client:
|
| 95 |
+
if request.method == "POST":
|
| 96 |
+
body = await request.body()
|
| 97 |
+
headers = {"Content-Type": request.headers.get("content-type", "application/json")}
|
| 98 |
+
resp = await client.post(target_url, content=body, headers=headers, timeout=60.0)
|
| 99 |
+
else:
|
| 100 |
+
resp = await client.get(target_url, params=request.query_params, timeout=60.0)
|
| 101 |
+
return Response(content=resp.content, status_code=resp.status_code)
|
| 102 |
+
except Exception as e:
|
| 103 |
+
print(f"🔥 Erro na Ponte Telegram: {str(e)}")
|
| 104 |
+
return Response(content=f'{{"ok": false, "error_code": 500, "description": "Erro no Escudo: {str(e)}"}}', status_code=500)
|
| 105 |
+
|
| 106 |
if __name__ == "__main__":
|
| 107 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|