| 972 | return content, status_code |
| 973 | |
| 974 | async def abort(self, request_id, n=1) -> None: |
| 975 | if envs.FD_ENABLE_REQUEST_DISCONNECT_STOP_INFERENCE: |
| 976 | api_server_logger.info(f"abort request_id:{request_id}") |
| 977 | if n <= 0: |
| 978 | api_server_logger.warning("Abort function called with non-positive n: %d. No requests aborted.", n) |
| 979 | return |
| 980 | match = re.search(r"_\d+$", request_id) |
| 981 | if match: |
| 982 | prefix = request_id[: match.start()] |
| 983 | else: |
| 984 | api_server_logger.warning( |
| 985 | "request_id format error: %s does not end with _<number>. Using it as prefix.", request_id |
| 986 | ) |
| 987 | prefix = request_id |
| 988 | request_ids = [f"{prefix}_{i}" for i in range(n)] |
| 989 | for req_id in request_ids: |
| 990 | data = { |
| 991 | "request_id": req_id, |
| 992 | "status": RequestStatus.ABORT.value, |
| 993 | } |
| 994 | self._send_task(data) |
| 995 | |
| 996 | api_server_logger.info("Aborted request(s) %s.", ",".join(request_ids)) |
| 997 | |
| 998 | def process_messages(self, messages): |
| 999 | for message in messages: |