polish code with new pre-commit rule (#2923)

This commit is contained in:
Zero Rains
2025-07-19 23:19:27 +08:00
committed by GitHub
parent b8676d71a8
commit 25698d56d1
424 changed files with 14307 additions and 13518 deletions

View File

@@ -14,29 +14,32 @@
# limitations under the License.
"""
from datetime import datetime
import time
import json
import time
from datetime import datetime
from fastdeploy.engine.request import Request, RequestOutput
class ScheduledRequest(object):
class ScheduledRequest:
"""
A wrapper class for Request objects with scheduling metadata.
This class extends Request objects with:
- Queue information for distributed scheduling
- Timestamp tracking
- Serialization capabilities
"""
def __init__(self,
request: Request,
request_queue_name: str = "",
response_queue_name: str = ""):
def __init__(
self,
request: Request,
request_queue_name: str = "",
response_queue_name: str = "",
):
"""
Initialize a ScheduledRequest instance.
Args:
request: The original Request object
request_queue_name: Name of the request queue
@@ -49,17 +52,18 @@ class ScheduledRequest(object):
def __repr__(self) -> str:
local_time = datetime.fromtimestamp(self.schedule_time)
formatted_time = local_time.strftime(
"%Y-%m-%d %H:%M:%S") + f"{local_time.microsecond // 1000:03d}"
return (f"request_id:{self.request_id} request_queue:{self.request_queue_name} "
f"response_queue:{self.response_queue_name} "
f"schedule_time:{formatted_time}")
formatted_time = local_time.strftime("%Y-%m-%d %H:%M:%S") + f"{local_time.microsecond // 1000:03d}"
return (
f"request_id:{self.request_id} request_queue:{self.request_queue_name} "
f"response_queue:{self.response_queue_name} "
f"schedule_time:{formatted_time}"
)
@property
def request_id(self) -> str:
"""
Get the request ID.
Returns:
The unique request identifier
"""
@@ -69,7 +73,7 @@ class ScheduledRequest(object):
def request_id(self, id: str):
"""
Set the request ID.
Args:
id: New request identifier
"""
@@ -79,7 +83,7 @@ class ScheduledRequest(object):
def prompt_tokens_ids_len(self) -> int:
"""
Get the length of prompt token IDs.
Returns:
Number of tokens in the prompt
"""
@@ -88,7 +92,7 @@ class ScheduledRequest(object):
def serialize(self) -> bytes:
"""
Serialize the request to bytes for storage/transmission.
Returns:
Serialized request data as bytes
"""
@@ -102,13 +106,13 @@ class ScheduledRequest(object):
return serialized_data.encode()
@classmethod
def unserialize(cls, serialized_data: bytes) -> 'ScheduledRequest':
def unserialize(cls, serialized_data: bytes) -> "ScheduledRequest":
"""
Deserialize bytes back into a ScheduledRequest.
Args:
serialized_data: Serialized request data
Returns:
Reconstructed ScheduledRequest object
"""
@@ -121,10 +125,10 @@ class ScheduledRequest(object):
return scheduled_request
class ScheduledResponse(object):
class ScheduledResponse:
"""
A wrapper class for RequestOutput objects with scheduling metadata.
This class extends RequestOutput objects with:
- Timestamp tracking
- Serialization capabilities
@@ -134,7 +138,7 @@ class ScheduledResponse(object):
def __init__(self, response: RequestOutput):
"""
Initialize a ScheduledResponse instance.
Args:
response: The original RequestOutput object
"""
@@ -148,7 +152,7 @@ class ScheduledResponse(object):
def request_id(self) -> str:
"""
Get the request ID.
Returns:
The unique request identifier
"""
@@ -158,7 +162,7 @@ class ScheduledResponse(object):
def request_id(self, id: str):
"""
Set the request ID.
Args:
id: New request identifier
"""
@@ -168,7 +172,7 @@ class ScheduledResponse(object):
def index(self) -> int:
"""
Get the output index.
Returns:
Position index of this response in the sequence
"""
@@ -178,7 +182,7 @@ class ScheduledResponse(object):
def finished(self) -> bool:
"""
Check if the request is complete.
Returns:
True if this is the final response for the request
"""
@@ -187,7 +191,7 @@ class ScheduledResponse(object):
def serialize(self) -> bytes:
"""
Serialize the response to bytes for storage/transmission.
Returns:
Serialized response data as bytes
"""
@@ -199,13 +203,13 @@ class ScheduledResponse(object):
return serialized_data.encode()
@classmethod
def unserialize(cls, serialized_data: bytes) -> 'ScheduledResponse':
def unserialize(cls, serialized_data: bytes) -> "ScheduledResponse":
"""
Deserialize bytes back into a ScheduledResponse.
Args:
serialized_data: Serialized response data
Returns:
Reconstructed ScheduledResponse object
"""