"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .servervadchunkingstrategy import (
    ServerVadChunkingStrategy,
    ServerVadChunkingStrategyTypedDict,
)
from friendli.core.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict

ContainerAudioTranscriptionBodyChunkingStrategyTypedDict = TypeAliasType(
    "ContainerAudioTranscriptionBodyChunkingStrategyTypedDict",
    Union[ServerVadChunkingStrategyTypedDict, str],
)
'Controls how the audio is cut into chunks. When set to `\\"auto\\"`, the server first normalizes loudness and then uses voice activity detection (VAD) to choose boundaries. `server_vad` object can be provided to tweak VAD detection parameters manually. If unset, the audio is transcribed as a single block.'
ContainerAudioTranscriptionBodyChunkingStrategy = TypeAliasType(
    "ContainerAudioTranscriptionBodyChunkingStrategy",
    Union[ServerVadChunkingStrategy, str],
)
'Controls how the audio is cut into chunks. When set to `\\"auto\\"`, the server first normalizes loudness and then uses voice activity detection (VAD) to choose boundaries. `server_vad` object can be provided to tweak VAD detection parameters manually. If unset, the audio is transcribed as a single block.'


class ContainerAudioTranscriptionBodyTypedDict(TypedDict):
    file: bytes
    "The audio file object (not file name) to transcribe, in one of these formats: mp3, wav, flac, ogg, and many other standard audio formats."
    model: NotRequired[Nullable[str]]
    "Routes the request to a specific adapter."
    chunking_strategy: NotRequired[
        Nullable[ContainerAudioTranscriptionBodyChunkingStrategyTypedDict]
    ]
    'Controls how the audio is cut into chunks. When set to `\\"auto\\"`, the server first normalizes loudness and then uses voice activity detection (VAD) to choose boundaries. `server_vad` object can be provided to tweak VAD detection parameters manually. If unset, the audio is transcribed as a single block.'
    language: NotRequired[Nullable[str]]
    "The language of the input audio. Supplying the input language in [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`) format will improve accuracy and latency."
    temperature: NotRequired[Nullable[float]]
    "The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic."


class ContainerAudioTranscriptionBody(BaseModel):
    file: bytes
    "The audio file object (not file name) to transcribe, in one of these formats: mp3, wav, flac, ogg, and many other standard audio formats."
    model: OptionalNullable[str] = UNSET
    "Routes the request to a specific adapter."
    chunking_strategy: OptionalNullable[
        ContainerAudioTranscriptionBodyChunkingStrategy
    ] = UNSET
    'Controls how the audio is cut into chunks. When set to `\\"auto\\"`, the server first normalizes loudness and then uses voice activity detection (VAD) to choose boundaries. `server_vad` object can be provided to tweak VAD detection parameters manually. If unset, the audio is transcribed as a single block.'
    language: OptionalNullable[str] = UNSET
    "The language of the input audio. Supplying the input language in [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`) format will improve accuracy and latency."
    temperature: OptionalNullable[float] = UNSET
    "The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic."

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["model", "chunking_strategy", "language", "temperature"]
        nullable_fields = ["model", "chunking_strategy", "language", "temperature"]
        null_default_fields = []
        serialized = handler(self)
        m = {}
        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)
            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )
            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                k not in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val
        return m
