Improve AI logic

This commit is contained in:
Urtzi Alfaro
2025-11-05 13:34:56 +01:00
parent 5c87fbcf48
commit 394ad3aea4
218 changed files with 30627 additions and 7658 deletions

View File

@@ -16,8 +16,8 @@ logger = structlog.get_logger()
class ProductionServiceClient(BaseServiceClient):
"""Client for communicating with the Production Service"""
def __init__(self, config: BaseServiceSettings):
super().__init__("production", 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 "/api/v1"
@@ -63,7 +63,7 @@ class ProductionServiceClient(BaseServiceClient):
request_data["recipes_data"] = recipes_data
result = await self.post(
"production/generate-schedule",
"production/operations/generate-schedule",
data=request_data,
tenant_id=tenant_id
)
@@ -404,6 +404,47 @@ class ProductionServiceClient(BaseServiceClient):
error=str(e), tenant_id=tenant_id)
return None
# ================================================================
# ML INSIGHTS: Yield Prediction
# ================================================================
async def trigger_yield_prediction(
self,
tenant_id: str,
recipe_ids: Optional[List[str]] = None,
lookback_days: int = 90,
min_history_runs: int = 30
) -> Optional[Dict[str, Any]]:
"""
Trigger yield prediction for production recipes.
Args:
tenant_id: Tenant UUID
recipe_ids: Specific recipe IDs to analyze. If None, analyzes all recipes
lookback_days: Days of historical production to analyze (30-365)
min_history_runs: Minimum production runs required (10-100)
Returns:
Dict with prediction results including insights posted
"""
try:
data = {
"recipe_ids": recipe_ids,
"lookback_days": lookback_days,
"min_history_runs": min_history_runs
}
result = await self.post("production/ml/insights/predict-yields", data=data, tenant_id=tenant_id)
if result:
logger.info("Triggered yield prediction",
recipes_analyzed=result.get('recipes_analyzed', 0),
insights_posted=result.get('total_insights_posted', 0),
tenant_id=tenant_id)
return result
except Exception as e:
logger.error("Error triggering yield prediction",
error=str(e), tenant_id=tenant_id)
return None
# ================================================================
# UTILITY METHODS
# ================================================================