Spaces:
Sleeping
Sleeping
modelfit_chat returns ok
Browse files
main.py
CHANGED
|
@@ -188,7 +188,7 @@ async def _fetch_url_to_dataframe(data_url: str) -> pd.DataFrame:
|
|
| 188 |
return df
|
| 189 |
|
| 190 |
|
| 191 |
-
async def _forward(path: str, method: str = "GET", json_body=None, user_token: str | None = None):
|
| 192 |
"""
|
| 193 |
Forward request to the PRIVATE Space:
|
| 194 |
- 'Authorization: Bearer <HF_TOKEN>' to pass HF private gate
|
|
@@ -269,6 +269,10 @@ async def _forward(path: str, method: str = "GET", json_body=None, user_token: s
|
|
| 269 |
if r is None:
|
| 270 |
raise RuntimeError("Upstream request did not complete")
|
| 271 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
ct = r.headers.get("content-type", "")
|
| 273 |
|
| 274 |
if "application/json" in ct:
|
|
@@ -586,7 +590,8 @@ async def modelfit_chat(
|
|
| 586 |
"""
|
| 587 |
Fetch training data from data_url (HTTPS), infer schema from column order, then call /modelfit/ on the API.
|
| 588 |
Column order: 1st = id_col, 2nd = time_col, 3rd..second-to-last = current_features, last = y.
|
| 589 |
-
All other parameters use defaults.
|
|
|
|
| 590 |
"""
|
| 591 |
user_token = _extract_user_token(req)
|
| 592 |
if not user_token:
|
|
@@ -614,7 +619,13 @@ async def modelfit_chat(
|
|
| 614 |
"meanvar_test": False,
|
| 615 |
"signif": 0.05,
|
| 616 |
}
|
| 617 |
-
return await _forward(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 618 |
|
| 619 |
|
| 620 |
@app.post("/modelforecast_chat/")
|
|
|
|
| 188 |
return df
|
| 189 |
|
| 190 |
|
| 191 |
+
async def _forward(path: str, method: str = "GET", json_body=None, user_token: str | None = None, success_response_override: dict | None = None):
|
| 192 |
"""
|
| 193 |
Forward request to the PRIVATE Space:
|
| 194 |
- 'Authorization: Bearer <HF_TOKEN>' to pass HF private gate
|
|
|
|
| 269 |
if r is None:
|
| 270 |
raise RuntimeError("Upstream request did not complete")
|
| 271 |
|
| 272 |
+
# When caller wants a minimal response on success (e.g. for chat to avoid response size limits)
|
| 273 |
+
if success_response_override is not None and r.status_code == 200:
|
| 274 |
+
return JSONResponse(status_code=200, content=success_response_override)
|
| 275 |
+
|
| 276 |
ct = r.headers.get("content-type", "")
|
| 277 |
|
| 278 |
if "application/json" in ct:
|
|
|
|
| 590 |
"""
|
| 591 |
Fetch training data from data_url (HTTPS), infer schema from column order, then call /modelfit/ on the API.
|
| 592 |
Column order: 1st = id_col, 2nd = time_col, 3rd..second-to-last = current_features, last = y.
|
| 593 |
+
All other parameters use defaults. On success returns a minimal JSON (ok, message) to stay under
|
| 594 |
+
chat platform response size limits; errors are returned in full.
|
| 595 |
"""
|
| 596 |
user_token = _extract_user_token(req)
|
| 597 |
if not user_token:
|
|
|
|
| 619 |
"meanvar_test": False,
|
| 620 |
"signif": 0.05,
|
| 621 |
}
|
| 622 |
+
return await _forward(
|
| 623 |
+
"/modelfit/",
|
| 624 |
+
"POST",
|
| 625 |
+
json_body=payload,
|
| 626 |
+
user_token=user_token,
|
| 627 |
+
success_response_override={"ok": True, "message": "Model fitted. Call modelforecast_chat with your forecast data URL next."},
|
| 628 |
+
)
|
| 629 |
|
| 630 |
|
| 631 |
@app.post("/modelforecast_chat/")
|