o
    lWiM                     @   s   d dl Z d dlm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 e e j dZ!G dd dZ"G dd dZ#dS )    N)JSONDecodeError   )core)ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)jsonable_encoder)RequestOptions)construct_type)UnprocessableEntityError)AddKnowledgeBaseResponseModel)HttpValidationError)RagDocumentIndexResponseModel)RagDocumentIndexesResponseModel)RagIndexOverviewResponseModel.c                   @      e Zd ZdefddZdeeedddeje deje deje d	eje	j
 d
eje dee fddZdd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dddeded
eje dee fddZdS )RawConversationalAiClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r   k/var/www/html/asistente-voz-ia/venv/lib/python3.10/site-packages/elevenlabs/conversational_ai/raw_client.py__init__      
z"RawConversationalAiClient.__init__Nagent_idnameurlfilerequest_optionsr!   r"   r#   r$   r%   returnc          	   
   C   s   | j jjddd|i||di |durd|ini |tdd}z>d	|j  kr*d
k r?n ntttt|	 d}t
||dW S |jdkrWtt|jtttt|	 dd|	 }W n tyo   t|jt|j|jdw t|jt|j|d)a_  
        Upload a file or webpage URL to create a knowledge base document. <br> <Note> After creating the document, update the agent's knowledge base by calling [Update agent](/docs/api-reference/agents/update). </Note>

        Parameters
        ----------
        agent_id : typing.Optional[str]

        name : typing.Optional[str]
            A custom, human-readable name for the document.

        url : typing.Optional[str]
            URL to a page of documentation that the agent will have access to in order to interact with users.

        file : typing.Optional[core.File]
            See core.File for more documentation

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

        Returns
        -------
        HttpResponse[AddKnowledgeBaseResponseModel]
            Successful Response
        v1/convai/knowledge-basePOSTr!   r"   r#   Nr$   Tmethodparamsdatafilesr%   omitforce_multipart   ,  type_object_responser-     headersbodystatus_coder:   r;   )r   httpx_clientrequestOMITr=   typingcastr   r   jsonr	   r   dictr:   r   r   r   text	r   r!   r"   r#   r$   r%   	_response_data_response_jsonr   r   r   add_to_knowledge_base   sR   !

z/RawConversationalAiClient.add_to_knowledge_baser%   c             	   C   s   | j jjdd|d}z>d|j  krdk r+n ntttt| d}t	||dW S |jdkrCt
t|jtttt| dd	| }W n ty[   t|jt|j|jd
w t|jt|j|d
)al  
        Provides total size and other information of RAG indexes used by knowledgebase documents

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

        Returns
        -------
        HttpResponse[RagIndexOverviewResponseModel]
            Successful Response
        "v1/convai/knowledge-base/rag-indexGETr+   r%   r1   r2   r3   r6   r8   r9   r<   )r   r>   r?   r=   rA   rB   r   r   rC   r	   r   rD   r:   r   r   r   rE   r   r%   rG   rH   rI   r   r   r   rag_index_overviewh   s>   

z,RawConversationalAiClient.rag_index_overviewdocumentation_idc             	   C   s   | j jjdt| dd|d}z>d|j  krdk r1n ntttt|	 d}t
||dW S |jd	krItt|jtttt|	 dd
|	 }W n tya   t|jt|j|jdw t|jt|j|d)a  
        Provides information about all RAG indexes of the specified knowledgebase document.

        Parameters
        ----------
        documentation_id : str
            The id of a document from the knowledge base. This is returned on document addition.

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

        Returns
        -------
        HttpResponse[RagDocumentIndexesResponseModel]
            Successful Response
        v1/convai/knowledge-base/
/rag-indexrM   rN   r1   r2   r3   r6   r8   r9   r<   )r   r>   r?   r
   r=   rA   rB   r   r   rC   r	   r   rD   r:   r   r   r   rE   r   rQ   r%   rG   rH   rI   r   r   r   get_document_rag_indexes   s>   

z2RawConversationalAiClient.get_document_rag_indexesrag_index_idc             	   C   s   | j jjdt| dt| d|d}z>d|j  kr dk r5n ntttt|	 d}t
||dW S |jd	krMtt|jtttt|	 dd
|	 }W n tye   t|jt|j|jdw t|jt|j|d)a&  
        Delete RAG index for the knowledgebase document.

        Parameters
        ----------
        documentation_id : str
            The id of a document from the knowledge base. This is returned on document addition.

        rag_index_id : str
            The id of RAG index of document from the knowledge base.

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

        Returns
        -------
        HttpResponse[RagDocumentIndexResponseModel]
            Successful Response
        rR   /rag-index/DELETErN   r1   r2   r3   r6   r8   r9   r<   )r   r>   r?   r
   r=   rA   rB   r   r   rC   r	   r   rD   r:   r   r   r   rE   r   rQ   rV   r%   rG   rH   rI   r   r   r   delete_document_rag_index   s>   

z3RawConversationalAiClient.delete_document_rag_index)__name__
__module____qualname__r   r   r@   rA   Optionalstrr   Filer   r	   r   rJ   r   rP   r   rU   r   rZ   r   r   r   r   r      X    

M
0
3r   c                   @   r   )AsyncRawConversationalAiClientr   c                C   r   r   r   r   r   r   r   r      r   z'AsyncRawConversationalAiClient.__init__Nr    r!   r"   r#   r$   r%   r&   c          	   
      s   | j jjddd|i||di |durd|ini |tddI dH }z>d	|j  kr.d
k rCn ntttt|	 d}t
||dW S |jdkr[tt|jtttt|	 dd|	 }W n tys   t|jt|j|jdw t|jt|j|d)ad  
        Upload a file or webpage URL to create a knowledge base document. <br> <Note> After creating the document, update the agent's knowledge base by calling [Update agent](/docs/api-reference/agents/update). </Note>

        Parameters
        ----------
        agent_id : typing.Optional[str]

        name : typing.Optional[str]
            A custom, human-readable name for the document.

        url : typing.Optional[str]
            URL to a page of documentation that the agent will have access to in order to interact with users.

        file : typing.Optional[core.File]
            See core.File for more documentation

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

        Returns
        -------
        AsyncHttpResponse[AddKnowledgeBaseResponseModel]
            Successful Response
        r'   r(   r!   r)   Nr$   Tr*   r1   r2   r3   r6   r8   r9   r<   )r   r>   r?   r@   r=   rA   rB   r   r   rC   r   r   rD   r:   r   r   r   rE   rF   r   r   r   rJ     sT   !

z4AsyncRawConversationalAiClient.add_to_knowledge_baserK   c             	      s   | j jjdd|dI dH }z>d|j  krdk r/n ntttt| d}t	||dW S |jd	krGt
t|jtttt| dd
| }W n ty_   t|jt|j|jdw t|jt|j|d)aq  
        Provides total size and other information of RAG indexes used by knowledgebase documents

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

        Returns
        -------
        AsyncHttpResponse[RagIndexOverviewResponseModel]
            Successful Response
        rL   rM   rN   Nr1   r2   r3   r6   r8   r9   r<   )r   r>   r?   r=   rA   rB   r   r   rC   r   r   rD   r:   r   r   r   rE   rO   r   r   r   rP   O  s@   

z1AsyncRawConversationalAiClient.rag_index_overviewrQ   c             	      s   | j jjdt| dd|dI dH }z>d|j  kr dk r5n ntttt|	 d}t
||d	W S |jd
krMtt|jtttt|	 dd|	 }W n tye   t|jt|j|jdw t|jt|j|d)a  
        Provides information about all RAG indexes of the specified knowledgebase document.

        Parameters
        ----------
        documentation_id : str
            The id of a document from the knowledge base. This is returned on document addition.

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

        Returns
        -------
        AsyncHttpResponse[RagDocumentIndexesResponseModel]
            Successful Response
        rR   rS   rM   rN   Nr1   r2   r3   r6   r8   r9   r<   )r   r>   r?   r
   r=   rA   rB   r   r   rC   r   r   rD   r:   r   r   r   rE   rT   r   r   r   rU   ~  s@   

z7AsyncRawConversationalAiClient.get_document_rag_indexesrV   c             	      s   | j jjdt| dt| d|dI dH }z>d|j  kr$dk r9n ntttt|	 d}t
||d	W S |jd
krQtt|jtttt|	 dd|	 }W n tyi   t|jt|j|jdw t|jt|j|d)a+  
        Delete RAG index for the knowledgebase document.

        Parameters
        ----------
        documentation_id : str
            The id of a document from the knowledge base. This is returned on document addition.

        rag_index_id : str
            The id of RAG index of document from the knowledge base.

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

        Returns
        -------
        AsyncHttpResponse[RagDocumentIndexResponseModel]
            Successful Response
        rR   rW   rX   rN   Nr1   r2   r3   r6   r8   r9   r<   )r   r>   r?   r
   r=   rA   rB   r   r   rC   r   r   rD   r:   r   r   r   rE   rY   r   r   r   rZ     s@   

z8AsyncRawConversationalAiClient.delete_document_rag_index)r[   r\   r]   r   r   r@   rA   r^   r_   r   r`   r   r   r   rJ   r   rP   r   rU   r   rZ   r   r   r   r   rb      ra   rb   )$rA   json.decoderr    r   core.api_errorr   core.client_wrapperr   r   core.http_responser   r	   core.jsonable_encoderr
   core.request_optionsr   core.unchecked_base_modelr   !errors.unprocessable_entity_errorr   'types.add_knowledge_base_response_modelr   types.http_validation_errorr   'types.rag_document_index_response_modelr   )types.rag_document_indexes_response_modelr   'types.rag_index_overview_response_modelr   rB   Anyr@   r   rb   r   r   r   r   <module>   s&    h