Skip to content

Commit b86417a

Browse files
authored
Merge pull request #1 from saichandrapandraju/main
Fix Endpoint Duplication in FastAPI Swagger by Segregating Routers into Individual Tags
2 parents c535d4c + cd4d6a0 commit b86417a

File tree

15 files changed

+416
-336
lines changed

15 files changed

+416
-336
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/endpoints/drift_metrics.py

Lines changed: 0 additions & 288 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from fastapi import APIRouter, HTTPException
2+
from pydantic import BaseModel
3+
from typing import Optional
4+
import logging
5+
6+
router = APIRouter()
7+
logger = logging.getLogger(__name__)
8+
9+
10+
class ModelConfig(BaseModel):
11+
target: str
12+
name: str
13+
version: Optional[str] = None
14+
15+
16+
class GlobalExplanationRequest(BaseModel):
17+
modelConfig: ModelConfig
18+
19+
20+
@router.post("/explainers/global/lime")
21+
async def global_lime_explanation(request: GlobalExplanationRequest):
22+
"""Compute a global LIME explanation."""
23+
try:
24+
logger.info(
25+
f"Computing global LIME explanation for model: {request.modelConfig.name}"
26+
)
27+
# TODO: Implement
28+
except Exception as e:
29+
logger.error(f"Error computing global LIME explanation: {str(e)}")
30+
raise HTTPException(
31+
status_code=500, detail=f"Error computing explanation: {str(e)}"
32+
)
33+
34+
35+
@router.post("/explainers/global/pdp")
36+
async def global_pdp_explanation(request: GlobalExplanationRequest):
37+
"""Compute a global PDP explanation."""
38+
try:
39+
logger.info(
40+
f"Computing global PDP explanation for model: {request.modelConfig.name}"
41+
)
42+
# TODO: Implement
43+
return {"status": "success", "explanation": {}}
44+
except Exception as e:
45+
logger.error(f"Error computing global PDP explanation: {str(e)}")
46+
raise HTTPException(
47+
status_code=500, detail=f"Error computing explanation: {str(e)}"
48+
)

src/endpoints/explainers.py renamed to src/endpoints/explainers/local_explainer.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,6 @@ class ModelConfig(BaseModel):
1414
version: Optional[str] = None
1515

1616

17-
class GlobalExplanationRequest(BaseModel):
18-
modelConfig: ModelConfig
19-
20-
21-
@router.post("/explainers/global/lime")
22-
async def global_lime_explanation(request: GlobalExplanationRequest):
23-
"""Compute a global LIME explanation."""
24-
try:
25-
logger.info(
26-
f"Computing global LIME explanation for model: {request.modelConfig.name}"
27-
)
28-
# TODO: Implement
29-
except Exception as e:
30-
logger.error(f"Error computing global LIME explanation: {str(e)}")
31-
raise HTTPException(
32-
status_code=500, detail=f"Error computing explanation: {str(e)}"
33-
)
34-
35-
36-
@router.post("/explainers/global/pdp")
37-
async def global_pdp_explanation(request: GlobalExplanationRequest):
38-
"""Compute a global PDP explanation."""
39-
try:
40-
logger.info(
41-
f"Computing global PDP explanation for model: {request.modelConfig.name}"
42-
)
43-
# TODO: Implement
44-
return {"status": "success", "explanation": {}}
45-
except Exception as e:
46-
logger.error(f"Error computing global PDP explanation: {str(e)}")
47-
raise HTTPException(
48-
status_code=500, detail=f"Error computing explanation: {str(e)}"
49-
)
50-
51-
5217
class LimeExplainerConfig(BaseModel):
5318
n_samples: int = 300
5419
timeout: int = 10

0 commit comments

Comments
 (0)