A generic control request that supports method and args for control operations. This request type is used for system-level control operations rather than typical inference requests. It enables dynamic control of engine behavior, resource management, and system configuration via a flexib
| 548 | |
| 549 | |
| 550 | class ControlRequest: |
| 551 | """A generic control request that supports method and args for control operations. |
| 552 | |
| 553 | This request type is used for system-level control operations rather than |
| 554 | typical inference requests. It enables dynamic control of engine behavior, |
| 555 | resource management, and system configuration via a flexible method-args interface. |
| 556 | """ |
| 557 | |
| 558 | def __init__( |
| 559 | self, |
| 560 | request_id: str, |
| 561 | method: str, |
| 562 | args: Optional[Dict[str, Any]] = None, |
| 563 | ) -> None: |
| 564 | """ |
| 565 | Args: |
| 566 | request_id: Unique identifier for the control request. |
| 567 | method: The control method to execute (e.g., "reset_scheduler", "get_metrics"). |
| 568 | args: Optional arguments for the control method. |
| 569 | """ |
| 570 | self.request_id = request_id |
| 571 | self.method = method |
| 572 | self.args = args or {} |
| 573 | |
| 574 | @classmethod |
| 575 | def from_dict(cls, d: dict): |
| 576 | """Create ControlRequest instance from dictionary.""" |
| 577 | return cls(request_id=d["request_id"], method=d["method"], args=d.get("args", {})) |
| 578 | |
| 579 | def to_dict(self) -> dict: |
| 580 | """Convert ControlRequest into a serializable dict.""" |
| 581 | return {"request_id": self.request_id, "method": self.method, "args": self.args} |
| 582 | |
| 583 | def __repr__(self) -> str: |
| 584 | """Provide a clean representation of the control request.""" |
| 585 | try: |
| 586 | if not envs.FD_DEBUG: |
| 587 | return f"ControlRequest(request_id={self.request_id}, method={self.method})" |
| 588 | else: |
| 589 | return ( |
| 590 | f"ControlRequest(" |
| 591 | f"request_id={self.request_id}, " |
| 592 | f"method={self.method}, " |
| 593 | f"args={self.args}" |
| 594 | f")" |
| 595 | ) |
| 596 | except Exception as e: |
| 597 | return f"<ControlRequest repr failed: {e}>" |
| 598 | |
| 599 | def get_method(self) -> str: |
| 600 | """Get the control method name.""" |
| 601 | return self.method |
| 602 | |
| 603 | def get_args(self) -> Dict[str, Any]: |
| 604 | """Get the control method arguments.""" |
| 605 | return self.args.copy() |
| 606 | |
| 607 | @staticmethod |
no outgoing calls