refactor(bedrock): return unsupported transcription params as a value and raise at the param step

This commit is contained in:
mateo-berri 2026-10-28 14:44:39 -07:00
parent 327016967c
commit c02f40a6bb
2 changed files with 20 additions and 11 deletions

View file

@ -1,12 +1,12 @@
import base64
import math
from collections.abc import Mapping
from dataclasses import dataclass
from typing import Final
import httpx
from pydantic import BaseModel, ConfigDict
from litellm.exceptions import UnsupportedParamsError
from litellm.litellm_core_utils.audio_utils.utils import process_audio_file
from litellm.rust_bridge import runtime
from litellm.rust_bridge.catalog import Route, RouteContext
@ -45,16 +45,20 @@ def _rejection(key: str, value: object) -> str | None:
return None
@dataclass(frozen=True, slots=True)
class UnsupportedTranscriptionParams:
message: str
def map_openai_transcription_params(
non_default_params: Mapping[str, object], drop_params: bool
) -> Mapping[str, object]:
) -> Mapping[str, object] | UnsupportedTranscriptionParams:
rejections: Final = {
key: reason for key, value in non_default_params.items() if (reason := _rejection(key, value)) is not None
}
if rejections and not drop_params:
raise UnsupportedParamsError(
message=f"{' '.join(rejections.values())} To drop it from the call, set `litellm.drop_params = True`.",
llm_provider="bedrock",
return UnsupportedTranscriptionParams(
message=f"{' '.join(rejections.values())} To drop it from the call, set `litellm.drop_params = True`."
)
return {
key: _as_float(value) if key == "temperature" else value

View file

@ -4107,13 +4107,18 @@ def get_optional_params_transcription(
drop_params=drop_params if drop_params is not None else False,
)
elif custom_llm_provider == "bedrock":
from litellm.llms.bedrock.audio_transcription import map_openai_transcription_params
optional_params = dict(
map_openai_transcription_params(
non_default_params, drop_params=drop_params is True or litellm.drop_params is True
)
from litellm.llms.bedrock.audio_transcription import (
UnsupportedTranscriptionParams,
map_openai_transcription_params,
)
match map_openai_transcription_params(
non_default_params, drop_params=drop_params is True or litellm.drop_params is True
):
case UnsupportedTranscriptionParams(message=message):
raise UnsupportedParamsError(message=message, llm_provider="bedrock")
case mapped_params:
optional_params = dict(mapped_params)
elif provider_config is not None: # custom audio transcription config
supported_params = provider_config.get_supported_openai_params(model=model)
_check_valid_arg(supported_params=supported_params)