Skip to content

Commit 04eb606

Browse files
authored
Include context length in /v1/models response. (#4809)
1 parent e84f4ba commit 04eb606

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

python/sglang/srt/entrypoints/http_server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,13 @@ def available_models():
561561
served_model_names = [_global_state.tokenizer_manager.served_model_name]
562562
model_cards = []
563563
for served_model_name in served_model_names:
564-
model_cards.append(ModelCard(id=served_model_name, root=served_model_name))
564+
model_cards.append(
565+
ModelCard(
566+
id=served_model_name,
567+
root=served_model_name,
568+
max_model_len=_global_state.tokenizer_manager.model_config.context_len,
569+
)
570+
)
565571
return ModelList(data=model_cards)
566572

567573

python/sglang/srt/openai_api/protocol.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ModelCard(BaseModel):
2828
created: int = Field(default_factory=lambda: int(time.time()))
2929
owned_by: str = "sglang"
3030
root: Optional[str] = None
31+
max_model_len: Optional[int] = None
3132

3233

3334
class ModelList(BaseModel):

test/srt/test_openai_server.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,12 @@ def test_response_prefill(self):
542542
.startswith('"name": "SmartHome Mini",')
543543
)
544544

545+
def test_model_list(self):
546+
client = openai.Client(api_key=self.api_key, base_url=self.base_url)
547+
models = list(client.models.list())
548+
assert len(models) == 1
549+
assert isinstance(getattr(models[0], "max_model_len", None), int)
550+
545551

546552
# -------------------------------------------------------------------------
547553
# EBNF Test Class: TestOpenAIServerEBNF

0 commit comments

Comments
 (0)