# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

from ...core.datetime_utils import serialize_datetime
from ...core.pydantic_utilities import pydantic_v1
from .chat_completion_chunk_choice import ChatCompletionChunkChoice


class ChatCompletionChunk(pydantic_v1.BaseModel):
    """
    Represents a single chunk of a streaming chat completion response.

    This object's schema is compatible with OpenAI's Chat Completion API.
    """

    choices: typing.List[ChatCompletionChunkChoice] = pydantic_v1.Field()
    """
    A list of chat completion choices.Can be more than one if n is greater than 1.
    """

    created: int = pydantic_v1.Field()
    """
    The Unix timestamp (in seconds) of whenthe chat completion was created. Each chunk has the same timestamp.
    """

    id: str = pydantic_v1.Field()
    """
    A unique identifier for the entire chat completion request.Each chunk in the stream has the same ID.
    """

    model: str = pydantic_v1.Field()
    """
    The model used for the chat completion.
    """

    object: typing.Optional[str] = pydantic_v1.Field(default=None)
    """
    The object type, which is always `chat.completion.chunk`.
    """

    def json(self, **kwargs: typing.Any) -> str:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().json(**kwargs_with_defaults)

    def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().dict(**kwargs_with_defaults)

    class Config:
        frozen = True
        smart_union = True
        extra = pydantic_v1.Extra.allow
        json_encoders = {dt.datetime: serialize_datetime}
