Spaces:
Sleeping
Sleeping
Update app.py
#11
by
sahil-1-garg
- opened
app.py
CHANGED
|
@@ -60,6 +60,12 @@ async def notes_llm_route(
|
|
| 60 |
use_rlhf: bool = Query(False),
|
| 61 |
user_api_key: Optional[str] = Form(None)
|
| 62 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
file_path = f"data/input/{file.filename}"
|
| 64 |
os.makedirs("data/input", exist_ok=True)
|
| 65 |
with open(file_path, "wb") as buffer:
|
|
@@ -110,6 +116,8 @@ async def notes_llm_route(
|
|
| 110 |
|
| 111 |
except ValueError as ve:
|
| 112 |
logger.error(f"API key error: {ve}")
|
|
|
|
|
|
|
| 113 |
raise HTTPException(status_code=400, detail=str(ve))
|
| 114 |
except Exception as e:
|
| 115 |
logger.error(f"LLM Notes pipeline failed: {e}")
|
|
@@ -328,6 +336,12 @@ async def pnl_route(file: UploadFile = File(...), use_rlhf: bool = Query(False))
|
|
| 328 |
|
| 329 |
@router.post("/bs")
|
| 330 |
async def bs_route(file: UploadFile = File(...), use_rlhf: bool = Query(False), user_api_key: Optional[str] = Form(None)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
file_path = f"data/input/{file.filename}"
|
| 332 |
os.makedirs("data/input", exist_ok=True)
|
| 333 |
with open(file_path, "wb") as buffer:
|
|
@@ -358,7 +372,14 @@ async def bs_route(file: UploadFile = File(...), use_rlhf: bool = Query(False),
|
|
| 358 |
|
| 359 |
return response
|
| 360 |
else:
|
| 361 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
|
| 363 |
|
| 364 |
@router.post("/cf")
|
|
|
|
| 60 |
use_rlhf: bool = Query(False),
|
| 61 |
user_api_key: Optional[str] = Form(None)
|
| 62 |
):
|
| 63 |
+
if not user_api_key or user_api_key.strip() == "":
|
| 64 |
+
raise HTTPException(
|
| 65 |
+
status_code=400,
|
| 66 |
+
detail="Missing required parameter: 'user_api_key'. Please provide your OpenRouter API key as a form parameter (not in JSON body)."
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
file_path = f"data/input/{file.filename}"
|
| 70 |
os.makedirs("data/input", exist_ok=True)
|
| 71 |
with open(file_path, "wb") as buffer:
|
|
|
|
| 116 |
|
| 117 |
except ValueError as ve:
|
| 118 |
logger.error(f"API key error: {ve}")
|
| 119 |
+
if "API key is required" in str(ve):
|
| 120 |
+
raise HTTPException(status_code=400, detail="Missing OpenRouter API key. Please provide your API key via the 'user_api_key' form parameter.")
|
| 121 |
raise HTTPException(status_code=400, detail=str(ve))
|
| 122 |
except Exception as e:
|
| 123 |
logger.error(f"LLM Notes pipeline failed: {e}")
|
|
|
|
| 336 |
|
| 337 |
@router.post("/bs")
|
| 338 |
async def bs_route(file: UploadFile = File(...), use_rlhf: bool = Query(False), user_api_key: Optional[str] = Form(None)):
|
| 339 |
+
if not user_api_key or user_api_key.strip() == "":
|
| 340 |
+
raise HTTPException(
|
| 341 |
+
status_code=400,
|
| 342 |
+
detail="Missing required parameter: 'user_api_key'. Please provide your OpenRouter API key as a form parameter (not in JSON body)."
|
| 343 |
+
)
|
| 344 |
+
|
| 345 |
file_path = f"data/input/{file.filename}"
|
| 346 |
os.makedirs("data/input", exist_ok=True)
|
| 347 |
with open(file_path, "wb") as buffer:
|
|
|
|
| 372 |
|
| 373 |
return response
|
| 374 |
else:
|
| 375 |
+
error_msg = result.get("error", "Unknown error")
|
| 376 |
+
# Check if error is about missing API key
|
| 377 |
+
if "Missing OpenRouter API key" in error_msg:
|
| 378 |
+
raise HTTPException(
|
| 379 |
+
status_code=400,
|
| 380 |
+
detail="Missing OpenRouter API key. Please provide your API key via the 'user_api_key' form parameter."
|
| 381 |
+
)
|
| 382 |
+
raise HTTPException(status_code=500, detail=error_msg)
|
| 383 |
|
| 384 |
|
| 385 |
@router.post("/cf")
|