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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.pagination import AsyncPager, SyncPager
from ..core.request_options import RequestOptions
from ..types.chat import Chat
from ..types.chat_parameters import ChatParameters
from ..types.generation_parameters import GenerationParameters
from ..types.list_chat_turns_response import ListChatTurnsResponse
from ..types.search_corpora_parameters import SearchCorporaParameters
from ..types.turn import Turn
from .raw_client import AsyncRawChatsClient, RawChatsClient
from .types.chats_create_response import ChatsCreateResponse
from .types.chats_create_stream_response import ChatsCreateStreamResponse
from .types.chats_create_turns_response import ChatsCreateTurnsResponse
from .types.chats_create_turns_stream_response import ChatsCreateTurnsStreamResponse

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class ChatsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawChatsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawChatsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawChatsClient
        """
        return self._raw_client

    def list(
        self,
        *,
        limit: typing.Optional[int] = None,
        page_key: typing.Optional[str] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[Chat]:
        """
        Retrieve a list of previous chats in the Vectara account.

        Parameters
        ----------
        limit : typing.Optional[int]
            The maximum number of results to return in the list.

        page_key : typing.Optional[str]
            Used to retrieve the next page of chats after the limit has been reached.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        SyncPager[Chat]
            List of chats.

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        response = client.chats.list()
        for item in response:
            yield item
        # alternatively, you can paginate page-by-page
        for page in response.iter_pages():
            yield page
        """
        return self._raw_client.list(
            limit=limit,
            page_key=page_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )

    def create_stream(
        self,
        *,
        query: str,
        search: SearchCorporaParameters,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        generation: typing.Optional[GenerationParameters] = OMIT,
        chat: typing.Optional[ChatParameters] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        intelligent_query_rewriting: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[ChatsCreateStreamResponse]:
        """
        Create a chat while specifying the default retrieval parameters used by the prompt.

        Parameters
        ----------
        query : str
            The chat message or question.

        search : SearchCorporaParameters

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        generation : typing.Optional[GenerationParameters]

        chat : typing.Optional[ChatParameters]

        save_history : typing.Optional[bool]
            Indicates whether to save the chat in both the chat and query history. This overrides `chat.store`.

        intelligent_query_rewriting : typing.Optional[bool]
            [Tech Preview] Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to extract metadata filter and rewrite the query to improve search results. Read [here](https://docs.vectara.com/docs/search-and-retrieval/intelligent-query-rewriting) for more details.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.Iterator[ChatsCreateStreamResponse]


        Examples
        --------
        from vectara import (
            ChatParameters,
            CitationParameters,
            ContextConfiguration,
            CustomerSpecificReranker,
            GenerationParameters,
            KeyedSearchCorpus,
            SearchCorporaParameters,
            Vectara,
        )

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        response = client.chats.create_stream(
            query="What is a hallucination?",
            search=SearchCorporaParameters(
                corpora=[
                    KeyedSearchCorpus(
                        corpus_key="corpus_key",
                        metadata_filter="",
                        lexical_interpolation=0.005,
                    )
                ],
                context_configuration=ContextConfiguration(
                    sentences_before=2,
                    sentences_after=2,
                ),
                reranker=CustomerSpecificReranker(
                    reranker_id="rnk_272725719",
                ),
            ),
            generation=GenerationParameters(
                response_language="eng",
                citations=CitationParameters(
                    style="none",
                ),
                enable_factual_consistency_score=True,
            ),
            chat=ChatParameters(
                store=True,
            ),
        )
        for chunk in response:
            yield chunk
        """
        with self._raw_client.create_stream(
            query=query,
            search=search,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            generation=generation,
            chat=chat,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_options=request_options,
        ) as r:
            yield from r.data

    def create(
        self,
        *,
        query: str,
        search: SearchCorporaParameters,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        generation: typing.Optional[GenerationParameters] = OMIT,
        chat: typing.Optional[ChatParameters] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        intelligent_query_rewriting: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChatsCreateResponse:
        """
        Create a chat while specifying the default retrieval parameters used by the prompt.

        Parameters
        ----------
        query : str
            The chat message or question.

        search : SearchCorporaParameters

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        generation : typing.Optional[GenerationParameters]

        chat : typing.Optional[ChatParameters]

        save_history : typing.Optional[bool]
            Indicates whether to save the chat in both the chat and query history. This overrides `chat.store`.

        intelligent_query_rewriting : typing.Optional[bool]
            [Tech Preview] Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to extract metadata filter and rewrite the query to improve search results. Read [here](https://docs.vectara.com/docs/search-and-retrieval/intelligent-query-rewriting) for more details.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ChatsCreateResponse


        Examples
        --------
        from vectara import (
            ChatParameters,
            CitationParameters,
            ContextConfiguration,
            CustomerSpecificReranker,
            GenerationParameters,
            KeyedSearchCorpus,
            SearchCorporaParameters,
            Vectara,
        )

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.chats.create(
            query="What is a hallucination?",
            search=SearchCorporaParameters(
                corpora=[
                    KeyedSearchCorpus(
                        corpus_key="corpus_key",
                        metadata_filter="",
                        lexical_interpolation=0.005,
                    )
                ],
                context_configuration=ContextConfiguration(
                    sentences_before=2,
                    sentences_after=2,
                ),
                reranker=CustomerSpecificReranker(
                    reranker_id="rnk_272725719",
                ),
            ),
            generation=GenerationParameters(
                response_language="eng",
                enable_factual_consistency_score=True,
                citations=CitationParameters(
                    style="none",
                ),
            ),
            chat=ChatParameters(
                store=True,
            ),
        )
        """
        _response = self._raw_client.create(
            query=query,
            search=search,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            generation=generation,
            chat=chat,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_options=request_options,
        )
        return _response.data

    def get(
        self,
        chat_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Chat:
        """
        Get a chat summary to view what started the chat, but not subsequent turns.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Chat
            A chat.

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.chats.get(
            chat_id="chat_id",
        )
        """
        _response = self._raw_client.get(
            chat_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    def delete(
        self,
        chat_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Delete a chat and any turns it contains permanently.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.chats.delete(
            chat_id="chat_id",
        )
        """
        _response = self._raw_client.delete(
            chat_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    def list_turns(
        self,
        chat_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListChatTurnsResponse:
        """
        List all turns in a chat to see all message and response pairs that make up the dialog.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ListChatTurnsResponse
            List of turns.

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.chats.list_turns(
            chat_id="cht_1234567890",
        )
        """
        _response = self._raw_client.list_turns(
            chat_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    def create_turns_stream(
        self,
        chat_id: str,
        *,
        query: str,
        search: SearchCorporaParameters,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        generation: typing.Optional[GenerationParameters] = OMIT,
        chat: typing.Optional[ChatParameters] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        intelligent_query_rewriting: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Iterator[ChatsCreateTurnsStreamResponse]:
        """
        Create a new turn in the chat. Each conversation has a series of `turn` objects, which are the sequence of message and response pairs that make up the dialog.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        query : str
            The chat message or question.

        search : SearchCorporaParameters

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        generation : typing.Optional[GenerationParameters]

        chat : typing.Optional[ChatParameters]

        save_history : typing.Optional[bool]
            Indicates whether to save the chat in both the chat and query history. This overrides `chat.store`.

        intelligent_query_rewriting : typing.Optional[bool]
            [Tech Preview] Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to extract metadata filter and rewrite the query to improve search results. Read [here](https://docs.vectara.com/docs/search-and-retrieval/intelligent-query-rewriting) for more details.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.Iterator[ChatsCreateTurnsStreamResponse]


        Examples
        --------
        from vectara import SearchCorporaParameters, Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        response = client.chats.create_turns_stream(
            chat_id="chat_id",
            query="What are the carbon reduction efforts by EU banks in 2023?",
            search=SearchCorporaParameters(),
        )
        for chunk in response:
            yield chunk
        """
        with self._raw_client.create_turns_stream(
            chat_id,
            query=query,
            search=search,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            generation=generation,
            chat=chat,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_options=request_options,
        ) as r:
            yield from r.data

    def create_turns(
        self,
        chat_id: str,
        *,
        query: str,
        search: SearchCorporaParameters,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        generation: typing.Optional[GenerationParameters] = OMIT,
        chat: typing.Optional[ChatParameters] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        intelligent_query_rewriting: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChatsCreateTurnsResponse:
        """
        Create a new turn in the chat. Each conversation has a series of `turn` objects, which are the sequence of message and response pairs that make up the dialog.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        query : str
            The chat message or question.

        search : SearchCorporaParameters

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        generation : typing.Optional[GenerationParameters]

        chat : typing.Optional[ChatParameters]

        save_history : typing.Optional[bool]
            Indicates whether to save the chat in both the chat and query history. This overrides `chat.store`.

        intelligent_query_rewriting : typing.Optional[bool]
            [Tech Preview] Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to extract metadata filter and rewrite the query to improve search results. Read [here](https://docs.vectara.com/docs/search-and-retrieval/intelligent-query-rewriting) for more details.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ChatsCreateTurnsResponse


        Examples
        --------
        from vectara import SearchCorporaParameters, Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.chats.create_turns(
            chat_id="chat_id",
            query="What are the carbon reduction efforts by EU banks in 2023?",
            search=SearchCorporaParameters(),
        )
        """
        _response = self._raw_client.create_turns(
            chat_id,
            query=query,
            search=search,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            generation=generation,
            chat=chat,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_options=request_options,
        )
        return _response.data

    def get_turn(
        self,
        chat_id: str,
        turn_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Turn:
        """
        Get a specific turn from a chat, which is a message and response pair from the conversation.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        turn_id : str
            The ID of the turn.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Turn
            The turn.

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.chats.get_turn(
            chat_id="chat_id",
            turn_id="turn_id",
        )
        """
        _response = self._raw_client.get_turn(
            chat_id,
            turn_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    def delete_turn(
        self,
        chat_id: str,
        turn_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Delete a turn from a chat. This will delete all subsequent turns in the chat.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        turn_id : str
            The ID of the turn.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.chats.delete_turn(
            chat_id="chat_id",
            turn_id="turn_id",
        )
        """
        _response = self._raw_client.delete_turn(
            chat_id,
            turn_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    def update_turn(
        self,
        chat_id: str,
        turn_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        enabled: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Turn:
        """
        Update a turn; used to disable or enable a chat.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        turn_id : str
            The ID of the turn.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        enabled : typing.Optional[bool]
            Indicates whether to disable a turn. It will disable this turn and all subsequent turns. Enabling a turn is not implemented.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Turn
            Successfully modified the turn.

        Examples
        --------
        from vectara import Vectara

        client = Vectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )
        client.chats.update_turn(
            chat_id="cht_1234567890",
            turn_id="trn_987654321",
        )
        """
        _response = self._raw_client.update_turn(
            chat_id,
            turn_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            enabled=enabled,
            request_options=request_options,
        )
        return _response.data


class AsyncChatsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawChatsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawChatsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawChatsClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        limit: typing.Optional[int] = None,
        page_key: typing.Optional[str] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[Chat]:
        """
        Retrieve a list of previous chats in the Vectara account.

        Parameters
        ----------
        limit : typing.Optional[int]
            The maximum number of results to return in the list.

        page_key : typing.Optional[str]
            Used to retrieve the next page of chats after the limit has been reached.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncPager[Chat]
            List of chats.

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            response = await client.chats.list()
            async for item in response:
                yield item

            # alternatively, you can paginate page-by-page
            async for page in response.iter_pages():
                yield page


        asyncio.run(main())
        """
        return await self._raw_client.list(
            limit=limit,
            page_key=page_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )

    async def create_stream(
        self,
        *,
        query: str,
        search: SearchCorporaParameters,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        generation: typing.Optional[GenerationParameters] = OMIT,
        chat: typing.Optional[ChatParameters] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        intelligent_query_rewriting: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[ChatsCreateStreamResponse]:
        """
        Create a chat while specifying the default retrieval parameters used by the prompt.

        Parameters
        ----------
        query : str
            The chat message or question.

        search : SearchCorporaParameters

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        generation : typing.Optional[GenerationParameters]

        chat : typing.Optional[ChatParameters]

        save_history : typing.Optional[bool]
            Indicates whether to save the chat in both the chat and query history. This overrides `chat.store`.

        intelligent_query_rewriting : typing.Optional[bool]
            [Tech Preview] Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to extract metadata filter and rewrite the query to improve search results. Read [here](https://docs.vectara.com/docs/search-and-retrieval/intelligent-query-rewriting) for more details.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.AsyncIterator[ChatsCreateStreamResponse]


        Examples
        --------
        import asyncio

        from vectara import (
            AsyncVectara,
            ChatParameters,
            CitationParameters,
            ContextConfiguration,
            CustomerSpecificReranker,
            GenerationParameters,
            KeyedSearchCorpus,
            SearchCorporaParameters,
        )

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            response = await client.chats.create_stream(
                query="What is a hallucination?",
                search=SearchCorporaParameters(
                    corpora=[
                        KeyedSearchCorpus(
                            corpus_key="corpus_key",
                            metadata_filter="",
                            lexical_interpolation=0.005,
                        )
                    ],
                    context_configuration=ContextConfiguration(
                        sentences_before=2,
                        sentences_after=2,
                    ),
                    reranker=CustomerSpecificReranker(
                        reranker_id="rnk_272725719",
                    ),
                ),
                generation=GenerationParameters(
                    response_language="eng",
                    citations=CitationParameters(
                        style="none",
                    ),
                    enable_factual_consistency_score=True,
                ),
                chat=ChatParameters(
                    store=True,
                ),
            )
            async for chunk in response:
                yield chunk


        asyncio.run(main())
        """
        async with self._raw_client.create_stream(
            query=query,
            search=search,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            generation=generation,
            chat=chat,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_options=request_options,
        ) as r:
            async for _chunk in r.data:
                yield _chunk

    async def create(
        self,
        *,
        query: str,
        search: SearchCorporaParameters,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        generation: typing.Optional[GenerationParameters] = OMIT,
        chat: typing.Optional[ChatParameters] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        intelligent_query_rewriting: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChatsCreateResponse:
        """
        Create a chat while specifying the default retrieval parameters used by the prompt.

        Parameters
        ----------
        query : str
            The chat message or question.

        search : SearchCorporaParameters

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        generation : typing.Optional[GenerationParameters]

        chat : typing.Optional[ChatParameters]

        save_history : typing.Optional[bool]
            Indicates whether to save the chat in both the chat and query history. This overrides `chat.store`.

        intelligent_query_rewriting : typing.Optional[bool]
            [Tech Preview] Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to extract metadata filter and rewrite the query to improve search results. Read [here](https://docs.vectara.com/docs/search-and-retrieval/intelligent-query-rewriting) for more details.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ChatsCreateResponse


        Examples
        --------
        import asyncio

        from vectara import (
            AsyncVectara,
            ChatParameters,
            CitationParameters,
            ContextConfiguration,
            CustomerSpecificReranker,
            GenerationParameters,
            KeyedSearchCorpus,
            SearchCorporaParameters,
        )

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.chats.create(
                query="What is a hallucination?",
                search=SearchCorporaParameters(
                    corpora=[
                        KeyedSearchCorpus(
                            corpus_key="corpus_key",
                            metadata_filter="",
                            lexical_interpolation=0.005,
                        )
                    ],
                    context_configuration=ContextConfiguration(
                        sentences_before=2,
                        sentences_after=2,
                    ),
                    reranker=CustomerSpecificReranker(
                        reranker_id="rnk_272725719",
                    ),
                ),
                generation=GenerationParameters(
                    response_language="eng",
                    enable_factual_consistency_score=True,
                    citations=CitationParameters(
                        style="none",
                    ),
                ),
                chat=ChatParameters(
                    store=True,
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            query=query,
            search=search,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            generation=generation,
            chat=chat,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self,
        chat_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Chat:
        """
        Get a chat summary to view what started the chat, but not subsequent turns.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Chat
            A chat.

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.chats.get(
                chat_id="chat_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get(
            chat_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    async def delete(
        self,
        chat_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Delete a chat and any turns it contains permanently.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.chats.delete(
                chat_id="chat_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete(
            chat_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    async def list_turns(
        self,
        chat_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListChatTurnsResponse:
        """
        List all turns in a chat to see all message and response pairs that make up the dialog.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ListChatTurnsResponse
            List of turns.

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.chats.list_turns(
                chat_id="cht_1234567890",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_turns(
            chat_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    async def create_turns_stream(
        self,
        chat_id: str,
        *,
        query: str,
        search: SearchCorporaParameters,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        generation: typing.Optional[GenerationParameters] = OMIT,
        chat: typing.Optional[ChatParameters] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        intelligent_query_rewriting: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.AsyncIterator[ChatsCreateTurnsStreamResponse]:
        """
        Create a new turn in the chat. Each conversation has a series of `turn` objects, which are the sequence of message and response pairs that make up the dialog.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        query : str
            The chat message or question.

        search : SearchCorporaParameters

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        generation : typing.Optional[GenerationParameters]

        chat : typing.Optional[ChatParameters]

        save_history : typing.Optional[bool]
            Indicates whether to save the chat in both the chat and query history. This overrides `chat.store`.

        intelligent_query_rewriting : typing.Optional[bool]
            [Tech Preview] Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to extract metadata filter and rewrite the query to improve search results. Read [here](https://docs.vectara.com/docs/search-and-retrieval/intelligent-query-rewriting) for more details.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.AsyncIterator[ChatsCreateTurnsStreamResponse]


        Examples
        --------
        import asyncio

        from vectara import AsyncVectara, SearchCorporaParameters

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            response = await client.chats.create_turns_stream(
                chat_id="chat_id",
                query="What are the carbon reduction efforts by EU banks in 2023?",
                search=SearchCorporaParameters(),
            )
            async for chunk in response:
                yield chunk


        asyncio.run(main())
        """
        async with self._raw_client.create_turns_stream(
            chat_id,
            query=query,
            search=search,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            generation=generation,
            chat=chat,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_options=request_options,
        ) as r:
            async for _chunk in r.data:
                yield _chunk

    async def create_turns(
        self,
        chat_id: str,
        *,
        query: str,
        search: SearchCorporaParameters,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        generation: typing.Optional[GenerationParameters] = OMIT,
        chat: typing.Optional[ChatParameters] = OMIT,
        save_history: typing.Optional[bool] = OMIT,
        intelligent_query_rewriting: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChatsCreateTurnsResponse:
        """
        Create a new turn in the chat. Each conversation has a series of `turn` objects, which are the sequence of message and response pairs that make up the dialog.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        query : str
            The chat message or question.

        search : SearchCorporaParameters

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        generation : typing.Optional[GenerationParameters]

        chat : typing.Optional[ChatParameters]

        save_history : typing.Optional[bool]
            Indicates whether to save the chat in both the chat and query history. This overrides `chat.store`.

        intelligent_query_rewriting : typing.Optional[bool]
            [Tech Preview] Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to extract metadata filter and rewrite the query to improve search results. Read [here](https://docs.vectara.com/docs/search-and-retrieval/intelligent-query-rewriting) for more details.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ChatsCreateTurnsResponse


        Examples
        --------
        import asyncio

        from vectara import AsyncVectara, SearchCorporaParameters

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.chats.create_turns(
                chat_id="chat_id",
                query="What are the carbon reduction efforts by EU banks in 2023?",
                search=SearchCorporaParameters(),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_turns(
            chat_id,
            query=query,
            search=search,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            generation=generation,
            chat=chat,
            save_history=save_history,
            intelligent_query_rewriting=intelligent_query_rewriting,
            request_options=request_options,
        )
        return _response.data

    async def get_turn(
        self,
        chat_id: str,
        turn_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Turn:
        """
        Get a specific turn from a chat, which is a message and response pair from the conversation.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        turn_id : str
            The ID of the turn.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Turn
            The turn.

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.chats.get_turn(
                chat_id="chat_id",
                turn_id="turn_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_turn(
            chat_id,
            turn_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    async def delete_turn(
        self,
        chat_id: str,
        turn_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Delete a turn from a chat. This will delete all subsequent turns in the chat.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        turn_id : str
            The ID of the turn.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.chats.delete_turn(
                chat_id="chat_id",
                turn_id="turn_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_turn(
            chat_id,
            turn_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return _response.data

    async def update_turn(
        self,
        chat_id: str,
        turn_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        enabled: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Turn:
        """
        Update a turn; used to disable or enable a chat.

        Parameters
        ----------
        chat_id : str
            The ID of the chat.

        turn_id : str
            The ID of the turn.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

        enabled : typing.Optional[bool]
            Indicates whether to disable a turn. It will disable this turn and all subsequent turns. Enabling a turn is not implemented.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        Turn
            Successfully modified the turn.

        Examples
        --------
        import asyncio

        from vectara import AsyncVectara

        client = AsyncVectara(
            api_key="YOUR_API_KEY",
            client_id="YOUR_CLIENT_ID",
            client_secret="YOUR_CLIENT_SECRET",
        )


        async def main() -> None:
            await client.chats.update_turn(
                chat_id="cht_1234567890",
                turn_id="trn_987654321",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_turn(
            chat_id,
            turn_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            enabled=enabled,
            request_options=request_options,
        )
        return _response.data
