Hanuman2 commited on
Commit
dc8adb8
·
verified ·
1 Parent(s): 4a903b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -5,7 +5,7 @@ import os
5
 
6
  app = FastAPI()
7
 
8
- # CORS इनेबल करना ताकि आपका फ्रंटएंड इसे एक्सेस कर सके
9
  app.add_middleware(
10
  CORSMiddleware,
11
  allow_origins=["*"],
@@ -13,13 +13,21 @@ app.add_middleware(
13
  allow_headers=["*"],
14
  )
15
 
 
16
  NVIDIA_API_KEY = os.getenv("NVIDIA_API_KEY")
17
  MODEL_NAME = os.getenv("MODEL_NAME", "microsoft/phi-4-multimodal-instruct")
18
  API_URL = "https://integrate.api.nvidia.com/v1/chat/completions"
19
 
 
 
 
20
  @app.post("/v1/chat/completions")
21
  async def chat_proxy(request: Request):
22
  data = await request.json()
 
 
 
 
23
 
24
  async with httpx.AsyncClient() as client:
25
  response = await client.post(
@@ -30,10 +38,13 @@ async def chat_proxy(request: Request):
30
  },
31
  json={
32
  "model": MODEL_NAME,
33
- "messages": data.get("messages"),
34
  "max_tokens": data.get("max_tokens", 4096),
35
  "temperature": data.get("temperature", 0.6),
36
- "top_p": 0.70
 
 
 
37
  },
38
  timeout=60.0
39
  )
@@ -41,4 +52,5 @@ async def chat_proxy(request: Request):
41
 
42
  if __name__ == "__main__":
43
  import uvicorn
 
44
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
5
 
6
  app = FastAPI()
7
 
8
+ # CORS इनेबल करना
9
  app.add_middleware(
10
  CORSMiddleware,
11
  allow_origins=["*"],
 
13
  allow_headers=["*"],
14
  )
15
 
16
+ # कॉन्फ़िगरेशन - Secrets से लें
17
  NVIDIA_API_KEY = os.getenv("NVIDIA_API_KEY")
18
  MODEL_NAME = os.getenv("MODEL_NAME", "microsoft/phi-4-multimodal-instruct")
19
  API_URL = "https://integrate.api.nvidia.com/v1/chat/completions"
20
 
21
+ # सिस्टम प्रॉम्ट जो हमेशा सर्वर पर रहेगा
22
+ SYSTEM_PROMPT = "You are Aura Gen 2.0, a state-of-the-art AI assistant developed by Divy Bhai. You possess world-class expertise in software engineering, advanced algorithmic logic, and complex problem-solving. Always provide highly optimized, secure, and precise solutions in English by default. Use Markdown formatting extensively (code blocks, tables, lists) to structure your answers clearly and effectively."
23
+
24
  @app.post("/v1/chat/completions")
25
  async def chat_proxy(request: Request):
26
  data = await request.json()
27
+ user_messages = data.get("messages", [])
28
+
29
+ # हमेशा सिस्टम प्रॉम्ट को सबसे ऊपर जोड़ें
30
+ full_messages = [{"role": "system", "content": SYSTEM_PROMPT}] + user_messages
31
 
32
  async with httpx.AsyncClient() as client:
33
  response = await client.post(
 
38
  },
39
  json={
40
  "model": MODEL_NAME,
41
+ "messages": full_messages,
42
  "max_tokens": data.get("max_tokens", 4096),
43
  "temperature": data.get("temperature", 0.6),
44
+ "top_p": 0.70,
45
+ "frequency_penalty": 0.00,
46
+ "presence_penalty": 0.00,
47
+ "stream": False
48
  },
49
  timeout=60.0
50
  )
 
52
 
53
  if __name__ == "__main__":
54
  import uvicorn
55
+ # Hugging Face Spaces 7860 पोर्ट का उपयोग करता है
56
  uvicorn.run(app, host="0.0.0.0", port=7860)