Skip to content

Commit d33955d

Browse files
authored
Properly return error response in vertex_generate HTTP endpoint (sgl-project#5956)
1 parent 6fc1759 commit d33955d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

python/sglang/srt/entrypoints/http_server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,8 @@ async def vertex_generate(vertex_req: VertexGenerateReqInput, raw_request: Reque
675675
**(vertex_req.parameters or {}),
676676
)
677677
ret = await generate_request(req, raw_request)
678+
if isinstance(ret, Response):
679+
return ret
678680
return ORJSONResponse({"predictions": ret})
679681

680682

test/srt/test_vertex_endpoint.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import unittest
6+
from http import HTTPStatus
67

78
import requests
89

@@ -49,6 +50,15 @@ def test_vertex_generate(self):
4950
for parameters in [None, {"sampling_params": {"max_new_tokens": 4}}]:
5051
self.run_generate(parameters)
5152

53+
def test_vertex_generate_fail(self):
54+
data = {
55+
"instances": [
56+
{"prompt": "The capital of France is"},
57+
],
58+
}
59+
response = requests.post(self.base_url + "/vertex_generate", json=data)
60+
assert response.status_code == HTTPStatus.BAD_REQUEST
61+
5262

5363
if __name__ == "__main__":
5464
unittest.main()

0 commit comments

Comments
 (0)