| import sys | |
| def generate_recommendation( | |
| risk_score, | |
| region, | |
| recent_incidents=None, | |
| weather_alert=None, | |
| intent=None, | |
| origin=None, | |
| destination=None | |
| ): | |
| if origin and destination: | |
| region_str = f"{origin} to {destination}" | |
| else: | |
| region_str = region | |
| if risk_score >= 0.8: | |
| level = "High risk" | |
| message = ( | |
| f"{level} detected for {region_str}! Recent incidents or delays increase disruption probability. " | |
| "Immediate mitigation advised—consider rerouting, switching suppliers, or delaying shipment." | |
| ) | |
| action = "reroute/switch_supplier/delay" | |
| elif risk_score >= 0.6: | |
| level = "Elevated risk" | |
| message = ( | |
| f"{level} in {region_str}. Monitor closely and prioritize more reliable suppliers and routes." | |
| ) | |
| action = "monitor_prioritize" | |
| elif risk_score >= 0.3: | |
| level = "Moderate risk" | |
| message = ( | |
| f"{level} for {region_str}. Standard operations are feasible, but stay alert for escalating risks." | |
| ) | |
| action = "continue_monitor" | |
| else: | |
| level = "Low risk" | |
| message = f"{level} for {region_str}. Proceed with routine operations." | |
| action = "proceed" | |
| if weather_alert: | |
| message += f"\nWeather Alert: {weather_alert}" | |
| if recent_incidents: | |
| message += f"\nRecent incidents: {', '.join(recent_incidents[:3])}" | |
| if recent_incidents and risk_score >= 0.8: | |
| message += "\nSupply chain disruption likely due to recent incidents. Take immediate action to mitigate risk." | |
| if intent == "mitigation_help" and risk_score >= 0.5: | |
| message += "\nWould you like to view alternate routes or suppliers for mitigation?" | |
| return { | |
| "message": message, | |
| "action": action, | |
| "risk_score": risk_score, | |
| "region": region_str | |
| } | |
| if __name__ == "__main__": | |
| main() | |