Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -20,6 +20,20 @@ class Payload(BaseModel):
|
|
20 |
model: str
|
21 |
messages: list
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
@app.post("/api/v1/chat/completions")
|
24 |
async def get_completion(payload: Payload, request: Request):
|
25 |
api_key = request.headers.get("Authorization")
|
@@ -51,6 +65,14 @@ async def get_completion(payload: Payload, request: Request):
|
|
51 |
except ValueError:
|
52 |
raise HTTPException(status_code=500, detail="Non-JSON response received")
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
# Run the server with Uvicorn using the 'main' module
|
55 |
if __name__ == "__main__":
|
56 |
import uvicorn
|
|
|
20 |
model: str
|
21 |
messages: list
|
22 |
|
23 |
+
@app.get("/")
|
24 |
+
async def root():
|
25 |
+
return {"message": "Hi, I am API made by mr_leaderyt"}
|
26 |
+
|
27 |
+
@app.get("/models")
|
28 |
+
async def get_models():
|
29 |
+
try:
|
30 |
+
response = requests.get("https://lokiai.vercel.app/api/v1/models")
|
31 |
+
response.raise_for_status()
|
32 |
+
models = response.json()
|
33 |
+
return models
|
34 |
+
except requests.exceptions.RequestException as e:
|
35 |
+
raise HTTPException(status_code=500, detail=f"Request failed: {e}")
|
36 |
+
|
37 |
@app.post("/api/v1/chat/completions")
|
38 |
async def get_completion(payload: Payload, request: Request):
|
39 |
api_key = request.headers.get("Authorization")
|
|
|
65 |
except ValueError:
|
66 |
raise HTTPException(status_code=500, detail="Non-JSON response received")
|
67 |
|
68 |
+
# Log the API endpoints
|
69 |
+
@app.on_event("startup")
|
70 |
+
async def startup_event():
|
71 |
+
print("API endpoints:")
|
72 |
+
print("GET /")
|
73 |
+
print("GET /models")
|
74 |
+
print("POST /api/v1/chat/completions")
|
75 |
+
|
76 |
# Run the server with Uvicorn using the 'main' module
|
77 |
if __name__ == "__main__":
|
78 |
import uvicorn
|