# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import List, Union, Optional
from datetime import datetime
from typing_extensions import Literal, TypeAlias

from pydantic import Field as FieldInfo

from .snippet import Snippet
from .._models import BaseModel
from .chat_response import ChatResponse

__all__ = [
    "SessionChatResponse",
    "ChunkChatResponse",
    "ChunkChatResponseChoice",
    "ChunkChatResponseChoiceDelta",
    "ChunkChatResponseChoiceDeltaContentUnionMember2",
    "ChunkChatResponseChoiceDeltaContentUnionMember2Content",
    "ChunkChatResponseChoiceDeltaContentUnionMember2ContentModel",
    "ChunkChatResponseChoiceDeltaContentUnionMember2ContentModelImageURL",
    "ChunkChatResponseChoiceLogprobs",
    "ChunkChatResponseChoiceLogprobsContent",
    "ChunkChatResponseChoiceLogprobsContentTopLogprob",
    "ChunkChatResponseDoc",
    "ChunkChatResponseDocOwner",
    "ChunkChatResponseUsage",
]


class ChunkChatResponseChoiceDeltaContentUnionMember2Content(BaseModel):
    text: str

    type: Optional[Literal["text"]] = None


class ChunkChatResponseChoiceDeltaContentUnionMember2ContentModelImageURL(BaseModel):
    url: str

    detail: Optional[Literal["low", "high", "auto"]] = None


class ChunkChatResponseChoiceDeltaContentUnionMember2ContentModel(BaseModel):
    image_url: ChunkChatResponseChoiceDeltaContentUnionMember2ContentModelImageURL
    """The image URL"""

    type: Optional[Literal["image_url"]] = None


ChunkChatResponseChoiceDeltaContentUnionMember2: TypeAlias = Union[
    ChunkChatResponseChoiceDeltaContentUnionMember2Content, ChunkChatResponseChoiceDeltaContentUnionMember2ContentModel
]


class ChunkChatResponseChoiceDelta(BaseModel):
    content: Union[str, List[str], List[ChunkChatResponseChoiceDeltaContentUnionMember2]]

    role: Literal["user", "assistant", "system", "function", "function_response", "function_call", "auto"]

    continue_: Optional[bool] = FieldInfo(alias="continue", default=None)

    name: Optional[str] = None


class ChunkChatResponseChoiceLogprobsContentTopLogprob(BaseModel):
    token: str

    logprob: float

    bytes: Optional[List[int]] = None


class ChunkChatResponseChoiceLogprobsContent(BaseModel):
    token: str

    logprob: float

    top_logprobs: List[ChunkChatResponseChoiceLogprobsContentTopLogprob]

    bytes: Optional[List[int]] = None


class ChunkChatResponseChoiceLogprobs(BaseModel):
    content: Optional[List[ChunkChatResponseChoiceLogprobsContent]] = None


class ChunkChatResponseChoice(BaseModel):
    delta: ChunkChatResponseChoiceDelta
    """The message generated by the model"""

    index: int

    finish_reason: Optional[Literal["stop", "length", "content_filter", "tool_calls"]] = None

    logprobs: Optional[ChunkChatResponseChoiceLogprobs] = None


class ChunkChatResponseDocOwner(BaseModel):
    id: str

    role: Literal["user", "agent"]


class ChunkChatResponseDoc(BaseModel):
    id: str

    owner: ChunkChatResponseDocOwner

    snippet: Snippet

    distance: Optional[float] = None

    metadata: Optional[object] = None

    title: Optional[str] = None


class ChunkChatResponseUsage(BaseModel):
    completion_tokens: Optional[int] = None

    prompt_tokens: Optional[int] = None

    total_tokens: Optional[int] = None


class ChunkChatResponse(BaseModel):
    id: str

    choices: List[ChunkChatResponseChoice]

    created_at: datetime

    docs: Optional[List[ChunkChatResponseDoc]] = None

    jobs: Optional[List[str]] = None

    usage: Optional[ChunkChatResponseUsage] = None
    """Usage statistics for the completion request"""


SessionChatResponse: TypeAlias = Union[ChunkChatResponse, ChatResponse]
