o
    
FiJ                     @   s   d dl Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZ e e jdZG dd dZG dd dZdS )    N   )AsyncClientWrapperSyncClientWrapper)RequestOptions)"ChatCompletionRequestMessageParams)ChatCompletionToolParams)StopConfigurationParams)ToolChoiceOptionParams)ChatCompletionChunk)CreateChatCompletionResponse)ReasoningEffort)SarvamModelIds   )AsyncRawChatClientRawChatClient.c                &   @     e Zd ZdefddZedefddZej	ddddddddddddddd	ej
e d
edeje deje deje deje dejd deje deje deje deje deje deje dejej
e  deje deje deje f"ddZej	dddddddddddddddd	ej
e d
edeje deje deje deje dejejd  deje deje deje deje deje deje dejej
e  deje deje def"ddZeeeeeeeeeeeeeddd	ej
e d
edeje deje deje deje deje deje deje deje deje deje deje dejej
e  deje deje dejeeje f f"d dZdS )!
ChatClientclient_wrapperc                C      t |d| _d S N)r   )r   _raw_clientselfr    r   a/home/aiteam/pcaa-dev/dashboard-backend/venv/lib/python3.10/site-packages/sarvamai/chat/client.py__init__      zChatClient.__init__returnc                 C      | j S )z
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawChatClient
        r   r   r   r   r   with_raw_response      	zChatClient.with_raw_response.temperaturetop_preasoning_effort
max_tokensstopnseedfrequency_penaltypresence_penaltywiki_groundingtoolstool_choicerequest_optionsmessagesmodelr$   r%   r&   r'   streamTr(   r)   r*   r+   r,   r-   r.   r/   r0   c                C      d S Nr   r   r1   r2   r$   r%   r&   r'   r3   r(   r)   r*   r+   r,   r-   r.   r/   r0   r   r   r   completions$      zChatClient.completionsr$   r%   r&   r'   r3   r(   r)   r*   r+   r,   r-   r.   r/   r0   Fc                C   r4   r5   r   r6   r   r   r   r7   :   r8   Nc                C   s   |du r;| j jdi d|d|d|d|d|d|ddd	|d
|	d|
d|d|d|d|d|d|S | j jdi d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d|d|}|jS )a~  
        Parameters
        ----------
        messages : typing.Sequence[ChatCompletionRequestMessageParams]
            A list of messages comprising the conversation so far.

        model : SarvamModelIds
            Model ID used to generate the response, like `sarvam-m`.

        temperature : typing.Optional[float]
            What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
            We generally recommend altering this or `top_p` but not both.

        top_p : typing.Optional[float]
            An alternative to sampling with temperature, called nucleus sampling,
            where the model considers the results of the tokens with top_p probability
            mass. So 0.1 means only the tokens comprising the top 10% probability mass
            are considered.

            We generally recommend altering this or `temperature` but not both.

        reasoning_effort : typing.Optional[ReasoningEffort]
            The effort to use for reasoning

        max_tokens : typing.Optional[int]
            The maximum number of tokens that can be generated in the chat completion.

        stream : typing.Optional[bool]
            If set to true, the model response data will be streamed to the client
            as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
            When true, returns an Iterator[ChatCompletionChunk] instead of CreateChatCompletionResponse.

        stop : typing.Optional[StopConfigurationParams]

        n : typing.Optional[int]
            How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs.

        seed : typing.Optional[int]
            This feature is in Beta.
            If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result.
            Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.

        frequency_penalty : typing.Optional[float]
            Number between -2.0 and 2.0. Positive values penalize new tokens based on
            their existing frequency in the text so far, decreasing the model's
            likelihood to repeat the same line verbatim.

        presence_penalty : typing.Optional[float]
            Number between -2.0 and 2.0. Positive values penalize new tokens based on
            whether they appear in the text so far, increasing the model's likelihood
            to talk about new topics.

        wiki_grounding : typing.Optional[bool]
            If set to true, the model response will be wiki grounded.

        tools : typing.Optional[typing.Sequence[ChatCompletionToolParams]]
            A list of tools the model may call. Currently, only functions are supported as a tool.

        tool_choice : typing.Optional[ToolChoiceOptionParams]
            Controls which (if any) tool is called by the model.

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

        Returns
        -------
        CreateChatCompletionResponse or Iterator[ChatCompletionChunk]
            When stream=False (default): CreateChatCompletionResponse.
            When stream=True: Iterator yielding ChatCompletionChunk objects.

        Examples
        --------
        from sarvamai import SarvamAI

        client = SarvamAI(
            api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
        )

        # Non-streaming
        response = client.chat.completions(
            messages=[{"role": "user", "content": "Hello"}],
            model="sarvam-m",
        )

        # Streaming
        for chunk in client.chat.completions(
            messages=[{"role": "user", "content": "Hello"}],
            model="sarvam-m",
            stream=True,
        ):
            print(chunk)
        Tr1   r2   r$   r%   r&   r'   r3   r(   r)   r*   r+   r,   r-   r.   r/   r0   Nr   r   r7   datar   r1   r2   r$   r%   r&   r'   r3   r(   r)   r*   r+   r,   r-   r.   r/   r0   	_responser   r   r   r7   P   s   p	
	
)__name__
__module____qualname__r   r   propertyr   r!   typingoverloadSequencer   r   Optionalfloatr   intLiteralr   boolr   r	   r   Iteratorr
   r7   r   OMITUnionr   r   r   r   r      0   
	
	
	
r   c                &   @   r   )!AsyncChatClientr   c                C   r   r   )r   r   r   r   r   r   r      r   zAsyncChatClient.__init__r   c                 C   r   )z
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawChatClient
        r   r    r   r   r   r!      r"   z!AsyncChatClient.with_raw_response.r#   r1   r2   r$   r%   r&   r'   r3   Tr(   r)   r*   r+   r,   r-   r.   r/   r0   c                      d S r5   r   r6   r   r   r   r7         zAsyncChatClient.completionsr9   Fc                   rO   r5   r   r6   r   r   r   r7     rP   Nc                   s   |du r?| j jdi d|d|d|d|d|d|ddd	|d
|	d|
d|d|d|d|d|d|I dH S | j jdi d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d|d|I dH }|jS )a)  
        Parameters
        ----------
        messages : typing.Sequence[ChatCompletionRequestMessageParams]
            A list of messages comprising the conversation so far.

        model : SarvamModelIds
            Model ID used to generate the response, like `sarvam-m`.

        temperature : typing.Optional[float]
            What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
            We generally recommend altering this or `top_p` but not both.

        top_p : typing.Optional[float]
            An alternative to sampling with temperature, called nucleus sampling,
            where the model considers the results of the tokens with top_p probability
            mass. So 0.1 means only the tokens comprising the top 10% probability mass
            are considered.

            We generally recommend altering this or `temperature` but not both.

        reasoning_effort : typing.Optional[ReasoningEffort]
            The effort to use for reasoning

        max_tokens : typing.Optional[int]
            The maximum number of tokens that can be generated in the chat completion.

        stream : typing.Optional[bool]
            If set to true, the model response data will be streamed to the client
            as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
            When true, returns an AsyncIterator[ChatCompletionChunk] instead of CreateChatCompletionResponse.

        stop : typing.Optional[StopConfigurationParams]

        n : typing.Optional[int]
            How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs.

        seed : typing.Optional[int]
            This feature is in Beta.
            If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result.
            Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.

        frequency_penalty : typing.Optional[float]
            Number between -2.0 and 2.0. Positive values penalize new tokens based on
            their existing frequency in the text so far, decreasing the model's
            likelihood to repeat the same line verbatim.

        presence_penalty : typing.Optional[float]
            Number between -2.0 and 2.0. Positive values penalize new tokens based on
            whether they appear in the text so far, increasing the model's likelihood
            to talk about new topics.

        wiki_grounding : typing.Optional[bool]
            If set to true, the model response will be wiki grounded.

        tools : typing.Optional[typing.Sequence[ChatCompletionToolParams]]
            A list of tools the model may call. Currently, only functions are supported as a tool.

        tool_choice : typing.Optional[ToolChoiceOptionParams]
            Controls which (if any) tool is called by the model.

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

        Returns
        -------
        CreateChatCompletionResponse or AsyncIterator[ChatCompletionChunk]
            When stream=False (default): CreateChatCompletionResponse.
            When stream=True: AsyncIterator yielding ChatCompletionChunk objects.

        Examples
        --------
        import asyncio
        from sarvamai import AsyncSarvamAI

        client = AsyncSarvamAI(
            api_subscription_key="YOUR_API_SUBSCRIPTION_KEY",
        )

        async def main() -> None:
            # Non-streaming
            response = await client.chat.completions(
                messages=[{"role": "user", "content": "Hello"}],
                model="sarvam-m",
            )

            # Streaming
            async for chunk in client.chat.completions(
                messages=[{"role": "user", "content": "Hello"}],
                model="sarvam-m",
                stream=True,
            ):
                print(chunk)

        asyncio.run(main())
        Tr1   r2   r$   r%   r&   r'   r3   r(   r)   r*   r+   r,   r-   r.   r/   r0   Nr   r:   r<   r   r   r   r7   $  s   t	

	

)r>   r?   r@   r   r   rA   r   r!   rB   rC   rD   r   r   rE   rF   r   rG   rH   r   rI   r   r	   r   AsyncIteratorr
   r7   r   rK   rL   r   r   r   r   rN      rM   rN   )rB   core.client_wrapperr   r   core.request_optionsr   (requests.chat_completion_request_messager   requests.chat_completion_toolr   requests.stop_configurationr   requests.tool_choice_optionr	   types.chat_completion_chunkr
   %types.create_chat_completion_responser   types.reasoning_effortr   types.sarvam_model_idsr   
raw_clientr   r   castAnyrK   r   rN   r   r   r   r   <module>   s     U