Skip to content

Commit 1655cc3

Browse files
committed
fix fmt
1 parent 63f4a5a commit 1655cc3

File tree

13 files changed

+73
-76
lines changed

13 files changed

+73
-76
lines changed

sgl-router/src/routers/openai/context.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use dashmap::DashMap;
1010
use reqwest::StatusCode;
1111
use serde_json::Value;
1212

13+
use super::mcp::ToolLoopState;
1314
use crate::{
1415
core::CircuitBreaker,
1516
data_connector::{ConversationItemStorage, ConversationStorage, ResponseStorage},
@@ -20,8 +21,6 @@ use crate::{
2021
},
2122
};
2223

23-
use super::mcp::ToolLoopState;
24-
2524
// ============================================================================
2625
// Main Request Context
2726
// ============================================================================
@@ -253,9 +252,7 @@ impl RequestContext {
253252
pub fn model(&self) -> &str {
254253
match &self.input.request_type {
255254
RequestType::Chat(req) => &req.model,
256-
RequestType::Responses(req) => {
257-
self.input.model_id.as_deref().unwrap_or(&req.model)
258-
}
255+
RequestType::Responses(req) => self.input.model_id.as_deref().unwrap_or(&req.model),
259256
}
260257
}
261258
}

sgl-router/src/routers/openai/pipeline.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,9 @@ impl RequestPipeline {
103103

104104
// Return final response
105105
match ctx.state.final_response {
106-
Some(final_resp) => {
107-
(StatusCode::OK, Json(final_resp.json_response)).into_response()
108-
}
106+
Some(final_resp) => (StatusCode::OK, Json(final_resp.json_response)).into_response(),
109107
None => {
110-
error!(
111-
function = "execute",
112-
"No response produced by pipeline"
113-
);
108+
error!(function = "execute", "No response produced by pipeline");
114109
(
115110
StatusCode::INTERNAL_SERVER_ERROR,
116111
Json(serde_json::json!({

sgl-router/src/routers/openai/router.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ use super::{
2929
};
3030
use crate::{
3131
core::{CircuitBreaker, CircuitBreakerConfig as CoreCircuitBreakerConfig},
32-
data_connector::{
33-
ConversationItemStorage, ConversationStorage, ResponseId, ResponseStorage,
34-
},
32+
data_connector::{ConversationItemStorage, ConversationStorage, ResponseId, ResponseStorage},
3533
mcp::McpManager,
3634
protocols::{
3735
chat::ChatCompletionRequest,

sgl-router/src/routers/openai/stages/context_loading.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
//! - Builds conversation context for the request
77
88
use async_trait::async_trait;
9-
use axum::{http::StatusCode, response::{IntoResponse, Response}, Json};
9+
use axum::{
10+
http::StatusCode,
11+
response::{IntoResponse, Response},
12+
Json,
13+
};
1014
use serde_json::json;
1115
use tracing::warn;
1216

@@ -150,10 +154,7 @@ impl PipelineStage for ContextLoadingStage {
150154
});
151155
}
152156
Err(e) => {
153-
warn!(
154-
"Failed to deserialize message content: {}",
155-
e
156-
);
157+
warn!("Failed to deserialize message content: {}", e);
157158
}
158159
}
159160
}
@@ -164,10 +165,7 @@ impl PipelineStage for ContextLoadingStage {
164165
) {
165166
Ok(func_call) => conversation_items.push(func_call),
166167
Err(e) => {
167-
warn!(
168-
"Failed to deserialize function_call: {}",
169-
e
170-
);
168+
warn!("Failed to deserialize function_call: {}", e);
171169
}
172170
}
173171
}
@@ -180,10 +178,7 @@ impl PipelineStage for ContextLoadingStage {
180178
conversation_items.push(func_output);
181179
}
182180
Err(e) => {
183-
warn!(
184-
"Failed to deserialize function_call_output: {}",
185-
e
186-
);
181+
warn!("Failed to deserialize function_call_output: {}", e);
187182
}
188183
}
189184
}

sgl-router/src/routers/openai/stages/discovery.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
use std::time::{Duration, Instant};
99

1010
use async_trait::async_trait;
11-
use axum::{http::StatusCode, response::{IntoResponse, Response}};
11+
use axum::{
12+
http::StatusCode,
13+
response::{IntoResponse, Response},
14+
};
1215

1316
use super::PipelineStage;
1417
use crate::routers::openai::{
@@ -243,7 +246,10 @@ mod tests {
243246

244247
#[tokio::test]
245248
async fn test_discovery_stage_cache_hit() {
246-
let worker_urls = vec!["http://localhost:8000".to_string(), "http://localhost:8001".to_string()];
249+
let worker_urls = vec![
250+
"http://localhost:8000".to_string(),
251+
"http://localhost:8001".to_string(),
252+
];
247253
let components = create_test_components(worker_urls.clone()).await;
248254

249255
// Pre-populate cache

sgl-router/src/routers/openai/stages/execution.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
use async_trait::async_trait;
1111
use axum::{
1212
body::Body,
13-
http::{
14-
header::CONTENT_TYPE,
15-
HeaderValue, StatusCode,
16-
},
13+
http::{header::CONTENT_TYPE, HeaderValue, StatusCode},
1714
response::{IntoResponse, Response},
1815
};
1916
use futures::StreamExt;
@@ -89,8 +86,8 @@ impl PipelineStage for RequestExecutionStage {
8986
}
9087
};
9188

92-
let status =
93-
StatusCode::from_u16(resp.status().as_u16()).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
89+
let status = StatusCode::from_u16(resp.status().as_u16())
90+
.unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
9491

9592
// Handle streaming responses - return early
9693
if payload_output.is_streaming {
@@ -115,8 +112,7 @@ impl PipelineStage for RequestExecutionStage {
115112
}
116113
});
117114

118-
let mut response =
119-
Response::new(Body::from_stream(UnboundedReceiverStream::new(rx)));
115+
let mut response = Response::new(Body::from_stream(UnboundedReceiverStream::new(rx)));
120116
*response.status_mut() = status;
121117
response
122118
.headers_mut()

sgl-router/src/routers/openai/stages/mcp_preparation.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ impl McpPreparationStage {
5757

5858
if !tools_json.is_empty() {
5959
obj.insert("tools".to_string(), Value::Array(tools_json));
60-
obj.insert(
61-
"tool_choice".to_string(),
62-
Value::String("auto".to_string()),
63-
);
60+
obj.insert("tool_choice".to_string(), Value::String("auto".to_string()));
6461
}
6562
}
6663
}

sgl-router/src/routers/openai/stages/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ pub trait PipelineStage: Send + Sync {
3131
// Stage Modules (imported here)
3232
// ============================================================================
3333

34-
mod validation;
35-
mod discovery;
3634
mod context_loading;
37-
mod request_building;
38-
mod mcp_preparation;
35+
mod discovery;
3936
mod execution;
40-
mod response_processing;
37+
mod mcp_preparation;
4138
mod persistence;
39+
mod request_building;
40+
mod response_processing;
41+
mod validation;
4242

4343
// Export stage implementations
44-
pub use validation::ValidationStage;
45-
pub use discovery::ModelDiscoveryStage;
4644
pub use context_loading::ContextLoadingStage;
47-
pub use request_building::RequestBuildingStage;
48-
pub use mcp_preparation::McpPreparationStage;
45+
pub use discovery::ModelDiscoveryStage;
4946
pub use execution::RequestExecutionStage;
50-
pub use response_processing::ResponseProcessingStage;
47+
pub use mcp_preparation::McpPreparationStage;
5148
pub use persistence::PersistenceStage;
49+
pub use request_building::RequestBuildingStage;
50+
pub use response_processing::ResponseProcessingStage;
51+
pub use validation::ValidationStage;

sgl-router/src/routers/openai/stages/persistence.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
//! - Returns final JSON response
88
99
use async_trait::async_trait;
10-
use axum::{http::StatusCode, response::{IntoResponse, Response}, Json};
10+
use axum::{
11+
http::StatusCode,
12+
response::{IntoResponse, Response},
13+
Json,
14+
};
1115
use tracing::warn;
1216

1317
use super::PipelineStage;
@@ -37,7 +41,9 @@ impl PipelineStage for PersistenceStage {
3741
RequestType::Responses(req) => req,
3842
RequestType::Chat(_) => {
3943
// For chat requests, just return the JSON response
40-
return Ok(Some((StatusCode::OK, Json(processed.json_response)).into_response()));
44+
return Ok(Some(
45+
(StatusCode::OK, Json(processed.json_response)).into_response(),
46+
));
4147
}
4248
};
4349

@@ -100,9 +106,7 @@ mod tests {
100106
chat::{ChatCompletionRequest, ChatMessage, MessageContent},
101107
responses::{ResponseInput, ResponsesRequest},
102108
},
103-
routers::openai::context::{
104-
ProcessedResponse, RequestInput, SharedComponents,
105-
},
109+
routers::openai::context::{ProcessedResponse, RequestInput, SharedComponents},
106110
};
107111

108112
async fn create_test_components(worker_urls: Vec<String>) -> Arc<SharedComponents> {

sgl-router/src/routers/openai/stages/request_building.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
use std::collections::HashSet;
1111

1212
use async_trait::async_trait;
13-
use axum::{http::StatusCode, response::{IntoResponse, Response}};
13+
use axum::{
14+
http::StatusCode,
15+
response::{IntoResponse, Response},
16+
};
1417
use once_cell::sync::Lazy;
1518
use serde_json::{to_value, Value};
1619

@@ -408,7 +411,10 @@ mod tests {
408411

409412
// First item should be the conversation history
410413
let first_item = input_arr[0].as_object().unwrap();
411-
assert_eq!(first_item.get("role").and_then(|v| v.as_str()), Some("user"));
414+
assert_eq!(
415+
first_item.get("role").and_then(|v| v.as_str()),
416+
Some("user")
417+
);
412418

413419
// Second item should be current request
414420
let second_item = input_arr[1].as_object().unwrap();

0 commit comments

Comments
 (0)