diff --git a/services/forecasting/app/main.py b/services/forecasting/app/main.py index f93d2151..56fc1a76 100644 --- a/services/forecasting/app/main.py +++ b/services/forecasting/app/main.py @@ -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(): diff --git a/services/forecasting/app/services/forecasting_service.py b/services/forecasting/app/services/forecasting_service.py index ce6c8075..e765b530 100644 --- a/services/forecasting/app/services/forecasting_service.py +++ b/services/forecasting/app/services/forecasting_service.py @@ -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 diff --git a/services/forecasting/app/services/model_client.py b/services/forecasting/app/services/model_client.py index 08c4d0b7..906a3d12 100644 --- a/services/forecasting/app/services/model_client.py +++ b/services/forecasting/app/services/model_client.py @@ -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: diff --git a/shared/clients/training_client.py b/shared/clients/training_client.py index f098d5b4..5a0d477c 100644 --- a/shared/clients/training_client.py +++ b/shared/clients/training_client.py @@ -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"""