o
    "ik                     @   s   d dl Z 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 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 zd dlmZ W n ey[   d dlZY nw e e jdZG dd dZG dd dZ dS )    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)jsonable_encoder)remove_none_from_dict)RequestOptions)UnprocessableEntityError)GetSpeechHistoryResponse)HttpValidationError)SpeechHistoryItemResponse.c                   @      e Zd Zd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
f
ddZddded	eje	 d
efddZddded	eje	 d
ejfddZddded	eje	 d
eje fddZdddeje d	eje	 d
dfddZdS )HistoryClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r   ]/var/www/html/voicebot/backend/venv/lib/python3.10/site-packages/elevenlabs/history/client.py__init__      
zHistoryClient.__init__N	page_sizestart_after_history_item_idvoice_idrequest_optionsr   r   r   r   returnc                C   s8  | j jjdtj| j   ddtt|||d|dur"|	di ni tti | j 
 |dur8|	di ni |durL|	ddurL|	dnd	d
|durW|	dnd
d}d|j  krfdk rpn ntt| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a  
        Returns metadata about all your generated audio.

        Parameters:
            - page_size: typing.Optional[int]. How many history items to return at maximum. Can not exceed 1000, defaults to 100.

            - start_after_history_item_id: typing.Optional[str]. After which ID to start fetching, use this parameter to paginate across a large collection of history items. In case this parameter is not provided history items will be fetched starting from the most recently created one ordered descending by their creation date.

            - voice_id: typing.Optional[str]. Voice ID to be filtered for, you can use GET https://api.elevenlabs.io/v1/voices to receive a list of voices and their IDs.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.history.get_all()
        GET/
v1/historyr   r   r   Nadditional_query_parametersadditional_headerstimeout_in_seconds<   r   max_retriesparamsheaderstimeoutretriesr)      ,    status_codebodyr   httpx_clientrequesturllibparseurljoinget_base_urlr   r   getget_headersr3   pydanticparse_obj_asr   jsonr
   r   r   r   textr   r   r   r   r   	_response_response_jsonr   r   r   get_all   sP   	

zHistoryClient.get_allr   history_item_idc                C   s0  | j jjdtj| j   ddt| t|dur |dndtt	i | j 
 |dur4|di ni |durH|ddurH|dndd	|durS|d
nd	d}d|j  krbdk rln ntt| S |jdkr{ttt| z| }W n ty   t|j|jdw t|j|d)aA  
        Returns information about an history item by its ID.

        Parameters:
            - history_item_id: str. History item ID to be used, you can use GET https://api.elevenlabs.io/v1/history to receive a list of history items and their IDs.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.history.get(
            history_item_id="history_item_id",
        )
        r!   r"   v1/history/Nr%   r&   r'   r(   r   r)   r*   r/   r0   r1   r2   r   r6   r7   r8   r9   r:   r;   r   r<   r   r=   r3   r>   r?   r   r@   r
   r   r   r   rA   r   rG   r   rC   rD   r   r   r   r<   b   sB   	

zHistoryClient.getc                C   s2  | j jjdtj| j   ddt| t|dur |dndtt	i | j 
 |dur4|di ni |durH|ddurH|dndd	|durS|d
nd	d}d|j  krbdk rmn n	ttj| S |jdkr|ttt| z| }W n ty   t|j|jdw t|j|d)a/  
        Delete a history item by its ID

        Parameters:
            - history_item_id: str. History item ID to be used, you can use GET https://api.elevenlabs.io/v1/history to receive a list of history items and their IDs.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.history.delete(
            history_item_id="history_item_id",
        )
        DELETEr"   rH   Nr%   r&   r'   r(   r   r)   r*   r/   r0   r1   r2   r   r6   r7   r8   r9   r:   r;   r   r<   r   r=   r3   r>   r?   typingAnyr@   r
   r   r   r   rA   rJ   r   r   r   delete   sB   	

zHistoryClient.deletec                c   sJ   | j jjdtj| j   ddt| dt|dur"|dndtt	i | j 
 |dur6|di ni |durJ|ddurJ|dnd	d
|durU|dnd
dB}d|j  kredk rzn n| D ]}|V  qk	 W d   dS |  z| }W n ty   t|j|jdw t|j|d1 sw   Y  dS )a/  
        Returns the audio of an history item.

        Parameters:
            - history_item_id: str. History item ID to be used, you can use GET https://api.elevenlabs.io/v1/history to receive a list of history items and their IDs.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.history.get_audio(
            history_item_id="string",
        )
        r!   r"   rH   /audioNr%   r&   r'   r(   r   r)   r*   r/   r0   r2   )r   r6   streamr8   r9   r:   r;   r   r<   r   r=   r3   
iter_bytesreadr@   r   r   rA   r   rG   r   rC   _chunkrD   r   r   r   	get_audio   sL   	
zHistoryClient.get_audiohistory_item_idsc                C   sZ  | j jjdtj| j   ddt|dur|dnd|du s(|ddu r.td|ini td|itt	|di tt	i | j 
 |durQ|di ni |dure|d	dure|d	nd
d|durp|dndd}d|j  krdk rdS  |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a  
        Download one or more history items. If one history item ID is provided, we will return a single audio file. If more than one history item IDs are provided, we will provide the history items packed into a .zip file.

        Parameters:
            - history_item_ids: typing.Sequence[str]. A list of history items to download, you can get IDs of history items and other metadata using the GET https://api.elevenlabs.io/v1/history endpoint.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.history.download(
            history_item_ids=["history_item_ids"],
        )
        POSTr"   v1/history/downloadNr%   additional_body_parametersrW   r&   r'   r(   r   r)   r+   r@   r,   r-   r.   r)   r/   r0   r1   r2   r   r6   r7   r8   r9   r:   r;   r   r<   r   r=   r3   r
   r>   r?   r   r@   r   r   rA   r   rW   r   rC   rD   r   r   r   download   sN   
	

zHistoryClient.download)__name__
__module____qualname__r   r   rM   Optionalintstrr	   r   rE   r   r<   rN   rO   IteratorbytesrV   Sequencer^   r   r   r   r   r      sT    
E
$43
6r   c                   @   r   )AsyncHistoryClientr   c                C   r   r   r   r   r   r   r   r   7  r   zAsyncHistoryClient.__init__Nr   r   r   r   r   r    c                   s@  | j jjdtj| j   ddtt|||d|dur#|	di ni tti | j 
 |dur9|	di ni |durM|	ddurM|	dnd	d
|durX|	dnd
dI dH }d|j  krjdk rtn ntt| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a  
        Returns metadata about all your generated audio.

        Parameters:
            - page_size: typing.Optional[int]. How many history items to return at maximum. Can not exceed 1000, defaults to 100.

            - start_after_history_item_id: typing.Optional[str]. After which ID to start fetching, use this parameter to paginate across a large collection of history items. In case this parameter is not provided history items will be fetched starting from the most recently created one ordered descending by their creation date.

            - voice_id: typing.Optional[str]. Voice ID to be filtered for, you can use GET https://api.elevenlabs.io/v1/voices to receive a list of voices and their IDs.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.history.get_all()
        r!   r"   r#   r$   Nr%   r&   r'   r(   r   r)   r*   r/   r0   r1   r2   r5   rB   r   r   r   rE   :  sR   	

zAsyncHistoryClient.get_allrF   rG   c                   s8  | j jjdtj| j   ddt| t|dur!|dndtt	i | j 
 |dur5|di ni |durI|ddurI|dndd	|durT|d
nd	dI dH }d|j  krfdk rpn ntt| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)aQ  
        Returns information about an history item by its ID.

        Parameters:
            - history_item_id: str. History item ID to be used, you can use GET https://api.elevenlabs.io/v1/history to receive a list of history items and their IDs.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.history.get(
            history_item_id="history_item_id",
        )
        r!   r"   rH   Nr%   r&   r'   r(   r   r)   r*   r/   r0   r1   r2   rI   rJ   r   r   r   r<   ~  sD   	

zAsyncHistoryClient.getc                   s:  | j jjdtj| j   ddt| t|dur!|dndtt	i | j 
 |dur5|di ni |durI|ddurI|dndd	|durT|d
nd	dI dH }d|j  krfdk rqn n	ttj| S |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a?  
        Delete a history item by its ID

        Parameters:
            - history_item_id: str. History item ID to be used, you can use GET https://api.elevenlabs.io/v1/history to receive a list of history items and their IDs.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.history.delete(
            history_item_id="history_item_id",
        )
        rK   r"   rH   Nr%   r&   r'   r(   r   r)   r*   r/   r0   r1   r2   rL   rJ   r   r   r   rO     sD   	

zAsyncHistoryClient.deletec                C  sn  | j jjdtj| j   ddt| dt|dur"|dndtt	i | j 
 |dur6|di ni |durJ|ddurJ|dnd	d
|durU|dnd
d4 I dH M}d|j  kridk rn n| 2 z	3 dH W }|V  qo6 	 W d  I dH  dS | I dH  z| }W n ty   t|j|jdw t|j|d1 I dH sw   Y  dS )a?  
        Returns the audio of an history item.

        Parameters:
            - history_item_id: str. History item ID to be used, you can use GET https://api.elevenlabs.io/v1/history to receive a list of history items and their IDs.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.history.get_audio(
            history_item_id="string",
        )
        r!   r"   rH   rP   Nr%   r&   r'   r(   r   r)   r*   r/   r0   r2   )r   r6   rQ   r8   r9   r:   r;   r   r<   r   r=   r3   aiter_bytesareadr@   r   r   rA   rT   r   r   r   rV     sN   	
zAsyncHistoryClient.get_audiorW   c                   sb  | j jjdtj| j   ddt|dur|dnd|du s)|ddu r/td|ini td|itt	|di tt	i | j 
 |durR|di ni |durf|d	durf|d	nd
d|durq|dnddI dH }d|j  krdk rdS  |jdkrttt| z| }W n ty   t|j|jdw t|j|d)a!  
        Download one or more history items. If one history item ID is provided, we will return a single audio file. If more than one history item IDs are provided, we will provide the history items packed into a .zip file.

        Parameters:
            - history_item_ids: typing.Sequence[str]. A list of history items to download, you can get IDs of history items and other metadata using the GET https://api.elevenlabs.io/v1/history endpoint.

            - request_options: typing.Optional[RequestOptions]. Request-specific configuration.
        ---
        from elevenlabs.client import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )
        await client.history.download(
            history_item_ids=["history_item_ids"],
        )
        rX   r"   rY   Nr%   rZ   rW   r&   r'   r(   r   r)   r[   r/   r0   r1   r2   r\   r]   r   r   r   r^     sP   
	

zAsyncHistoryClient.download)r_   r`   ra   r   r   rM   rb   rc   rd   r	   r   rE   r   r<   rN   rO   AsyncIteratorrf   rV   rg   r^   r   r   r   r   rh   6  sb    
E
5
5
6rh   )!rM   urllib.parser8   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.jsonable_encoderr   core.remove_none_from_dictr   core.request_optionsr	   !errors.unprocessable_entity_errorr
   !types.get_speech_history_responser   types.http_validation_errorr   "types.speech_history_item_responser   pydantic.v1v1r>   ImportErrorcastrN   OMITr   rh   r   r   r   r   <module>   s,     