Lei075fr commited on
Commit
7d8caa0
·
verified ·
1 Parent(s): 348cf47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -48
app.py CHANGED
@@ -1,71 +1,84 @@
1
- import os, random, httpx, uvicorn
2
  from fastapi import FastAPI, Request, Response
3
  from fastapi.responses import HTMLResponse
4
 
5
  app = FastAPI()
6
 
7
- # Pool de 15 Chaves
 
8
  KEYS = [os.getenv(f"OR_KEY_{i}") for i in range(1, 16)]
9
  KEYS = [k for k in KEYS if k and k.strip()]
10
 
11
- # MAPEAMENTO DE ELITE (Cérebros Pesados - Atualizado para Qwen3)
12
  MODEL_MAP = {
13
- "gpt-4o": "qwen/qwen3-coder:free",
14
- "vitalis": "google/gemini-2.0-pro-exp-02-05:free",
15
- "nexos": "qwen/qwen3-coder:free",
16
- "nutrilens": "google/gemini-2.0-flash-lite-preview-02-05:free",
17
- "default": "qwen/qwen3-coder:free"
18
  }
19
 
20
  @app.get("/", response_class=HTMLResponse)
21
  async def root():
22
- return f"<h1>🛡️ Escudo Fortune Ativo: {len(KEYS)} Chaves Operacionais</h1>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  @app.post("/v1/chat/completions")
25
  async def proxy(request: Request):
26
- if not KEYS:
27
- return Response(content='{"error": "Adiciona as chaves nos Secrets!"}', status_code=500)
28
-
29
- body = await request.json()
30
- msg_content = str(body.get("messages", "")).lower()
31
-
32
- # Roteador Inteligente de Projectos
33
- target = MODEL_MAP["gpt-4o"]
34
- if "vitalis" in msg_content: target = MODEL_MAP["vitalis"]
35
- elif "nexos" in msg_content: target = MODEL_MAP["nexos"]
36
- elif "nutrilens" in msg_content: target = MODEL_MAP["nutrilens"]
37
 
38
- body["model"] = target
39
- selected_key = random.choice(KEYS)
40
-
41
- headers = {
42
- "Authorization": f"Bearer {selected_key}",
43
- "X-Title": "Aria_Sovereign_System",
44
- "HTTP-Referer": "https://fortune-dev-moz.io",
45
- "Content-Type": "application/json"
46
- }
 
 
 
 
 
 
 
 
 
47
 
48
- async with httpx.AsyncClient() as client:
49
- try:
50
- resp = await client.post(
 
51
  "https://openrouter.ai/api/v1/chat/completions",
52
- json=body, headers=headers, timeout=60.0
 
 
53
  )
 
54
 
55
- # Modo de Emergência Absoluta:
56
- # Se a chave ou modelo falhar, ele usa o roteador livre do OpenRouter e troca de chave
57
- if resp.status_code != 200:
58
- print(f"⚠️ Erro {resp.status_code}, a ativar emergência...")
59
- body["model"] = "openrouter/free"
60
- headers["Authorization"] = f"Bearer {random.choice(KEYS)}"
61
- resp = await client.post(
62
- "https://openrouter.ai/api/v1/chat/completions",
63
- json=body, headers=headers, timeout=60.0
64
- )
65
-
66
- return Response(content=resp.content, status_code=resp.status_code)
67
- except Exception as e:
68
- return Response(content=f'{{"error": "{str(e)}"}}', status_code=500)
69
 
70
  if __name__ == "__main__":
71
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
 
1
+ import os, random, httpx, uvicorn, asyncio
2
  from fastapi import FastAPI, Request, Response
3
  from fastapi.responses import HTMLResponse
4
 
5
  app = FastAPI()
6
 
7
+ # --- ARSENAL DE CHAVES (Pool de 15 chaves - Operação Sofala) ---
8
+ # Carrega as chaves do OpenRouter configuradas nos Secrets do Hugging Face
9
  KEYS = [os.getenv(f"OR_KEY_{i}") for i in range(1, 16)]
10
  KEYS = [k for k in KEYS if k and k.strip()]
11
 
12
+ # --- MAPEAMENTO UNIFICADO (Cérebro Qwen3 Coder como Padrão) ---
13
  MODEL_MAP = {
14
+ "aria_coder": "qwen/qwen3-coder:free",
15
+ "aria_brain": "nvidia/nemotron-3-super:free",
16
+ "aria_med": "google/gemini-2.5-pro:free",
17
+ "aria_default": "qwen/qwen3-coder:free"
 
18
  }
19
 
20
  @app.get("/", response_class=HTMLResponse)
21
  async def root():
22
+ # Painel Visual de Poder Total
23
+ status_color = "#ff00ff" if KEYS else "#ff4444"
24
+ return f"""
25
+ <html>
26
+ <head>
27
+ <title>Aria Shield V2.8</title>
28
+ <meta charset="utf-8">
29
+ </head>
30
+ <body style='background:#050505; color:{status_color}; font-family:monospace; text-align:center; padding-top:100px;'>
31
+ <div style='border: 2px solid {status_color}; display:inline-block; padding:50px; background:#000; box-shadow: 0 0 30px {status_color}55; border-radius:15px;'>
32
+ <h1 style='letter-spacing:10px;'>ARIA SHIELD V2.8</h1>
33
+ <h2 style='color:#fff;'>UNLEASHED POWER EDITION</h2>
34
+ <p style='font-size:1.2em;'>Arsenal: <strong>{len(KEYS)} APIs Simultâneas</strong></p>
35
+ <p style='color:#444;'>Localização: Beira, Sofala, MZ</p>
36
+ <hr style='border:0.5px solid #222; margin: 30px 0;'>
37
+ <p style='font-size:1.8em; font-weight:bold;'>🔥 PODER TOTAL ATIVADO</p>
38
+ <p style='color:#666; font-size:0.8em;'>Buffers: 8K Tokens | Timeout: 300s</p>
39
+ </div>
40
+ </body>
41
+ </html>
42
+ """
43
 
44
  @app.post("/v1/chat/completions")
45
  async def proxy(request: Request):
46
+ if not KEYS:
47
+ return Response(content='{"error": "Sem combustível! Configure as chaves OR_KEY_1 a 15."}', status_code=500)
 
 
 
 
 
 
 
 
 
48
 
49
+ try:
50
+ body = await request.json()
51
+ model_requested = body.get("model", "")
52
+
53
+ # 1. TRADUÇÃO DE MODELO: Limpa prefixos e mapeia para os IDs do OpenRouter
54
+ clean_model = model_requested.replace("fortune/", "")
55
+ body["model"] = MODEL_MAP.get(clean_model, clean_model)
56
+
57
+ # 2. OTIMIZAÇÃO DE FLUXO MASSIVO:
58
+ # Forçamos 8192 tokens para evitar que a Aria trunque o raciocínio clínico ou código.
59
+ body["max_tokens"] = 8192
60
+
61
+ headers = {
62
+ "Authorization": f"Bearer {random.choice(KEYS)}",
63
+ "HTTP-Referer": "https://github.com/Fortnee/Ariaaa",
64
+ "X-Title": "Aria Sovereign System",
65
+ "Content-Type": "application/json"
66
+ }
67
 
68
+ # 3. CONEXÃO RESILIENTE:
69
+ # Aumentamos o timeout para 5 minutos (300.0) para buscas profundas na Internet.
70
+ async with httpx.AsyncClient() as client:
71
+ response = await client.post(
72
  "https://openrouter.ai/api/v1/chat/completions",
73
+ json=body,
74
+ headers=headers,
75
+ timeout=300.0
76
  )
77
+ return Response(content=response.content, status_code=response.status_code)
78
 
79
+ except Exception as e:
80
+ return Response(content=f'{{"error": "Falha na combustão do motor: {str(e)}"}}', status_code=500)
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
  if __name__ == "__main__":
83
+ print("🛰️ Injetando 15 chaves no sistema... Aria Shield V2.8 Online.")
84
+ uvicorn.run(app, host="0.0.0.0", port=7860)