[MyPy] Fix mypy for vllm/benchmarks (#39896)
Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
co-authored by
Harry Mellor
parent
547d2c40d7
commit
275b43183c
@@ -75,7 +75,7 @@ class RequestFuncInput:
|
||||
logprobs: int | None = None
|
||||
extra_headers: dict | None = None
|
||||
extra_body: dict | None = None
|
||||
multi_modal_content: dict | list[dict] | None = None
|
||||
multi_modal_content: dict[str, Any] | list[dict[str, Any]] | None = None
|
||||
ignore_eos: bool = False
|
||||
language: str | None = None
|
||||
request_id: str | None = None
|
||||
@@ -272,13 +272,13 @@ def _get_chat_content(
|
||||
request_func_input: RequestFuncInput,
|
||||
mm_position: Literal["first", "last"] = "last",
|
||||
) -> list[dict[str, Any]]:
|
||||
mm_contents = []
|
||||
mm_contents: list[dict[str, Any]] = []
|
||||
if request_func_input.multi_modal_content:
|
||||
mm_content = request_func_input.multi_modal_content
|
||||
if isinstance(mm_content, list):
|
||||
mm_contents.extend(request_func_input.multi_modal_content)
|
||||
mm_contents.extend(mm_content)
|
||||
elif isinstance(mm_content, dict):
|
||||
mm_contents.append(request_func_input.multi_modal_content)
|
||||
mm_contents.append(mm_content)
|
||||
else:
|
||||
raise TypeError(
|
||||
"multi_modal_content must be a dict or list[dict] for openai-chat"
|
||||
@@ -293,10 +293,11 @@ def _get_chat_content(
|
||||
for item in prompt
|
||||
)
|
||||
):
|
||||
prompt_dicts: list[dict[str, Any]] = prompt # type: ignore[assignment]
|
||||
if mm_position == "first":
|
||||
return mm_contents + prompt
|
||||
return mm_contents + prompt_dicts
|
||||
|
||||
return prompt + mm_contents
|
||||
return prompt_dicts + mm_contents
|
||||
|
||||
text_contents = [{"type": "text", "text": prompt}]
|
||||
|
||||
@@ -307,15 +308,15 @@ def _get_chat_content(
|
||||
|
||||
|
||||
def _is_chat_messages(prompt: Any) -> bool:
|
||||
return (
|
||||
isinstance(prompt, list)
|
||||
and prompt
|
||||
and all(
|
||||
isinstance(item, dict)
|
||||
and isinstance(item.get("role"), str)
|
||||
and isinstance(item.get("content"), (str, list))
|
||||
for item in prompt
|
||||
)
|
||||
if not isinstance(prompt, list):
|
||||
return False
|
||||
if not prompt:
|
||||
return False
|
||||
return all(
|
||||
isinstance(item, dict)
|
||||
and isinstance(item.get("role"), str)
|
||||
and isinstance(item.get("content"), (str, list))
|
||||
for item in prompt
|
||||
)
|
||||
|
||||
|
||||
@@ -325,7 +326,7 @@ def _get_chat_messages(
|
||||
) -> list[dict[str, Any]]:
|
||||
prompt = request_func_input.prompt
|
||||
if _is_chat_messages(prompt):
|
||||
return prompt
|
||||
return prompt # type: ignore[return-value]
|
||||
|
||||
return [
|
||||
{
|
||||
@@ -385,8 +386,8 @@ async def async_request_openai_chat_completions(
|
||||
if not chunk_bytes:
|
||||
continue
|
||||
|
||||
messages = handler.add_chunk(chunk_bytes)
|
||||
for message in messages:
|
||||
message_strings = handler.add_chunk(chunk_bytes)
|
||||
for message in message_strings:
|
||||
# NOTE: SSE comments (often used as pings) start with
|
||||
# a colon. These are not JSON data payload and should
|
||||
# be skipped.
|
||||
@@ -790,7 +791,7 @@ async def async_request_infinity_embeddings(
|
||||
api_url = request_func_input.api_url
|
||||
_validate_api_url(api_url, "Infinity Embeddings API", "embeddings")
|
||||
|
||||
payload = {
|
||||
payload: dict[str, Any] = {
|
||||
"model": request_func_input.model_name
|
||||
if request_func_input.model_name
|
||||
else request_func_input.model,
|
||||
@@ -849,7 +850,10 @@ async def async_request_vllm_pooling(
|
||||
"truncate_prompt_tokens": -1,
|
||||
}
|
||||
|
||||
payload = payload | request_func_input.prompt
|
||||
if isinstance(request_func_input.prompt, dict):
|
||||
payload = payload | request_func_input.prompt
|
||||
else:
|
||||
payload["input"] = request_func_input.prompt
|
||||
|
||||
_update_payload_common(payload, request_func_input)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user