Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,10 @@ from fastapi import FastAPI, Request, HTTPException
|
|
| 4 |
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
from fastapi.responses import StreamingResponse
|
| 6 |
|
|
|
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
|
|
| 9 |
app.add_middleware(
|
| 10 |
CORSMiddleware,
|
| 11 |
allow_origins=["*"],
|
|
@@ -13,16 +15,22 @@ app.add_middleware(
|
|
| 13 |
allow_headers=["*"],
|
| 14 |
)
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
SECRET_TOKEN = "uISssvLLmXK0bsrcFICh14o7aj4q2ZT4"
|
| 18 |
API_KEY = os.getenv("SECRET_API_KEY")
|
| 19 |
API_URL = os.getenv("SECRET_API_URL")
|
| 20 |
MODEL_NAME = os.getenv("SECRET_MODEL_NAME")
|
| 21 |
SYSTEM_PROMPT = os.getenv("SECRET_SYSTEM_PROMPT")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
|
|
|
| 23 |
@app.post("/v1/chat/completions")
|
| 24 |
async def chat_completions(request: Request):
|
| 25 |
-
# टोकन वेरिफिकेशन
|
| 26 |
auth_header = request.headers.get("Authorization")
|
| 27 |
if auth_header != f"Bearer {SECRET_TOKEN}":
|
| 28 |
raise HTTPException(status_code=401, detail="Unauthorized: Invalid Token")
|
|
@@ -30,7 +38,7 @@ async def chat_completions(request: Request):
|
|
| 30 |
data = await request.json()
|
| 31 |
user_messages = data.get("messages", [])
|
| 32 |
|
| 33 |
-
#
|
| 34 |
full_messages = [{"role": "system", "content": SYSTEM_PROMPT}] + user_messages
|
| 35 |
|
| 36 |
payload = {
|
|
|
|
| 4 |
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
from fastapi.responses import StreamingResponse
|
| 6 |
|
| 7 |
+
# एप्लीकेशन की नींव
|
| 8 |
app = FastAPI()
|
| 9 |
|
| 10 |
+
# CORS पॉलिसी
|
| 11 |
app.add_middleware(
|
| 12 |
CORSMiddleware,
|
| 13 |
allow_origins=["*"],
|
|
|
|
| 15 |
allow_headers=["*"],
|
| 16 |
)
|
| 17 |
|
| 18 |
+
# सीक्रेट्स से डेटा प्राप्त करना
|
|
|
|
| 19 |
API_KEY = os.getenv("SECRET_API_KEY")
|
| 20 |
API_URL = os.getenv("SECRET_API_URL")
|
| 21 |
MODEL_NAME = os.getenv("SECRET_MODEL_NAME")
|
| 22 |
SYSTEM_PROMPT = os.getenv("SECRET_SYSTEM_PROMPT")
|
| 23 |
+
SECRET_TOKEN = "uISssvLLmXK0bsrcFICh14o7aj4q2ZT4"
|
| 24 |
+
|
| 25 |
+
# 1. रूट हेल्थ चेक (ताकि वह प्लेटफ़ॉर्म सर्वर को ढूंढ सके)
|
| 26 |
+
@app.get("/")
|
| 27 |
+
async def root():
|
| 28 |
+
return {"status": "Aura Gen 2.0 is online"}
|
| 29 |
|
| 30 |
+
# 2. ओपन एआई फॉर्मेट एंडपॉइंट
|
| 31 |
@app.post("/v1/chat/completions")
|
| 32 |
async def chat_completions(request: Request):
|
| 33 |
+
# टोकन वेरिफिकेशन
|
| 34 |
auth_header = request.headers.get("Authorization")
|
| 35 |
if auth_header != f"Bearer {SECRET_TOKEN}":
|
| 36 |
raise HTTPException(status_code=401, detail="Unauthorized: Invalid Token")
|
|
|
|
| 38 |
data = await request.json()
|
| 39 |
user_messages = data.get("messages", [])
|
| 40 |
|
| 41 |
+
# सिस्टम प्रॉम्ट जोड़ना
|
| 42 |
full_messages = [{"role": "system", "content": SYSTEM_PROMPT}] + user_messages
|
| 43 |
|
| 44 |
payload = {
|