# This file was added to support streaming chat completions (SSE).

import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from .choice_delta_tool_call import ChoiceDeltaToolCall
from .role import Role


class ChoiceDelta(UniversalBaseModel):
    """Delta content in a streaming chat completion chunk."""

    content: typing.Optional[str] = pydantic.Field(default=None)
    """
    The contents of the chunk message.
    """

    refusal: typing.Optional[str] = None

    reasoning_content: typing.Optional[str] = pydantic.Field(default=None)
    """
    The contents of the reasoning message chunk.
    """

    role: typing.Optional[Role] = pydantic.Field(default=None)
    """
    The role of the author of this message (only present in first chunk).
    """

    function_call: typing.Optional[typing.Dict[str, typing.Any]] = None

    tool_calls: typing.Optional[typing.List[ChoiceDeltaToolCall]] = pydantic.Field(default=None)
    """
    Tool calls generated by the model in this chunk.
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
