Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -18,7 +18,7 @@ secret_api_endpoint = os.getenv('SECRET_API_ENDPOINT')
|
|
18 |
|
19 |
# Check if the endpoint is set in the environment
|
20 |
if not secret_api_endpoint:
|
21 |
-
raise HTTPException(status_code=500, detail="
|
22 |
|
23 |
class Payload(BaseModel):
|
24 |
model: str
|
@@ -43,6 +43,7 @@ async def root():
|
|
43 |
<body>
|
44 |
<h1>Welcome to Loki.AI API!</h1>
|
45 |
<p>Created by Parth Sadaria</p>
|
|
|
46 |
<p>Check out the GitHub for more projects:</p>
|
47 |
<a href="https://github.com/ParthSadaria" target="_blank">github.com/ParthSadaria</a>
|
48 |
</body>
|
@@ -55,13 +56,13 @@ async def root():
|
|
55 |
async def get_cached_models():
|
56 |
async with httpx.AsyncClient() as client:
|
57 |
try:
|
58 |
-
response = await client.get(f"{secret_api_endpoint}/
|
59 |
response.raise_for_status()
|
60 |
return response.json()
|
61 |
except httpx.RequestError as e:
|
62 |
raise HTTPException(status_code=500, detail=f"Request failed: {e}")
|
63 |
|
64 |
-
@app.get("/models")
|
65 |
async def get_models():
|
66 |
return await get_cached_models()
|
67 |
|
|
|
18 |
|
19 |
# Check if the endpoint is set in the environment
|
20 |
if not secret_api_endpoint:
|
21 |
+
raise HTTPException(status_code=500, detail="API endpoint is not configured in environment variables.")
|
22 |
|
23 |
class Payload(BaseModel):
|
24 |
model: str
|
|
|
43 |
<body>
|
44 |
<h1>Welcome to Loki.AI API!</h1>
|
45 |
<p>Created by Parth Sadaria</p>
|
46 |
+
<p>Go to /models for more info</p>
|
47 |
<p>Check out the GitHub for more projects:</p>
|
48 |
<a href="https://github.com/ParthSadaria" target="_blank">github.com/ParthSadaria</a>
|
49 |
</body>
|
|
|
56 |
async def get_cached_models():
|
57 |
async with httpx.AsyncClient() as client:
|
58 |
try:
|
59 |
+
response = await client.get(f"{secret_api_endpoint}/v1/models", timeout=3)
|
60 |
response.raise_for_status()
|
61 |
return response.json()
|
62 |
except httpx.RequestError as e:
|
63 |
raise HTTPException(status_code=500, detail=f"Request failed: {e}")
|
64 |
|
65 |
+
@app.get("v1/models")
|
66 |
async def get_models():
|
67 |
return await get_cached_models()
|
68 |
|