From ad2b53079b78deba2f0aa833382085e85646e496 Mon Sep 17 00:00:00 2001 From: Mesh Date: Mon, 14 Jul 2025 05:37:01 -0500 Subject: [PATCH 1/7] fixed endpoint issues --- src/webapp/routers/data.py | 42 ++++++++++++-------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/src/webapp/routers/data.py b/src/webapp/routers/data.py index 2f230587..c42123eb 100644 --- a/src/webapp/routers/data.py +++ b/src/webapp/routers/data.py @@ -14,6 +14,7 @@ import logging from sqlalchemy.exc import IntegrityError from ..config import databricks_vars, env_vars, gcs_vars +from mlflow.exceptions import MlflowException import tempfile import pathlib @@ -1372,34 +1373,17 @@ def get_model_cards( f"get_model_cards(): Workspace client initialization failed: {e}" ) - host = w.config.host # e.g. "https://12345.gcp.databricks.com" - - # 2. Build the MLflow REST endpoint URL and params - download_endpoint = f"{host}/api/2.0/mlflow/artifacts/download" - artifact_path = f"model_card/model-card-{model_name}.pdf" - params = {"run_id": run_id, "path": artifact_path} - - # 3. Let WorkspaceClient’s ApiClient perform the authenticated GET try: - # perform_query will attach the same OAuth creds that WorkspaceClient uses - resp = w.api_client.perform_query( # type: ignore[attr-defined] - method="GET", - path=download_endpoint, - query_params=params, - ) # type: ignore[attr-defined] - # resp here is the raw bytes of the PDF + volume_path = f"/Volumes/staging_sst_01/{query_result[0][0].name}_gold/gold_volume/model-card-{model_name}.pdf" + with w.files.download(volume_path) as stream: + pdf_bytes = stream.read() except Exception as e: - raise HTTPException( - status_code=500, - detail=f"Could not download model card via MLflow REST API: {e}", - ) - - # 4. Write to a temp file and return it - with tempfile.TemporaryDirectory() as td: - out_path = pathlib.Path(td) / f"model-card-{model_name}.pdf" - out_path.write_bytes(resp) - return FileResponse( - path=str(out_path), - filename=out_path.name, - media_type="application/pdf", - ) + raise HTTPException(500, detail=f"Failed to fetch model card: {e}") + + # Stream back as FileResponse + tmp = tempfile.NamedTemporaryFile(suffix=".pdf", delete=False) + tmp.write(pdf_bytes) + tmp.flush() + return FileResponse( + tmp.name, filename=tmp.name.split("/")[-1], media_type="application/pdf" + ) From a54b01b0a84e24a87bf91801c8f27276a3b12240 Mon Sep 17 00:00:00 2001 From: Mesh Date: Mon, 14 Jul 2025 05:41:36 -0500 Subject: [PATCH 2/7] fixed endpoint issues --- src/webapp/routers/data.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/webapp/routers/data.py b/src/webapp/routers/data.py index c42123eb..6afcd047 100644 --- a/src/webapp/routers/data.py +++ b/src/webapp/routers/data.py @@ -1375,8 +1375,9 @@ def get_model_cards( try: volume_path = f"/Volumes/staging_sst_01/{query_result[0][0].name}_gold/gold_volume/model-card-{model_name}.pdf" - with w.files.download(volume_path) as stream: - pdf_bytes = stream.read() + response = w.files.download(volume_path) + pdf_bytes = response.read() + except Exception as e: raise HTTPException(500, detail=f"Failed to fetch model card: {e}") From fea2f9baaace1daf4028cc353818b7316b80d1ad Mon Sep 17 00:00:00 2001 From: Mesh Date: Mon, 14 Jul 2025 05:42:26 -0500 Subject: [PATCH 3/7] fixed endpoint issues --- src/webapp/routers/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webapp/routers/data.py b/src/webapp/routers/data.py index 6afcd047..4828e220 100644 --- a/src/webapp/routers/data.py +++ b/src/webapp/routers/data.py @@ -1377,7 +1377,7 @@ def get_model_cards( volume_path = f"/Volumes/staging_sst_01/{query_result[0][0].name}_gold/gold_volume/model-card-{model_name}.pdf" response = w.files.download(volume_path) pdf_bytes = response.read() - + except Exception as e: raise HTTPException(500, detail=f"Failed to fetch model card: {e}") From 366e1e9c2413a9285d3a10195f89d22917024d35 Mon Sep 17 00:00:00 2001 From: Mesh Date: Mon, 14 Jul 2025 05:48:23 -0500 Subject: [PATCH 4/7] fixed endpoint issues --- src/webapp/routers/data.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/webapp/routers/data.py b/src/webapp/routers/data.py index 4828e220..40996adc 100644 --- a/src/webapp/routers/data.py +++ b/src/webapp/routers/data.py @@ -14,7 +14,6 @@ import logging from sqlalchemy.exc import IntegrityError from ..config import databricks_vars, env_vars, gcs_vars -from mlflow.exceptions import MlflowException import tempfile import pathlib @@ -1376,7 +1375,7 @@ def get_model_cards( try: volume_path = f"/Volumes/staging_sst_01/{query_result[0][0].name}_gold/gold_volume/model-card-{model_name}.pdf" response = w.files.download(volume_path) - pdf_bytes = response.read() + pdf_bytes = response.contents.read() # pylint: disable=no-member except Exception as e: raise HTTPException(500, detail=f"Failed to fetch model card: {e}") @@ -1385,6 +1384,9 @@ def get_model_cards( tmp = tempfile.NamedTemporaryFile(suffix=".pdf", delete=False) tmp.write(pdf_bytes) tmp.flush() + return FileResponse( - tmp.name, filename=tmp.name.split("/")[-1], media_type="application/pdf" - ) + tmp.name, + filename=pathlib.Path(tmp.name).name, + media_type="application/pdf", + ) \ No newline at end of file From 1f0d7f5c7e8ca41bc3a7cc20a45facd4baf1d079 Mon Sep 17 00:00:00 2001 From: Mesh Date: Mon, 14 Jul 2025 05:49:46 -0500 Subject: [PATCH 5/7] fixed endpoint issues --- src/webapp/routers/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webapp/routers/data.py b/src/webapp/routers/data.py index 40996adc..8418c167 100644 --- a/src/webapp/routers/data.py +++ b/src/webapp/routers/data.py @@ -1389,4 +1389,4 @@ def get_model_cards( tmp.name, filename=pathlib.Path(tmp.name).name, media_type="application/pdf", - ) \ No newline at end of file + ) From 8ca9142d3f3f37ac32f4df312f26cc63c9d1fc02 Mon Sep 17 00:00:00 2001 From: Mesh Date: Mon, 14 Jul 2025 06:00:55 -0500 Subject: [PATCH 6/7] fixed endpoint issues --- src/webapp/routers/data.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/webapp/routers/data.py b/src/webapp/routers/data.py index 8418c167..aa5b8009 100644 --- a/src/webapp/routers/data.py +++ b/src/webapp/routers/data.py @@ -3,7 +3,7 @@ import uuid from datetime import datetime, date from databricks.sdk import WorkspaceClient -from typing import Annotated, Any, Dict, List +from typing import Annotated, Any, Dict, List, cast, IO from pydantic import BaseModel from fastapi import APIRouter, Depends, HTTPException, status, Response from fastapi.responses import FileResponse @@ -1375,7 +1375,8 @@ def get_model_cards( try: volume_path = f"/Volumes/staging_sst_01/{query_result[0][0].name}_gold/gold_volume/model-card-{model_name}.pdf" response = w.files.download(volume_path) - pdf_bytes = response.contents.read() # pylint: disable=no-member + stream = cast(IO[bytes], response.contents) + pdf_bytes = stream.read() except Exception as e: raise HTTPException(500, detail=f"Failed to fetch model card: {e}") @@ -1389,4 +1390,4 @@ def get_model_cards( tmp.name, filename=pathlib.Path(tmp.name).name, media_type="application/pdf", - ) + ) \ No newline at end of file From 571d379c2d5da919bdd57b58b4416a9275b1c447 Mon Sep 17 00:00:00 2001 From: Mesh Date: Mon, 14 Jul 2025 06:02:51 -0500 Subject: [PATCH 7/7] fixed endpoint issues --- src/webapp/routers/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webapp/routers/data.py b/src/webapp/routers/data.py index aa5b8009..42e51ee3 100644 --- a/src/webapp/routers/data.py +++ b/src/webapp/routers/data.py @@ -1390,4 +1390,4 @@ def get_model_cards( tmp.name, filename=pathlib.Path(tmp.name).name, media_type="application/pdf", - ) \ No newline at end of file + )