Improve AI logic
This commit is contained in:
@@ -17,8 +17,8 @@ logger = structlog.get_logger()
|
||||
class InventoryServiceClient(BaseServiceClient):
|
||||
"""Client for communicating with the inventory service via gateway"""
|
||||
|
||||
def __init__(self, config: BaseServiceSettings):
|
||||
super().__init__("inventory", config)
|
||||
def __init__(self, config: BaseServiceSettings, calling_service_name: str = "unknown"):
|
||||
super().__init__(calling_service_name, config)
|
||||
|
||||
def get_service_base_path(self) -> str:
|
||||
"""Return the base path for inventory service APIs"""
|
||||
@@ -610,6 +610,47 @@ class InventoryServiceClient(BaseServiceClient):
|
||||
)
|
||||
return {}
|
||||
|
||||
# ================================================================
|
||||
# ML INSIGHTS: Safety Stock Optimization
|
||||
# ================================================================
|
||||
|
||||
async def trigger_safety_stock_optimization(
|
||||
self,
|
||||
tenant_id: str,
|
||||
product_ids: Optional[List[str]] = None,
|
||||
lookback_days: int = 90,
|
||||
min_history_days: int = 30
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Trigger safety stock optimization for inventory products.
|
||||
|
||||
Args:
|
||||
tenant_id: Tenant UUID
|
||||
product_ids: Specific product IDs to optimize. If None, optimizes all products
|
||||
lookback_days: Days of historical demand to analyze (30-365)
|
||||
min_history_days: Minimum days of history required (7-180)
|
||||
|
||||
Returns:
|
||||
Dict with optimization results including insights posted
|
||||
"""
|
||||
try:
|
||||
data = {
|
||||
"product_ids": product_ids,
|
||||
"lookback_days": lookback_days,
|
||||
"min_history_days": min_history_days
|
||||
}
|
||||
result = await self.post("inventory/ml/insights/optimize-safety-stock", data=data, tenant_id=tenant_id)
|
||||
if result:
|
||||
logger.info("Triggered safety stock optimization",
|
||||
products_optimized=result.get('products_optimized', 0),
|
||||
insights_posted=result.get('total_insights_posted', 0),
|
||||
tenant_id=tenant_id)
|
||||
return result
|
||||
except Exception as e:
|
||||
logger.error("Error triggering safety stock optimization",
|
||||
error=str(e), tenant_id=tenant_id)
|
||||
return None
|
||||
|
||||
# ================================================================
|
||||
# UTILITY METHODS
|
||||
# ================================================================
|
||||
|
||||
Reference in New Issue
Block a user