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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.evaluate_factual_consistency_response import EvaluateFactualConsistencyResponse
from .raw_client import AsyncRawFactualConsistencyClient, RawFactualConsistencyClient
from .types.evaluate_factual_consistency_request_model_parameters import (
    EvaluateFactualConsistencyRequestModelParameters,
)

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


class FactualConsistencyClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawFactualConsistencyClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawFactualConsistencyClient
        """
        return self._raw_client

    def evaluate(
        self,
        *,
        generated_text: str,
        source_texts: typing.Sequence[str],
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        model_parameters: typing.Optional[EvaluateFactualConsistencyRequestModelParameters] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EvaluateFactualConsistencyResponse:
        """
        Evaluate the factual consistency of a generated text (like a summary) against source documents.
        This determines how accurately the generated text reflects the information in the source documents,
        helping identify potential hallucinations or misrepresentations.

        Parameters
        ----------
        generated_text : str
            The generated text (e.g., summary or answer) to evaluate for factual consistency.

        source_texts : typing.Sequence[str]
            The source documents or text snippets against which to evaluate factual consistency.

        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.

        model_parameters : typing.Optional[EvaluateFactualConsistencyRequestModelParameters]
            The model parameters for the evaluation.

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

        Returns
        -------
        EvaluateFactualConsistencyResponse
            The factual consistency evaluation results.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.factual_consistency.evaluate(generated_text='generated_text', source_texts=['source_texts'], )
        """
        response = self._raw_client.evaluate(
            generated_text=generated_text,
            source_texts=source_texts,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            model_parameters=model_parameters,
            request_options=request_options,
        )
        return response.data


class AsyncFactualConsistencyClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawFactualConsistencyClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawFactualConsistencyClient
        """
        return self._raw_client

    async def evaluate(
        self,
        *,
        generated_text: str,
        source_texts: typing.Sequence[str],
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        model_parameters: typing.Optional[EvaluateFactualConsistencyRequestModelParameters] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> EvaluateFactualConsistencyResponse:
        """
        Evaluate the factual consistency of a generated text (like a summary) against source documents.
        This determines how accurately the generated text reflects the information in the source documents,
        helping identify potential hallucinations or misrepresentations.

        Parameters
        ----------
        generated_text : str
            The generated text (e.g., summary or answer) to evaluate for factual consistency.

        source_texts : typing.Sequence[str]
            The source documents or text snippets against which to evaluate factual consistency.

        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.

        model_parameters : typing.Optional[EvaluateFactualConsistencyRequestModelParameters]
            The model parameters for the evaluation.

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

        Returns
        -------
        EvaluateFactualConsistencyResponse
            The factual consistency evaluation results.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.factual_consistency.evaluate(generated_text='generated_text', source_texts=['source_texts'], )
        asyncio.run(main())
        """
        response = await self._raw_client.evaluate(
            generated_text=generated_text,
            source_texts=source_texts,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            model_parameters=model_parameters,
            request_options=request_options,
        )
        return response.data
