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
37373ef2
Unverified
Commit
37373ef2
authored
Mar 04, 2025
by
Michael Feil
Committed by
GitHub
Mar 04, 2025
Browse files
sgl-router - issues on routing and project build. (#3870) (#3948)
parent
61261b39
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
593 deletions
+61
-593
sgl-router/Cargo.lock
sgl-router/Cargo.lock
+25
-574
sgl-router/Cargo.toml
sgl-router/Cargo.toml
+0
-1
sgl-router/pyproject.toml
sgl-router/pyproject.toml
+1
-1
sgl-router/src/router.rs
sgl-router/src/router.rs
+35
-17
No files found.
sgl-router/Cargo.lock
View file @
37373ef2
This diff is collapsed.
Click to expand it.
sgl-router/Cargo.toml
View file @
37373ef2
...
...
@@ -19,7 +19,6 @@ reqwest = { version = "0.12.8", features = ["stream", "blocking"] }
futures-util
=
"0.3"
serde_json
=
"1.0"
pyo3
=
{
version
=
"0.22.5"
,
features
=
["extension-module"]
}
tokenizers
=
{
version
=
"0.20.3"
,
features
=
["http"]
}
dashmap
=
"6.1.0"
http
=
"1.1.0"
env_logger
=
"0.11.5"
...
...
sgl-router/pyproject.toml
View file @
37373ef2
...
...
@@ -9,7 +9,7 @@ description = "SGLang router is a standalone module implemented in Rust to achie
authors
=
[
{name
=
"Byron Hsu"
,
email
=
"byronhsu1230@gmail.com"
}
]
requires-python
=
">=3.8"
readme
=
"README.md"
license
=
{
file
=
"LICENSE
"
}
license
=
{
text
=
"Apache-2.0
"
}
classifiers
=
[
"Programming Language :: Python :: Implementation :: CPython"
,
"Programming Language :: Rust"
,
...
...
sgl-router/src/router.rs
View file @
37373ef2
...
...
@@ -4,6 +4,7 @@ use actix_web::{HttpRequest, HttpResponse};
use
bytes
::
Bytes
;
use
futures_util
::{
StreamExt
,
TryStreamExt
};
use
log
::{
debug
,
error
,
info
,
warn
};
use
serde_json
::
Value
;
use
std
::
collections
::
HashMap
;
use
std
::
fmt
::
Debug
;
use
std
::
sync
::
atomic
::
AtomicUsize
;
...
...
@@ -403,25 +404,42 @@ impl Router {
}
fn
get_text_from_request
(
&
self
,
body
:
&
Bytes
,
route
:
&
str
)
->
String
{
// convert body to json
let
json
=
serde_json
::
from_slice
::
<
serde_json
::
Value
>
(
body
)
.unwrap
();
if
route
==
"generate"
{
// get the "text" field
let
text
=
json
.get
(
"text"
)
.and_then
(|
t
|
t
.as_str
())
.unwrap_or
(
""
);
return
text
.to_string
();
}
else
if
route
==
"v1/chat/completions"
{
// get the messages field as raw text
if
let
Some
(
messages
)
=
json
.get
(
"messages"
)
{
// Convert messages back to a string, preserving all JSON formatting
return
serde_json
::
to_string
(
messages
)
.unwrap_or_default
();
// Convert body to JSON
let
json
:
Value
=
match
serde_json
::
from_slice
(
body
)
{
Ok
(
j
)
=>
j
,
Err
(
_
)
=>
{
warn!
(
"Failed to parse JSON from request body."
);
return
String
::
new
();
}
}
else
if
route
==
"v1/completions"
{
let
prompt
=
json
.get
(
"prompt"
)
.and_then
(|
t
|
t
.as_str
())
.unwrap_or
(
""
);
return
prompt
.to_string
();
}
};
return
""
.to_string
();
match
route
{
"/generate"
=>
{
// For /generate, always use the "text" field.
match
json
.get
(
"text"
)
.and_then
(
Value
::
as_str
)
{
Some
(
text
)
=>
text
.to_string
(),
None
=>
{
warn!
(
"No 'text' field found in request body for route /generate."
);
String
::
new
()
}
}
}
"/v1/chat/completions"
|
"/v1/completions"
=>
{
// For these routes, try "messages", then "prompt", then "text".
if
let
Some
(
messages
)
=
json
.get
(
"messages"
)
{
serde_json
::
to_string
(
messages
)
.unwrap_or_default
()
}
else
if
let
Some
(
prompt
)
=
json
.get
(
"prompt"
)
.and_then
(
Value
::
as_str
)
{
prompt
.to_string
()
}
else
{
warn!
(
"Failed to find 'messages', 'prompt' in request body."
);
String
::
new
()
}
}
_
=>
{
warn!
(
"Unknown route: {} - defaulting to fallback string"
,
route
);
String
::
new
()
}
}
}
// TODO: return Result<String, String> instead of panicking
...
...
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