o
    lWiV                     @   sF  d dl Z d dlmZ ddlmZ ddlmZm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 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. e /e j0dZ1G dd dZ2G dd dZ3dS )    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)jsonable_encoder)RequestOptions)'convert_and_respect_annotation_metadata)construct_type)UnprocessableEntityError)AgentFailureResponseExample)AgentSuccessfulResponseExample)-ConversationHistoryTranscriptCommonModelInput)CreateUnitTestResponseModel)GetTestsPageResponseModel)#GetTestsSummariesByIdsResponseModel)GetUnitTestResponseModel)HttpValidationError)!TestFromConversationMetadataInput)UnitTestCommonModelType)$UnitTestToolCallEvaluationModelInput   )*CreateUnitTestRequestDynamicVariablesValue)*UpdateUnitTestRequestDynamicVariablesValue.c                   @     e Zd ZdefddZeeeedddeje de	deje
 d	eje d
e	deje dejeje	eje f  deje deje deje dee fddZddde	deje dee fddZeeeeddde	deje de	deje
 d	eje d
e	deje dejeje	eje f  deje deje deje dee fddZddde	deje deej fddZdddeje	 deje dee fddZddddddeje	 d eje d!eje	 deje dee f
d"d#Z dS )$RawTestsClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r%   q/var/www/html/asistente-voz-ia/venv/lib/python3.10/site-packages/elevenlabs/conversational_ai/tests/raw_client.py__init__!      
zRawTestsClient.__init__Ntool_call_parametersdynamic_variablestypefrom_conversation_metadatarequest_optionschat_historysuccess_conditionsuccess_examplesfailure_examplesnamer*   r+   r,   r-   r.   returnc       
         C   sJ  | j jjddt|tjt dd|t|tjt ddt|tjt ddt|t	ddt|tj
ttjt f dd|t|	tdd|d	ddi|
td}z>d	|j  krTd
k rin ntttt| d}t||dW S |jdkrtt|jtttt| dd| }W n ty   t|jt|j|jdw t|jt|j|d)a  
        Creates a new agent response test.

        Parameters
        ----------
        chat_history : typing.Sequence[ConversationHistoryTranscriptCommonModelInput]

        success_condition : str
            A prompt that evaluates whether the agent's response is successful. Should return True or False.

        success_examples : typing.Sequence[AgentSuccessfulResponseExample]
            Non-empty list of example responses that should be considered successful

        failure_examples : typing.Sequence[AgentFailureResponseExample]
            Non-empty list of example responses that should be considered failures

        name : str

        tool_call_parameters : typing.Optional[UnitTestToolCallEvaluationModelInput]
            How to evaluate the agent's tool call (if any). If empty, the tool call is not evaluated.

        dynamic_variables : typing.Optional[typing.Dict[str, typing.Optional[CreateUnitTestRequestDynamicVariablesValue]]]
            Dynamic variables to replace in the agent config during testing

        type : typing.Optional[UnitTestCommonModelType]

        from_conversation_metadata : typing.Optional[TestFromConversationMetadataInput]
            Metadata of a conversation this test was created from (if applicable).

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

        Returns
        -------
        HttpResponse[CreateUnitTestResponseModel]
            Successful Response
        v1/convai/agent-testing/createPOSTwriteobject_
annotation	direction	r/   r0   r1   r2   r*   r+   r,   r-   r3   content-typeapplication/jsonmethodjsonheadersr.   omit   ,  type_r9   responsedata  rB   bodystatus_coderB   rM   )r"   httpx_clientrequestr   typingSequencer   r   r   r   DictstrOptionalr   r   OMITrO   castr   r   rA   r   r   dictrB   r   r   r   textr$   r/   r0   r1   r2   r3   r*   r+   r,   r-   r.   	_response_data_response_jsonr%   r%   r&   create$   s|   5&

zRawTestsClient.creater.   test_idc             	   C   s   | j jjdt| d|d}z>d|j  krdk r0n ntttt|	 d}t
||dW S |jdkrHtt|jtttt|	 dd	|	 }W n ty`   t|jt|j|jd
w t|jt|j|d
)a  
        Gets an agent response test by ID.

        Parameters
        ----------
        test_id : str
            The id of a chat response test. This is returned on test creation.

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

        Returns
        -------
        HttpResponse[GetUnitTestResponseModel]
            Successful Response
        v1/convai/agent-testing/GETr@   r.   rD   rE   rF   rH   rK   rL   rN   )r"   rP   rQ   r	   rO   rR   rX   r   r   rA   r   r   rY   rB   r   r   r   rZ   r$   ra   r.   r\   r]   r^   r%   r%   r&   get   s>   

zRawTestsClient.getc       
         C   sT  | j jjdt| dt|tjt dd|t|tjt ddt|tjt	 ddt|t
ddt|tjttjt f dd|	t|
tdd|d	ddi|td}z>d	|j  krYd
k rnn ntttt| d}t||dW S |jdkrtt|jtttt| dd| }W n ty   t|jt|j|jdw t|jt|j|d)a9  
        Updates an agent response test by ID.

        Parameters
        ----------
        test_id : str
            The id of a chat response test. This is returned on test creation.

        chat_history : typing.Sequence[ConversationHistoryTranscriptCommonModelInput]

        success_condition : str
            A prompt that evaluates whether the agent's response is successful. Should return True or False.

        success_examples : typing.Sequence[AgentSuccessfulResponseExample]
            Non-empty list of example responses that should be considered successful

        failure_examples : typing.Sequence[AgentFailureResponseExample]
            Non-empty list of example responses that should be considered failures

        name : str

        tool_call_parameters : typing.Optional[UnitTestToolCallEvaluationModelInput]
            How to evaluate the agent's tool call (if any). If empty, the tool call is not evaluated.

        dynamic_variables : typing.Optional[typing.Dict[str, typing.Optional[UpdateUnitTestRequestDynamicVariablesValue]]]
            Dynamic variables to replace in the agent config during testing

        type : typing.Optional[UnitTestCommonModelType]

        from_conversation_metadata : typing.Optional[TestFromConversationMetadataInput]
            Metadata of a conversation this test was created from (if applicable).

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

        Returns
        -------
        HttpResponse[GetUnitTestResponseModel]
            Successful Response
        rb   PUTr7   r8   r<   r=   r>   r?   rD   rE   rF   rH   rK   rL   rN   )r"   rP   rQ   r	   r   rR   rS   r   r   r   r   rT   rU   rV   r   r   rW   rO   rX   r   r   rA   r   r   rY   rB   r   r   r   rZ   r$   ra   r/   r0   r1   r2   r3   r*   r+   r,   r-   r.   r\   r]   r^   r%   r%   r&   update   s|   9&

zRawTestsClient.updatec             	   C   s   | j jjdt| d|d}zP|du s|j s t|ddW S d|j  kr+dk rBn nt	tj
ttj
| d}t||dW S |jd	krZtt|jt	ttt| dd
| }W n tyr   t|jt|j|jdw t|jt|j|d)a  
        Deletes an agent response test by ID.

        Parameters
        ----------
        test_id : str
            The id of a chat response test. This is returned on test creation.

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

        Returns
        -------
        HttpResponse[typing.Any]
            Successful Response
        rb   DELETErd   NrH   rD   rE   rF   rK   rL   rN   )r"   rP   rQ   r	   rZ   stripr   rO   rR   rX   Anyr   rA   r   rY   rB   r   r   r   re   r%   r%   r&   deleteD  sB   

zRawTestsClient.deletetest_idsc             	   C   s   | j jjddd|iddi|td}z>d|j  krdk r2n ntttt|	 d	}t
||d
W S |jdkrJtt|jtttt|	 d	d|	 }W n tyb   t|jt|j|jdw t|jt|j|d)a  
        Gets multiple agent response tests by their IDs. Returns a dictionary mapping test IDs to test summaries.

        Parameters
        ----------
        test_ids : typing.Sequence[str]
            List of test IDs to fetch. No duplicates allowed.

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

        Returns
        -------
        HttpResponse[GetTestsSummariesByIdsResponseModel]
            Successful Response
        !v1/convai/agent-testing/summariesr6   rn   r=   r>   r?   rD   rE   rF   rH   rK   rL   rN   )r"   rP   rQ   rW   rO   rR   rX   r   r   rA   r   r   rY   rB   r   r   r   rZ   r$   rn   r.   r\   r]   r^   r%   r%   r&   	summariesx  sH   

zRawTestsClient.summariescursor	page_sizesearchr.   rs   rt   ru   c             	   C   s   | j jjdd|||d|d}z>d|j  krdk r0n ntttt| d}t	||dW S |jd	krHt
t|jtttt| dd
| }W n ty`   t|jt|j|jdw t|jt|j|d)a  
        Lists all agent response tests with pagination support and optional search filtering.

        Parameters
        ----------
        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

        page_size : typing.Optional[int]
            How many Tests to return at maximum. Can not exceed 100, defaults to 30.

        search : typing.Optional[str]
            Search query to filter tests by name.

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

        Returns
        -------
        HttpResponse[GetTestsPageResponseModel]
            Successful Response
        v1/convai/agent-testingrc   rs   rt   ru   r@   paramsr.   rD   rE   rF   rH   rK   rL   rN   )r"   rP   rQ   rO   rR   rX   r   r   rA   r   r   rY   rB   r   r   r   rZ   r$   rs   rt   ru   r.   r\   r]   r^   r%   r%   r&   list  sF   


zRawTestsClient.list)!__name__
__module____qualname__r   r'   rW   rR   rS   r   rU   r   r   rV   r   rT   r   r   r   r
   r   r   r_   r   rf   r   ri   rl   rm   r   rq   intr   r{   r%   r%   r%   r&   r           	
v
;	

z
5
<r   c                   @   r   )$AsyncRawTestsClientr   c                C   r   r    r!   r#   r%   r%   r&   r'     r(   zAsyncRawTestsClient.__init__Nr)   r/   r0   r1   r2   r3   r*   r+   r,   r-   r.   r4   c       
            sR  | j jjddt|tjt dd|t|tjt ddt|tjt ddt|t	ddt|tj
ttjt f dd|t|	tdd|d	ddi|
tdI d	H }z>d
|j  krXdk rmn ntttt| d}t||dW S |jdkrtt|jtttt| dd| }W n ty   t|jt|j|jdw t|jt|j|d)a  
        Creates a new agent response test.

        Parameters
        ----------
        chat_history : typing.Sequence[ConversationHistoryTranscriptCommonModelInput]

        success_condition : str
            A prompt that evaluates whether the agent's response is successful. Should return True or False.

        success_examples : typing.Sequence[AgentSuccessfulResponseExample]
            Non-empty list of example responses that should be considered successful

        failure_examples : typing.Sequence[AgentFailureResponseExample]
            Non-empty list of example responses that should be considered failures

        name : str

        tool_call_parameters : typing.Optional[UnitTestToolCallEvaluationModelInput]
            How to evaluate the agent's tool call (if any). If empty, the tool call is not evaluated.

        dynamic_variables : typing.Optional[typing.Dict[str, typing.Optional[CreateUnitTestRequestDynamicVariablesValue]]]
            Dynamic variables to replace in the agent config during testing

        type : typing.Optional[UnitTestCommonModelType]

        from_conversation_metadata : typing.Optional[TestFromConversationMetadataInput]
            Metadata of a conversation this test was created from (if applicable).

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

        Returns
        -------
        AsyncHttpResponse[CreateUnitTestResponseModel]
            Successful Response
        r5   r6   r7   r8   r<   r=   r>   r?   NrD   rE   rF   rH   rK   rL   rN   )r"   rP   rQ   r   rR   rS   r   r   r   r   rT   rU   rV   r   r   rW   rO   rX   r   r   rA   r   r   rY   rB   r   r   r   rZ   r[   r%   r%   r&   r_     s~   5&

zAsyncRawTestsClient.creater`   ra   c             	      s   | j jjdt| d|dI dH }z>d|j  krdk r4n ntttt|	 d}t
||dW S |jd	krLtt|jtttt|	 dd
|	 }W n tyd   t|jt|j|jdw t|jt|j|d)a  
        Gets an agent response test by ID.

        Parameters
        ----------
        test_id : str
            The id of a chat response test. This is returned on test creation.

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

        Returns
        -------
        AsyncHttpResponse[GetUnitTestResponseModel]
            Successful Response
        rb   rc   rd   NrD   rE   rF   rH   rK   rL   rN   )r"   rP   rQ   r	   rO   rR   rX   r   r   rA   r   r   rY   rB   r   r   r   rZ   re   r%   r%   r&   rf   m  s@   

zAsyncRawTestsClient.getc       
            s\  | j jjdt| dt|tjt dd|t|tjt ddt|tjt	 ddt|t
ddt|tjttjt f dd|	t|
tdd|d	ddi|tdI d	H }z>d
|j  kr]dk rrn ntttt| d}t||dW S |jdkrtt|jtttt| dd| }W n ty   t|jt|j|jdw t|jt|j|d)a>  
        Updates an agent response test by ID.

        Parameters
        ----------
        test_id : str
            The id of a chat response test. This is returned on test creation.

        chat_history : typing.Sequence[ConversationHistoryTranscriptCommonModelInput]

        success_condition : str
            A prompt that evaluates whether the agent's response is successful. Should return True or False.

        success_examples : typing.Sequence[AgentSuccessfulResponseExample]
            Non-empty list of example responses that should be considered successful

        failure_examples : typing.Sequence[AgentFailureResponseExample]
            Non-empty list of example responses that should be considered failures

        name : str

        tool_call_parameters : typing.Optional[UnitTestToolCallEvaluationModelInput]
            How to evaluate the agent's tool call (if any). If empty, the tool call is not evaluated.

        dynamic_variables : typing.Optional[typing.Dict[str, typing.Optional[UpdateUnitTestRequestDynamicVariablesValue]]]
            Dynamic variables to replace in the agent config during testing

        type : typing.Optional[UnitTestCommonModelType]

        from_conversation_metadata : typing.Optional[TestFromConversationMetadataInput]
            Metadata of a conversation this test was created from (if applicable).

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

        Returns
        -------
        AsyncHttpResponse[GetUnitTestResponseModel]
            Successful Response
        rb   rg   r7   r8   r<   r=   r>   r?   NrD   rE   rF   rH   rK   rL   rN   )r"   rP   rQ   r	   r   rR   rS   r   r   r   r   rT   rU   rV   r   r   rW   rO   rX   r   r   rA   r   r   rY   rB   r   r   r   rZ   rh   r%   r%   r&   ri     s~   9&

zAsyncRawTestsClient.updatec             	      s  | j jjdt| d|dI dH }zP|du s|j s$t|ddW S d|j  kr/dk rFn nt	tj
ttj
| d}t||dW S |jd	kr^tt|jt	ttt| dd
| }W n tyv   t|jt|j|jdw t|jt|j|d)a  
        Deletes an agent response test by ID.

        Parameters
        ----------
        test_id : str
            The id of a chat response test. This is returned on test creation.

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

        Returns
        -------
        AsyncHttpResponse[typing.Any]
            Successful Response
        rb   rj   rd   NrH   rD   rE   rF   rK   rL   rN   )r"   rP   rQ   r	   rZ   rk   r   rO   rR   rX   rl   r   rA   r   rY   rB   r   r   r   re   r%   r%   r&   rm     sD   

zAsyncRawTestsClient.deletern   c             	      s   | j jjddd|iddi|tdI dH }z>d|j  kr!d	k r6n ntttt|	 d
}t
||dW S |jdkrNtt|jtttt|	 d
d|	 }W n tyf   t|jt|j|jdw t|jt|j|d)a  
        Gets multiple agent response tests by their IDs. Returns a dictionary mapping test IDs to test summaries.

        Parameters
        ----------
        test_ids : typing.Sequence[str]
            List of test IDs to fetch. No duplicates allowed.

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

        Returns
        -------
        AsyncHttpResponse[GetTestsSummariesByIdsResponseModel]
            Successful Response
        ro   r6   rn   r=   r>   r?   NrD   rE   rF   rH   rK   rL   rN   )r"   rP   rQ   rW   rO   rR   rX   r   r   rA   r   r   rY   rB   r   r   r   rZ   rp   r%   r%   r&   rq   L  sJ   

zAsyncRawTestsClient.summariesrr   rs   rt   ru   c             	      s   | j jjdd|||d|dI dH }z>d|j  krdk r4n ntttt| d}t	||d	W S |jd
krLt
t|jtttt| dd| }W n tyd   t|jt|j|jdw t|jt|j|d)a  
        Lists all agent response tests with pagination support and optional search filtering.

        Parameters
        ----------
        cursor : typing.Optional[str]
            Used for fetching next page. Cursor is returned in the response.

        page_size : typing.Optional[int]
            How many Tests to return at maximum. Can not exceed 100, defaults to 30.

        search : typing.Optional[str]
            Search query to filter tests by name.

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

        Returns
        -------
        AsyncHttpResponse[GetTestsPageResponseModel]
            Successful Response
        rv   rc   rw   rx   NrD   rE   rF   rH   rK   rL   rN   )r"   rP   rQ   rO   rR   rX   r   r   rA   r   r   rY   rB   r   r   r   rZ   rz   r%   r%   r&   r{     sH   


zAsyncRawTestsClient.list)!r|   r}   r~   r   r'   rW   rR   rS   r   rU   r   r   rV   r   rT   r   r   r   r
   r   r   r_   r   rf   r   ri   rl   rm   r   rq   r   r   r{   r%   r%   r%   r&   r     r   r   )4rR   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.http_responser   r   core.jsonable_encoderr	   core.request_optionsr
   core.serializationr   core.unchecked_base_modelr   !errors.unprocessable_entity_errorr   $types.agent_failure_response_exampler   'types.agent_successful_response_exampler   8types.conversation_history_transcript_common_model_inputr   %types.create_unit_test_response_modelr   #types.get_tests_page_response_modelr   /types.get_tests_summaries_by_ids_response_modelr   "types.get_unit_test_response_modelr   types.http_validation_errorr   +types.test_from_conversation_metadata_inputr   !types.unit_test_common_model_typer   0types.unit_test_tool_call_evaluation_model_inputr   6types.create_unit_test_request_dynamic_variables_valuer   6types.update_unit_test_request_dynamic_variables_valuer   rX   rl   rW   r   r   r%   r%   r%   r&   <module>   s:      W