Start fixing forecast service API 8
This commit is contained in:
@@ -89,8 +89,8 @@ app.add_middleware(
|
||||
)
|
||||
|
||||
# Include API routers
|
||||
app.include_router(forecasts.router, prefix="/api/v1/forecasts", tags=["forecasts"])
|
||||
app.include_router(predictions.router, prefix="/api/v1/predictions", tags=["predictions"])
|
||||
app.include_router(forecasts.router, prefix="/api/v1", tags=["forecasts"])
|
||||
app.include_router(predictions.router, prefix="/api/v1", tags=["predictions"])
|
||||
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
|
||||
@@ -129,7 +129,7 @@ class ForecastingService:
|
||||
except Exception as e:
|
||||
logger.error("Error generating forecast",
|
||||
error=str(e),
|
||||
tenant_id=request.tenant_id,
|
||||
tenant_id=tenant_id,
|
||||
product=request.product_name)
|
||||
raise
|
||||
|
||||
@@ -247,11 +247,13 @@ class ForecastingService:
|
||||
|
||||
async def _get_latest_model(self, tenant_id: str, product_name: str) -> Optional[Dict[str, Any]]:
|
||||
"""Get the latest trained model for a tenant/product combination"""
|
||||
|
||||
try:
|
||||
model_data = await self.model_client.get_best_model_for_forecasting(tenant_id, product_name)
|
||||
# Pass the product_name to the model client
|
||||
model_data = await self.model_client.get_best_model_for_forecasting(
|
||||
tenant_id=tenant_id,
|
||||
product_name=product_name # Make sure to pass product_name
|
||||
)
|
||||
return model_data
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Error getting latest model", error=str(e))
|
||||
raise
|
||||
|
||||
@@ -64,9 +64,10 @@ class ModelClient:
|
||||
"""
|
||||
try:
|
||||
# Get latest model
|
||||
latest_model = await self.clients.training.get_latest_model(
|
||||
latest_model = await self.clients.training.get_active_model_for_product(
|
||||
tenant_id=tenant_id,
|
||||
model_type="forecasting"
|
||||
model_type="forecasting",
|
||||
product_name=product_id
|
||||
)
|
||||
|
||||
if not latest_model:
|
||||
|
||||
@@ -86,19 +86,17 @@ class TrainingServiceClient(BaseServiceClient):
|
||||
result = await self.get("models", tenant_id=tenant_id, params=params)
|
||||
return result.get("models", []) if result else None
|
||||
|
||||
async def get_latest_model(
|
||||
async def get_active_model_for_product(
|
||||
self,
|
||||
tenant_id: str,
|
||||
model_type: Optional[str] = None
|
||||
product_name: str
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
"""Get the latest trained model for a tenant"""
|
||||
params = {"latest": "true"}
|
||||
if model_type:
|
||||
params["model_type"] = model_type
|
||||
|
||||
result = await self.get("models", tenant_id=tenant_id, params=params)
|
||||
models = result.get("models", []) if result else []
|
||||
return models[0] if models else None
|
||||
"""
|
||||
Get the active model for a specific product
|
||||
This is the preferred method since models are stored per product.
|
||||
"""
|
||||
result = await self.get(f"models/{product_name}/active", tenant_id=tenant_id)
|
||||
return result
|
||||
|
||||
async def deploy_model(self, tenant_id: str, model_id: str) -> Optional[Dict[str, Any]]:
|
||||
"""Deploy a trained model"""
|
||||
|
||||
Reference in New Issue
Block a user