Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
83b22400
Unverified
Commit
83b22400
authored
Oct 27, 2025
by
Simo Lin
Committed by
GitHub
Oct 27, 2025
Browse files
[router] remove code duplication (#12245)
parent
285a8e69
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
20 deletions
+9
-20
sgl-router/src/routers/openai/conversations.rs
sgl-router/src/routers/openai/conversations.rs
+2
-2
sgl-router/src/routers/openai/mcp.rs
sgl-router/src/routers/openai/mcp.rs
+4
-2
sgl-router/src/routers/openai/router.rs
sgl-router/src/routers/openai/router.rs
+3
-6
sgl-router/src/routers/openai/utils.rs
sgl-router/src/routers/openai/utils.rs
+0
-10
No files found.
sgl-router/src/routers/openai/conversations.rs
View file @
83b22400
...
@@ -11,14 +11,14 @@ use chrono::Utc;
...
@@ -11,14 +11,14 @@ use chrono::Utc;
use
serde_json
::{
json
,
Value
};
use
serde_json
::{
json
,
Value
};
use
tracing
::{
debug
,
info
,
warn
};
use
tracing
::{
debug
,
info
,
warn
};
use
super
::
{
responses
::
build_stored_response
,
utils
::
generate_id
}
;
use
super
::
responses
::
build_stored_response
;
use
crate
::{
use
crate
::{
data_connector
::{
data_connector
::{
Conversation
,
ConversationId
,
ConversationItemId
,
ConversationItemStorage
,
Conversation
,
ConversationId
,
ConversationItemId
,
ConversationItemStorage
,
ConversationStorage
,
ListParams
,
NewConversation
,
NewConversationItem
,
ResponseId
,
ConversationStorage
,
ListParams
,
NewConversation
,
NewConversationItem
,
ResponseId
,
ResponseStorage
,
SortOrder
,
ResponseStorage
,
SortOrder
,
},
},
protocols
::
responses
::{
ResponseInput
,
ResponsesRequest
},
protocols
::
responses
::{
generate_id
,
ResponseInput
,
ResponsesRequest
},
};
};
/// Maximum number of properties allowed in conversation metadata
/// Maximum number of properties allowed in conversation metadata
...
...
sgl-router/src/routers/openai/mcp.rs
View file @
83b22400
...
@@ -16,10 +16,12 @@ use serde_json::{json, to_value, Value};
...
@@ -16,10 +16,12 @@ use serde_json::{json, to_value, Value};
use
tokio
::
sync
::
mpsc
;
use
tokio
::
sync
::
mpsc
;
use
tracing
::{
debug
,
info
,
warn
};
use
tracing
::{
debug
,
info
,
warn
};
use
super
::
utils
::
{
event_types
,
generate_id
}
;
use
super
::
utils
::
event_types
;
use
crate
::{
use
crate
::{
mcp
,
mcp
,
protocols
::
responses
::{
ResponseInput
,
ResponseTool
,
ResponseToolType
,
ResponsesRequest
},
protocols
::
responses
::{
generate_id
,
ResponseInput
,
ResponseTool
,
ResponseToolType
,
ResponsesRequest
,
},
routers
::
header_utils
::
apply_request_headers
,
routers
::
header_utils
::
apply_request_headers
,
};
};
...
...
sgl-router/src/routers/openai/router.rs
View file @
83b22400
...
@@ -52,8 +52,8 @@ use crate::{
...
@@ -52,8 +52,8 @@ use crate::{
generate
::
GenerateRequest
,
generate
::
GenerateRequest
,
rerank
::
RerankRequest
,
rerank
::
RerankRequest
,
responses
::{
responses
::{
ResponseContentPart
,
ResponseInput
,
ResponseInputOutputItem
,
ResponsesGetParams
,
generate_id
,
ResponseContentPart
,
ResponseInput
,
ResponseInputOutputItem
,
ResponsesRequest
,
ResponsesGetParams
,
ResponsesRequest
,
},
},
},
},
routers
::
header_utils
::
apply_request_headers
,
routers
::
header_utils
::
apply_request_headers
,
...
@@ -1034,10 +1034,7 @@ impl crate::routers::RouterTrait for OpenAIRouter {
...
@@ -1034,10 +1034,7 @@ impl crate::routers::RouterTrait for OpenAIRouter {
if
item
.get
(
"id"
)
.is_none
()
{
if
item
.get
(
"id"
)
.is_none
()
{
// Generate ID if not present using centralized utility
// Generate ID if not present using centralized utility
if
let
Some
(
obj
)
=
item
.as_object_mut
()
{
if
let
Some
(
obj
)
=
item
.as_object_mut
()
{
obj
.insert
(
obj
.insert
(
"id"
.to_string
(),
json!
(
generate_id
(
"msg"
)));
"id"
.to_string
(),
json!
(
super
::
utils
::
generate_id
(
"msg"
)),
);
}
}
}
}
item
item
...
...
sgl-router/src/routers/openai/utils.rs
View file @
83b22400
...
@@ -220,16 +220,6 @@ pub async fn probe_endpoint_for_model(
...
@@ -220,16 +220,6 @@ pub async fn probe_endpoint_for_model(
}
}
}
}
pub
fn
generate_id
(
prefix
:
&
str
)
->
String
{
use
rand
::
RngCore
;
let
mut
rng
=
rand
::
rng
();
// Generate exactly 50 hex characters (25 bytes) for the part after the underscore
let
mut
bytes
=
[
0u8
;
25
];
rng
.fill_bytes
(
&
mut
bytes
);
let
hex_string
:
String
=
bytes
.iter
()
.map
(|
b
|
format!
(
"{:02x}"
,
b
))
.collect
();
format!
(
"{}_{}"
,
prefix
,
hex_string
)
}
// ============================================================================
// ============================================================================
// Re-export FunctionCallInProgress from mcp module
// Re-export FunctionCallInProgress from mcp module
// ============================================================================
// ============================================================================
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment