Skip to content

Commit fe56f3a

Browse files
Superjomndominicshanshan
authored andcommitted
[None][doc] add status labels to LLM class's api reference (NVIDIA#6899)
Signed-off-by: Superjomn <[email protected]> Signed-off-by: Wangshanshan <[email protected]>
1 parent 29b0c89 commit fe56f3a

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

tensorrt_llm/llmapi/utils.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ def generate_api_docs_as_docstring(model: Type[BaseModel],
518518

519519
# Format the argument documentation with 12 spaces indent for args
520520
arg_line = f"{indent} {field_name} ({type_str}): "
521+
if status := field_info.get("status", None):
522+
arg_line += f":tag:`{status}` "
521523
if field_description:
522524
arg_line += field_description.split('\n')[0] # First line with type
523525

@@ -557,20 +559,21 @@ class ApiParamTagger:
557559
'''
558560

559561
def __call__(self, cls: Type[BaseModel]) -> None:
560-
self.process_pydantic_model(cls)
562+
""" The main entry point to tag the api doc. """
563+
self._process_pydantic_model(cls)
561564

562-
def process_pydantic_model(self, cls: Type[BaseModel]) -> None:
565+
def _process_pydantic_model(self, cls: Type[BaseModel]) -> None:
563566
"""Process the Pydantic model to add tags to the fields.
564567
"""
565568
for field_name, field_info in cls.model_fields.items():
566569
if field_info.json_schema_extra and 'status' in field_info.json_schema_extra:
567570
status = field_info.json_schema_extra['status']
568-
self.amend_pydantic_field_description_with_tags(
571+
self._amend_pydantic_field_description_with_tags(
569572
cls, [field_name], status)
570573

571-
def amend_pydantic_field_description_with_tags(self, cls: Type[BaseModel],
572-
field_names: list[str],
573-
tag: str) -> None:
574+
def _amend_pydantic_field_description_with_tags(self, cls: Type[BaseModel],
575+
field_names: list[str],
576+
tag: str) -> None:
574577
"""Amend the description of the fields with tags.
575578
e.g. :tag:`beta` or :tag:`prototype`
576579
Args:

tests/unittest/llmapi/test_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from tensorrt_llm.llmapi.utils import ApiStatusRegistry
1+
from tensorrt_llm.llmapi import LlmArgs
2+
from tensorrt_llm.llmapi.utils import (ApiStatusRegistry,
3+
generate_api_docs_as_docstring)
24

35

46
def test_api_status_registry():
@@ -24,3 +26,9 @@ def _my_method(self, *args, **kwargs):
2426
pass
2527

2628
assert ApiStatusRegistry.get_api_status(App._my_method) == "beta"
29+
30+
31+
def test_generate_api_docs_as_docstring():
32+
doc = generate_api_docs_as_docstring(LlmArgs)
33+
assert ":tag:`beta`" in doc, "the label is not generated"
34+
print(doc)

0 commit comments

Comments
 (0)