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

import builtins
from typing import TYPE_CHECKING, Dict, List, Union, Optional
from typing_extensions import Literal, TypeAlias

from pydantic import Field as FieldInfo

from ..._models import BaseModel

__all__ = [
    "NamespaceChatCompletionsResponse",
    "Choice",
    "ChoiceMessage",
    "ChoiceMessageContentUnionMember1",
    "ChoiceMessageContentUnionMember1UnionMember0",
    "ChoiceMessageContentUnionMember1UnionMember1",
    "ChoiceMessageContentUnionMember1UnionMember1ImageURL",
    "Chunk",
    "ChunkItem",
    "ChunkScoringDetails",
    "Error",
]


class ChoiceMessageContentUnionMember1UnionMember0(BaseModel):
    text: str

    type: Literal["text"]


class ChoiceMessageContentUnionMember1UnionMember1ImageURL(BaseModel):
    url: str


class ChoiceMessageContentUnionMember1UnionMember1(BaseModel):
    image_url: ChoiceMessageContentUnionMember1UnionMember1ImageURL

    type: Literal["image_url"]


ChoiceMessageContentUnionMember1: TypeAlias = Union[
    ChoiceMessageContentUnionMember1UnionMember0, ChoiceMessageContentUnionMember1UnionMember1
]


class ChoiceMessage(BaseModel):
    content: Union[str, List[ChoiceMessageContentUnionMember1], None] = None

    role: Literal["system", "developer", "user", "assistant", "tool"]

    if TYPE_CHECKING:
        # Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
        # value to this field, so for compatibility we avoid doing it at runtime.
        __pydantic_extra__: Dict[str, object] = FieldInfo(init=False)  # pyright: ignore[reportIncompatibleVariableOverride]

        # Stub to indicate that arbitrary properties are accepted.
        # To access properties that are not valid identifiers you can use `getattr`, e.g.
        # `getattr(obj, '$type')`
        def __getattr__(self, attr: str) -> object: ...
    else:
        __pydantic_extra__: Dict[str, object]


class Choice(BaseModel):
    message: ChoiceMessage

    index: Optional[int] = None


class ChunkItem(BaseModel):
    key: str

    metadata: Optional[Dict[str, object]] = None

    timestamp: Optional[float] = None


class ChunkScoringDetails(BaseModel):
    fusion_method: Optional[Literal["rrf", "max"]] = None

    keyword_rank: Optional[float] = None

    keyword_score: Optional[float] = None

    reranking_score: Optional[float] = None

    vector_rank: Optional[float] = None

    vector_score: Optional[float] = None


class Chunk(BaseModel):
    id: str

    instance_id: str

    score: float

    text: str

    type: str

    item: Optional[ChunkItem] = None

    scoring_details: Optional[ChunkScoringDetails] = None


class Error(BaseModel):
    instance_id: str

    message: str


class NamespaceChatCompletionsResponse(BaseModel):
    choices: List[Choice]

    chunks: List[Chunk]

    id: Optional[str] = None

    errors: Optional[List[Error]] = None

    model: Optional[str] = None

    object: Optional[str] = None

    if TYPE_CHECKING:
        # Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
        # value to this field, so for compatibility we avoid doing it at runtime.
        __pydantic_extra__: Dict[str, builtins.object] = FieldInfo(init=False)  # pyright: ignore[reportIncompatibleVariableOverride]

        # Stub to indicate that arbitrary properties are accepted.
        # To access properties that are not valid identifiers you can use `getattr`, e.g.
        # `getattr(obj, '$type')`
        def __getattr__(self, attr: str) -> builtins.object: ...
    else:
        __pydantic_extra__: Dict[str, builtins.object]
