Lei075fr commited on
Commit
2cb5b51
·
verified ·
1 Parent(s): 50cbfa8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, random, httpx, uvicorn
2
+ from fastapi import FastAPI, Request, Response
3
+
4
+ app = FastAPI()
5
+ KEYS = [os.getenv(f"OR_KEY_{i}") for i in range(1, 16) if os.getenv(f"OR_KEY_{i}")]
6
+
7
+ MODEL_MAP = {
8
+ "vitalis": "google/gemini-2.0-pro-exp-02-05:free",
9
+ "nexos": "meta-llama/llama-4-8b-scout:free",
10
+ "nutrilens": "anthropic/claude-3.5-sonnet:beta",
11
+ "default": "google/gemini-2.0-flash-lite:preview"
12
+ }
13
+
14
+ @app.post("/v1/chat/completions")
15
+ async def proxy(request: Request):
16
+ body = await request.json()
17
+ msg = str(body.get("messages", "")).lower()
18
+
19
+ # Roteamento Inteligente
20
+ selected = MODEL_MAP["default"]
21
+ for proj in ["vitalis", "nexos", "nutrilens"]:
22
+ if proj in msg: selected = MODEL_MAP[proj]
23
+ body["model"] = selected
24
+
25
+ headers = {
26
+ "Authorization": f"Bearer {random.choice(KEYS)}",
27
+ "X-Title": f"Fortune_Shield_{random.randint(100,999)}",
28
+ "HTTP-Referer": "https://fortune-dev.io",
29
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
30
+ }
31
+
32
+ async with httpx.AsyncClient() as client:
33
+ try:
34
+ resp = await client.post("https://openrouter.ai/api/v1/chat/completions",
35
+ json=body, headers=headers, timeout=60.0)
36
+ return Response(content=resp.content, status_code=resp.status_code)
37
+ except Exception as e:
38
+ return Response(content=f'{{"error": "{str(e)}"}}', status_code=500)
39
+
40
+ if __name__ == "__main__":
41
+ uvicorn.run(app, host="0.0.0.0", port=7860)