Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lightllm/server/api_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ async def completions_impl(request: CompletionRequest, raw_request: Request) ->


async def _process_prompts_completion(
prompts: List[str] | List[List[int]],
prompts: Union[List[str], List[List[int]]],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve readability and maintainability, consider defining type aliases for the complex Union types introduced in this PR. This makes the code cleaner and easier to understand, especially since Union[str, List[int]] is used in multiple function signatures.

You could define these at the module level:

PromptType = Union[str, List[int]]
PromptsType = Union[List[str], List[List[int]]]

Then you can use PromptsType here, and PromptType in the signatures of process_single_prompt and _handle_streaming_completion.

sampling_params: SamplingParams,
sampling_params_dict: Dict,
multimodal_params: MultimodalParams,
Expand All @@ -411,7 +411,7 @@ async def _process_prompts_completion(
prompts[0], sampling_params, multimodal_params, raw_request, request, created_time
)

async def process_single_prompt(prompt: str | List[int], prompt_index: int):
async def process_single_prompt(prompt: Union[str, List[int]], prompt_index: int):
if len(prompts) > 1:
individual_sampling_params = SamplingParams()
individual_sampling_params.init(tokenizer=g_objs.httpserver_manager.tokenizer, **sampling_params_dict)
Expand All @@ -437,7 +437,7 @@ async def process_single_prompt(prompt: str | List[int], prompt_index: int):


async def _handle_streaming_completion(
prompt: str | List[int],
prompt: Union[str, List[int]],
sampling_params: SamplingParams,
multimodal_params: MultimodalParams,
raw_request: Request,
Expand Down