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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -37
app.py CHANGED
@@ -1,41 +1,41 @@
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>
@@ -43,42 +43,59 @@ async def root():
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)
 
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
+ # --- ARSENAL DE CHAVES (Pool de 15 Chaves - Operação Beira) ---
 
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) ---
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
+ # Painel Visual de Poder Total - V2.8.5
23
  status_color = "#ff00ff" if KEYS else "#ff4444"
24
  return f"""
25
  <html>
26
  <head>
27
+ <title>Aria Shield V2.8.5</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.5</h1>
33
+ <h2 style='color:#fff;'>HYBRID CORE EDITION</h2>
34
+ <p style='font-size:1.2em;'>Arsenal: <strong>{len(KEYS)} Chaves Operacionais</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;'>🔥 ROTEAMENTO INTELIGENTE ATIVADO</p>
38
+ <p style='color:#666; font-size:0.8em;'>Anti-Truncagem: 8K Tokens | Timeout: 300s</p>
39
  </div>
40
  </body>
41
  </html>
 
43
 
44
  @app.post("/v1/chat/completions")
45
  async def proxy(request: Request):
46
+ if not KEYS:
47
+ return Response(content='{"error": "Adiciona as chaves nos Secrets!"}', status_code=500)
48
+
49
  try:
50
  body = await request.json()
51
+ msg_content = str(body.get("messages", "")).lower()
52
+
53
+ # --- Roteador Inteligente de Projectos do CEO ---
54
+ target = MODEL_MAP["gpt-4o"]
55
+ if "vitalis" in msg_content:
56
+ target = MODEL_MAP["vitalis"]
57
+ elif "nexos" in msg_content:
58
+ target = MODEL_MAP["nexos"]
59
+ elif "nutrilens" in msg_content:
60
+ target = MODEL_MAP["nutrilens"]
61
 
62
+ body["model"] = target
 
 
63
 
64
+ # --- OTIMIZAÇÃO PARA OUTPUTS LONGOS (Aria Unleashed) ---
65
+ body["max_tokens"] = 8192 # Força o modelo a entregar o código ou pesquisa completa sem truncar
 
66
 
67
+ selected_key = random.choice(KEYS)
68
+
69
  headers = {
70
+ "Authorization": f"Bearer {selected_key}",
71
+ "X-Title": "Aria_Sovereign_System",
72
+ "HTTP-Referer": "https://fortune-dev-moz.io",
73
  "Content-Type": "application/json"
74
  }
75
 
 
 
76
  async with httpx.AsyncClient() as client:
77
+ # Timeout de 5 minutos (300s) para não derrubar pesquisas massivas da web
78
+ resp = await client.post(
79
  "https://openrouter.ai/api/v1/chat/completions",
80
+ json=body, headers=headers, timeout=300.0
 
 
81
  )
82
+
83
+ # --- Modo de Emergência Absoluta ---
84
+ # Se a chave ou modelo falhar (ex: Rate limit no Gemini Pro), troca de chave e força um modelo livre genérico
85
+ if resp.status_code != 200:
86
+ print(f"⚠️ Erro {resp.status_code} no modelo {target}. A ativar emergência...")
87
+ body["model"] = "openrouter/free"
88
+ headers["Authorization"] = f"Bearer {random.choice(KEYS)}"
89
+
90
+ resp = await client.post(
91
+ "https://openrouter.ai/api/v1/chat/completions",
92
+ json=body, headers=headers, timeout=300.0
93
+ )
94
+
95
+ return Response(content=resp.content, status_code=resp.status_code)
96
 
97
  except Exception as e:
98
+ return Response(content=f'{{"error": "Falha crítica no núcleo: {str(e)}"}}', status_code=500)
99
 
100
  if __name__ == "__main__":
 
101
  uvicorn.run(app, host="0.0.0.0", port=7860)