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
b0facb33
"vscode:/vscode.git/clone" did not exist on "ae63bd08a3c6d8e5a468c13ece2ec04e6745dcdf"
Unverified
Commit
b0facb33
authored
Oct 16, 2024
by
Michael Feil
Committed by
GitHub
Oct 16, 2024
Browse files
add orjson for jsonresponse (#1688)
parent
ecb8bad2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
11 deletions
+11
-11
python/pyproject.toml
python/pyproject.toml
+1
-1
python/sglang/srt/openai_api/adapter.py
python/sglang/srt/openai_api/adapter.py
+2
-2
python/sglang/srt/server.py
python/sglang/srt/server.py
+6
-6
python/sglang/srt/utils.py
python/sglang/srt/utils.py
+2
-2
No files found.
python/pyproject.toml
View file @
b0facb33
...
...
@@ -21,7 +21,7 @@ dependencies = [
[project.optional-dependencies]
runtime_common
=
[
"aiohttp"
,
"decord"
,
"fastapi"
,
"hf_transfer"
,
"huggingface_hub"
,
"interegular"
,
"packaging"
,
"pillow"
,
"psutil"
,
"pydantic"
,
"python-multipart"
,
"orjson"
,
"packaging"
,
"pillow"
,
"psutil"
,
"pydantic"
,
"python-multipart"
,
"torchao"
,
"uvicorn"
,
"uvloop"
,
"zmq"
,
"outlines>=0.0.44"
,
"modelscope"
]
# xpu is not enabled in public vllm and torch whl,
...
...
python/sglang/srt/openai_api/adapter.py
View file @
b0facb33
...
...
@@ -25,7 +25,7 @@ from http import HTTPStatus
from
typing
import
Dict
,
List
from
fastapi
import
HTTPException
,
Request
,
UploadFile
from
fastapi.responses
import
JSONResponse
,
StreamingResponse
from
fastapi.responses
import
OR
JSONResponse
,
StreamingResponse
from
pydantic
import
ValidationError
try
:
...
...
@@ -101,7 +101,7 @@ def create_error_response(
status_code
:
HTTPStatus
=
HTTPStatus
.
BAD_REQUEST
,
):
error
=
ErrorResponse
(
message
=
message
,
type
=
err_type
,
code
=
status_code
.
value
)
return
JSONResponse
(
content
=
error
.
model_dump
(),
status_code
=
error
.
code
)
return
OR
JSONResponse
(
content
=
error
.
model_dump
(),
status_code
=
error
.
code
)
def
create_streaming_error_response
(
...
...
python/sglang/srt/server.py
View file @
b0facb33
...
...
@@ -40,7 +40,7 @@ import uvicorn
import
uvloop
from
fastapi
import
FastAPI
,
File
,
Form
,
Request
,
UploadFile
from
fastapi.middleware.cors
import
CORSMiddleware
from
fastapi.responses
import
JSONResponse
,
Response
,
StreamingResponse
from
fastapi.responses
import
OR
JSONResponse
,
Response
,
StreamingResponse
from
sglang.lang.backend.runtime_endpoint
import
RuntimeEndpoint
from
sglang.srt.hf_transformers_utils
import
get_tokenizer
...
...
@@ -176,12 +176,12 @@ async def update_weights(obj: UpdateWeightReqInput, request: Request):
success
,
message
=
await
tokenizer_manager
.
update_weights
(
obj
,
request
)
content
=
{
"success"
:
success
,
"message"
:
message
}
if
success
:
return
JSONResponse
(
return
OR
JSONResponse
(
content
,
status_code
=
HTTPStatus
.
OK
,
)
else
:
return
JSONResponse
(
return
OR
JSONResponse
(
content
,
status_code
=
HTTPStatus
.
BAD_REQUEST
,
)
...
...
@@ -211,7 +211,7 @@ async def generate_request(obj: GenerateReqInput, request: Request):
ret
=
await
tokenizer_manager
.
generate_request
(
obj
,
request
).
__anext__
()
return
ret
except
ValueError
as
e
:
return
JSONResponse
(
return
OR
JSONResponse
(
{
"error"
:
{
"message"
:
str
(
e
)}},
status_code
=
HTTPStatus
.
BAD_REQUEST
)
...
...
@@ -226,7 +226,7 @@ async def encode_request(obj: EmbeddingReqInput, request: Request):
ret
=
await
tokenizer_manager
.
generate_request
(
obj
,
request
).
__anext__
()
return
ret
except
ValueError
as
e
:
return
JSONResponse
(
return
OR
JSONResponse
(
{
"error"
:
{
"message"
:
str
(
e
)}},
status_code
=
HTTPStatus
.
BAD_REQUEST
)
...
...
@@ -241,7 +241,7 @@ async def judge_request(obj: RewardReqInput, request: Request):
ret
=
await
tokenizer_manager
.
generate_request
(
obj
,
request
).
__anext__
()
return
ret
except
ValueError
as
e
:
return
JSONResponse
(
return
OR
JSONResponse
(
{
"error"
:
{
"message"
:
str
(
e
)}},
status_code
=
HTTPStatus
.
BAD_REQUEST
)
...
...
python/sglang/srt/utils.py
View file @
b0facb33
...
...
@@ -35,7 +35,7 @@ import psutil
import
requests
import
torch
import
torch.distributed
as
dist
from
fastapi.responses
import
JSONResponse
from
fastapi.responses
import
OR
JSONResponse
from
packaging
import
version
as
pkg_version
from
torch
import
nn
from
torch.profiler
import
ProfilerActivity
,
profile
,
record_function
...
...
@@ -566,7 +566,7 @@ def add_api_key_middleware(app, api_key: str):
if
request
.
url
.
path
.
startswith
(
"/health"
):
return
await
call_next
(
request
)
if
request
.
headers
.
get
(
"Authorization"
)
!=
"Bearer "
+
api_key
:
return
JSONResponse
(
content
=
{
"error"
:
"Unauthorized"
},
status_code
=
401
)
return
OR
JSONResponse
(
content
=
{
"error"
:
"Unauthorized"
},
status_code
=
401
)
return
await
call_next
(
request
)
...
...
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