style(byteplus): format code with ruff and fix lint issues

This commit is contained in:
agungbesti 2026-09-15 04:06:18 +07:00
parent b4232ec3fd
commit 5e266bf57f
7 changed files with 54 additions and 42 deletions

View file

@ -3,6 +3,8 @@ BytePlus LLM Provider
Support for BytePlus (ModelArk) chat, embedding, responses, image generation, and TTS models.
"""
from typing import Final
from .chat.transformation import BytePlusChatConfig
from .common_utils import (
BytePlusError,
@ -14,8 +16,6 @@ from .image_generation.transformation import BytePlusImageGenerationConfig
from .responses.transformation import BytePlusResponsesAPIConfig
from .text_to_speech.transformation import BytePlusTextToSpeechConfig
from typing import Final
BytePlusConfig: Final = BytePlusChatConfig
__all__ = (

View file

@ -12,9 +12,7 @@ class BytePlusChatConfig(OpenAILikeChatConfig):
def get_config(cls) -> "BytePlusChatConfig":
return super().get_config()
def get_supported_openai_params(
self, model: str
) -> list: # mutable-ok: matches BaseConfig interface
def get_supported_openai_params(self, model: str) -> list: # mutable-ok: matches BaseConfig interface
return [ # mutable-ok: matches BaseConfig interface
"frequency_penalty",
"logit_bias",
@ -59,9 +57,12 @@ class BytePlusChatConfig(OpenAILikeChatConfig):
thinking_val: Final = mapped_params.pop("thinking", None)
if thinking_val is not None:
if isinstance(thinking_val, bool):
mapped_params["extra_body"] = {"thinking": {"type": "enabled" if thinking_val else "disabled"}} # mutable-ok: extra_body payload dict
mapped_params["extra_body"] = { # mutable-ok: extra_body payload dict
"thinking": { # mutable-ok: nested thinking dict
"type": "enabled" if thinking_val else "disabled"
},
}
elif isinstance(thinking_val, dict):
mapped_params["extra_body"] = {"thinking": thinking_val} # mutable-ok: extra_body payload dict
return mapped_params

View file

@ -34,4 +34,3 @@ def get_byteplus_headers(
headers.update(extra_headers)
return headers

View file

@ -1,7 +1,6 @@
from __future__ import annotations
import json
from collections.abc import Mapping, Sequence
from typing import TYPE_CHECKING, Final
import httpx
@ -29,12 +28,10 @@ class BytePlusEmbeddingConfig(BaseEmbeddingConfig):
"""
@classmethod
def get_config(cls) -> "BytePlusEmbeddingConfig":
def get_config(cls) -> BytePlusEmbeddingConfig:
return super().get_config()
def get_supported_openai_params(
self, model: str
) -> list[str]: # mutable-ok: matches BaseEmbeddingConfig interface
def get_supported_openai_params(self, model: str) -> list[str]: # mutable-ok: matches BaseEmbeddingConfig interface
return [ # mutable-ok: matches BaseEmbeddingConfig interface
"encoding_format",
"user",
@ -81,7 +78,9 @@ class BytePlusEmbeddingConfig(BaseEmbeddingConfig):
drop_params: bool,
) -> dict: # mutable-ok: matches BaseEmbeddingConfig interface
supported: Final = frozenset(self.get_supported_openai_params(model))
optional_params.update({k: v for k, v in non_default_params.items() if k in supported}) # mutable-ok: update params dict
optional_params.update(
{k: v for k, v in non_default_params.items() if k in supported} # mutable-ok: update params dict
)
return optional_params
def transform_embedding_request(
@ -116,7 +115,9 @@ class BytePlusEmbeddingConfig(BaseEmbeddingConfig):
data[key] = optional_params[key]
if "extra_body" in optional_params and isinstance(optional_params["extra_body"], dict):
extra_body: Final = {k: v for k, v in optional_params["extra_body"].items() if k not in ("model", "input")} # mutable-ok: extra_body dictionary
extra_body: Final = { # mutable-ok: extra_body dictionary
k: v for k, v in optional_params["extra_body"].items() if k not in ("model", "input")
}
data.update(extra_body)
return data
@ -126,7 +127,7 @@ class BytePlusEmbeddingConfig(BaseEmbeddingConfig):
model: str,
raw_response: httpx.Response,
model_response: EmbeddingResponse,
logging_obj: "LiteLLMLoggingObj",
logging_obj: LiteLLMLoggingObj,
api_key: str | None,
request_data: dict, # mutable-ok: matches BaseEmbeddingConfig interface
optional_params: dict, # mutable-ok: matches BaseEmbeddingConfig interface
@ -183,10 +184,10 @@ class BytePlusEmbeddingConfig(BaseEmbeddingConfig):
return get_byteplus_headers(api_key=resolved_api_key, extra_headers=headers)
def get_error_class(
self, error_message: str, status_code: int, headers: dict | httpx.Headers # mutable-ok: matches BaseEmbeddingConfig interface
self,
error_message: str,
status_code: int,
headers: dict | httpx.Headers, # mutable-ok: matches BaseEmbeddingConfig interface
) -> BytePlusError:
typed_headers: Final[httpx.Headers] = (
headers if isinstance(headers, httpx.Headers) else httpx.Headers(headers)
)
typed_headers: Final[httpx.Headers] = headers if isinstance(headers, httpx.Headers) else httpx.Headers(headers)
return BytePlusError(status_code=status_code, message=error_message, headers=typed_headers)

View file

@ -32,7 +32,13 @@ class BytePlusImageGenerationConfig(BaseImageGenerationConfig):
def get_supported_openai_params(
self, model: str
) -> list[OpenAIImageGenerationOptionalParams]: # mutable-ok: matches BaseImageGenerationConfig interface
return ["n", "response_format", "size", "user", "quality"] # mutable-ok: matches BaseImageGenerationConfig interface
return [ # mutable-ok: matches BaseImageGenerationConfig interface
"n",
"response_format",
"size",
"user",
"quality",
]
def map_openai_params(
self,
@ -42,7 +48,9 @@ class BytePlusImageGenerationConfig(BaseImageGenerationConfig):
drop_params: bool,
) -> dict: # mutable-ok: matches BaseImageGenerationConfig interface
supported_params: Final = frozenset(self.get_supported_openai_params(model))
optional_params.update({k: v for k, v in non_default_params.items() if k in supported_params}) # mutable-ok: update params dict
optional_params.update(
{k: v for k, v in non_default_params.items() if k in supported_params} # mutable-ok: update params dict
)
return optional_params
@ -86,11 +94,12 @@ class BytePlusImageGenerationConfig(BaseImageGenerationConfig):
return f"{base_url}/api/v3/images/generations"
def get_error_class(
self, error_message: str, status_code: int, headers: dict | httpx.Headers # mutable-ok: matches BaseImageGenerationConfig interface
self,
error_message: str,
status_code: int,
headers: dict | httpx.Headers, # mutable-ok: matches BaseImageGenerationConfig interface
) -> BytePlusError:
typed_headers: Final[httpx.Headers] = (
headers if isinstance(headers, httpx.Headers) else httpx.Headers(headers)
)
typed_headers: Final[httpx.Headers] = headers if isinstance(headers, httpx.Headers) else httpx.Headers(headers)
return BytePlusError(
status_code=status_code,
message=error_message,
@ -125,7 +134,9 @@ class BytePlusImageGenerationConfig(BaseImageGenerationConfig):
body[key] = optional_params[key]
if "extra_body" in optional_params and isinstance(optional_params["extra_body"], dict):
extra_body: Final = {k: v for k, v in optional_params["extra_body"].items() if k not in ("model", "prompt")} # mutable-ok: extra body dictionary
extra_body: Final = { # mutable-ok: extra body dictionary
k: v for k, v in optional_params["extra_body"].items() if k not in ("model", "prompt")
}
body.update(extra_body)
return body
@ -135,7 +146,7 @@ class BytePlusImageGenerationConfig(BaseImageGenerationConfig):
model: str,
raw_response: httpx.Response,
model_response: ImageResponse,
logging_obj: "LiteLLMLoggingObj",
logging_obj: LiteLLMLoggingObj,
request_data: dict, # mutable-ok: matches BaseImageGenerationConfig interface
optional_params: dict, # mutable-ok: matches BaseImageGenerationConfig interface
litellm_params: dict, # mutable-ok: matches BaseImageGenerationConfig interface
@ -160,4 +171,3 @@ class BytePlusImageGenerationConfig(BaseImageGenerationConfig):
)
return image_response

View file

@ -23,11 +23,12 @@ class BytePlusResponsesAPIConfig(VolcEngineResponsesAPIConfig):
return LlmProviders.BYTEPLUS
def get_error_class(
self, error_message: str, status_code: int, headers: dict | httpx.Headers # mutable-ok: matches BaseResponsesAPIConfig interface
self,
error_message: str,
status_code: int,
headers: dict | httpx.Headers, # mutable-ok: matches BaseResponsesAPIConfig interface
) -> BytePlusError:
typed_headers: Final[httpx.Headers] = (
headers if isinstance(headers, httpx.Headers) else httpx.Headers(headers)
)
typed_headers: Final[httpx.Headers] = headers if isinstance(headers, httpx.Headers) else httpx.Headers(headers)
return BytePlusError(
status_code=status_code,
message=error_message,
@ -78,4 +79,3 @@ class BytePlusResponsesAPIConfig(VolcEngineResponsesAPIConfig):
if base_url.endswith("/api/v3"):
return f"{base_url}/responses"
return f"{base_url}/api/v3/responses"

View file

@ -131,7 +131,6 @@ class BytePlusTextToSpeechConfig(BaseTextToSpeechConfig):
"speed",
]
def map_openai_params(
self,
model: str,
@ -170,9 +169,7 @@ class BytePlusTextToSpeechConfig(BaseTextToSpeechConfig):
access_key: Final = get_secret_str("BYTEPLUS_TTS_ACCESS_KEY")
app_key: Final = get_secret_str("BYTEPLUS_TTS_APP_KEY") or self.DEFAULT_APP_KEY
resource_id: Final[str] = (
model.removeprefix("byteplus/") if model.startswith("byteplus/") else model
)
resource_id: Final[str] = model.removeprefix("byteplus/") if model.startswith("byteplus/") else model
req_headers: Final[dict[str, str]] = { # mutable-ok: building concrete request headers to update
"X-Api-Resource-Id": resource_id,
@ -238,7 +235,9 @@ class BytePlusTextToSpeechConfig(BaseTextToSpeechConfig):
) -> TextToSpeechRequestData:
params: Final[dict] = dict(optional_params or {}) # mutable-ok: local copy of optional parameters
raw_extra_body: Final = params.pop("extra_body", None)
extra_body: Final[dict] = raw_extra_body if isinstance(raw_extra_body, dict) else {} # mutable-ok: extra body parameters
extra_body: Final[dict] = ( # mutable-ok: extra body parameters
raw_extra_body if isinstance(raw_extra_body, dict) else {} # mutable-ok: fallback empty dict
)
raw_speaker: Final = voice or extra_body.get("speaker") or "en_female_stokie_uranus_bigtts"
speaker: Final = (
@ -375,7 +374,9 @@ class BytePlusTextToSpeechConfig(BaseTextToSpeechConfig):
**kwargs: object, # kwargs-ok: matches BaseTextToSpeechConfig interface
) -> object:
safe_extra_headers: Final[dict | None] = ( # mutable-ok: filtered request headers dictionary
{k: v for k, v in extra_headers.items() if k.lower() not in _BYTEPLUS_TTS_AUTH_HEADERS} # mutable-ok: filtered headers dict comprehension
{ # mutable-ok: filtered headers dict comprehension
k: v for k, v in extra_headers.items() if k.lower() not in _BYTEPLUS_TTS_AUTH_HEADERS
}
if extra_headers
else None
)
@ -385,7 +386,7 @@ class BytePlusTextToSpeechConfig(BaseTextToSpeechConfig):
"api_base": api_base,
}
)
handler_func: Final = getattr(base_llm_http_handler, "text_to_speech_handler")
handler_func: Final = base_llm_http_handler.text_to_speech_handler
return handler_func(
model=model,
input=input,