refactor(http): improve pd_types.rs documentation and style (#16319)
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
// Custom error type for PD router operations
|
//! Types and utilities for the prefill-decode (PD) disaggregated router.
|
||||||
|
|
||||||
|
/// Custom error type for PD router operations
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum PDRouterError {
|
pub enum PDRouterError {
|
||||||
#[error("Worker already exists: {url}")]
|
#[error("Worker already exists: {url}")]
|
||||||
@@ -23,9 +25,9 @@ pub enum PDRouterError {
|
|||||||
Timeout { url: String },
|
Timeout { url: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions for workers
|
/// Construct a full API URL from a base URL and path.
|
||||||
pub fn api_path(url: &str, api_path: &str) -> String {
|
pub fn api_path(url: &str, api_path: &str) -> String {
|
||||||
if api_path.starts_with("/") {
|
if api_path.starts_with('/') {
|
||||||
format!("{}{}", url, api_path)
|
format!("{}{}", url, api_path)
|
||||||
} else {
|
} else {
|
||||||
format!("{}/{}", url, api_path)
|
format!("{}/{}", url, api_path)
|
||||||
@@ -34,7 +36,7 @@ pub fn api_path(url: &str, api_path: &str) -> String {
|
|||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
// Optimized bootstrap wrapper for single requests
|
/// Optimized bootstrap wrapper for single requests.
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct RequestWithBootstrap<'a, T: Serialize> {
|
pub struct RequestWithBootstrap<'a, T: Serialize> {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
@@ -44,7 +46,7 @@ pub struct RequestWithBootstrap<'a, T: Serialize> {
|
|||||||
pub bootstrap_room: u64,
|
pub bootstrap_room: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optimized bootstrap wrapper for batch requests
|
/// Optimized bootstrap wrapper for batch requests.
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct BatchRequestWithBootstrap<'a, T: Serialize> {
|
pub struct BatchRequestWithBootstrap<'a, T: Serialize> {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
@@ -54,13 +56,13 @@ pub struct BatchRequestWithBootstrap<'a, T: Serialize> {
|
|||||||
pub bootstrap_room: Vec<u64>,
|
pub bootstrap_room: Vec<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to generate bootstrap room ID
|
/// Generate a random bootstrap room ID.
|
||||||
pub fn generate_room_id() -> u64 {
|
pub fn generate_room_id() -> u64 {
|
||||||
// Generate a value in the range [0, 2^63 - 1] to match Python's random.randint(0, 2**63 - 1)
|
// Generate a value in the range [0, 2^63 - 1] to match Python's random.randint(0, 2**63 - 1)
|
||||||
rand::random::<u64>() & (i64::MAX as u64)
|
rand::random::<u64>() & (i64::MAX as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PD-specific routing policies
|
/// PD-specific routing policies.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum PDSelectionPolicy {
|
pub enum PDSelectionPolicy {
|
||||||
Random,
|
Random,
|
||||||
|
|||||||
Reference in New Issue
Block a user