
    ihPm                        d dl 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 j8                  e j:                  d      Z G d d      Z G d d      Z y)    N   )SyncClientWrapper   )HistoryGetAllRequestSource)RequestOptions)GetSpeechHistoryResponse)construct_type)UnprocessableEntityError)HttpValidationError)JSONDecodeError)ApiError)SpeechHistoryItemResponse)jsonable_encoder)DeleteHistoryItemResponse)BadRequestError)AsyncClientWrapper.c                   &   e Zd ZdefdZdddddd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fdZddded
ej                  e
   defdZddded
ej                  e
   defdZddded
ej                  e
   dej"                  e   fdZedddej*                  e   dej                  e   d
ej                  e
   dej"                  e   fdZy)HistoryClientclient_wrapperc                    || _         y N_client_wrapperselfr   s     W/var/www/html/dev/engine/venv/lib/python3.12/site-packages/elevenlabs/history/client.py__init__zHistoryClient.__init__   
    -    N	page_sizestart_after_history_item_idvoice_idsearchsourcerequest_optionsr!   r"   r#   r$   r%   r&   returnc          
      H   | j                   j                  j                  dd|||||d|      }	 d|j                  cxk  rdk  r:n n7t	        j
                  t        t        t        |j                                     S |j                  dk(  r@t        t	        j
                  t        t        t        |j                                           |j                         }t        |j                  |	      # t        $ r" t        |j                  |j                  	      w xY w)
a.  
        Returns a list of 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.

        search : typing.Optional[str]
            search term used for filtering

        source : typing.Optional[HistoryGetAllRequestSource]
            Source of the generated history item

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

        Returns
        -------
        GetSpeechHistoryResponse
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.history.get_all()
        
v1/historyGETr!   r"   r#   r$   r%   methodparamsr&      ,  type_object_  status_codebodyr   httpx_clientrequestr6   typingcastr   r	   jsonr
   r   r   r   text	r   r!   r"   r#   r$   r%   r&   	_response_response_jsons	            r   get_allzHistoryClient.get_all   s   ^ ((55==&/J$   , > 
		Si++1c1{{,"6 ) 0  $$+.KK+&"5$-NN$4  '^^-N 9#8#8~NN  	Sy'<'<9>>RR	Ss   AC6  AC6 6+D!r&   history_item_idc          
      R   | j                   j                  j                  dt        |       d|      }	 d|j                  cxk  rdk  r:n n7t        j                  t        t        t        |j                                     S |j                  dk(  r@t        t        j                  t        t        t        |j                                           |j                         }t        |j                  |      # t        $ r" t        |j                  |j                        w xY w)	a  
        Retrieves a 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.

        Returns
        -------
        SpeechHistoryItemResponse
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.history.get(
            history_item_id="HISTORY_ITEM_ID",
        )
        v1/history/r*   r-   r&   r/   r0   r1   r4   r5   r   r9   r:   r   r6   r;   r<   r   r	   r=   r
   r   r   r   r>   r   rD   r&   r@   rA   s        r   getzHistoryClient.getn   s   < ((55==*?;<=+ > 
	
	Si++1c1{{-"7 ) 0  $$+.KK+&"5$-NN$4  '^^-N 9#8#8~NN  	Sy'<'<9>>RR	S   AC; AC; ;+D&c          
      R   | j                   j                  j                  dt        |       d|      }	 d|j                  cxk  rdk  r:n n7t        j                  t        t        t        |j                                     S |j                  dk(  r@t        t        j                  t        t        t        |j                                           |j                         }t        |j                  |      # t        $ r" t        |j                  |j                        w xY w)	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.

        Returns
        -------
        DeleteHistoryItemResponse
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.history.delete(
            history_item_id="HISTORY_ITEM_ID",
        )
        rF   DELETErG   r/   r0   r1   r4   r5   r   r9   r:   r   r6   r;   r<   r   r	   r=   r
   r   r   r   r>   rI   s        r   deletezHistoryClient.delete   s   < ((55==*?;<=+ > 
	
	Si++1c1{{-"7 ) 0  $$+.KK+&"5$-NN$4  '^^-N 9#8#8~NN  	Sy'<'<9>>RR	SrK   c             #     K   | j                   j                  j                  dt        |       dd|      5 }	 d|j                  cxk  rdk  r>n n;||j                  dd	      nd	}|j                  |
      D ]  }|  	 ddd       y|j                          |j                  dk(  r@t        t        j                  t        t        t        |j                                           |j                         }t        |j                  |      # t        $ r" t        |j                  |j                         w xY w# 1 sw Y   yxY ww)a8  
        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. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Yields
        ------
        typing.Iterator[bytes]
            The audio file of the history item.

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.history.get_audio(
            history_item_id="HISTORY_ITEM_ID",
        )
        rF   /audior*   rG   r/   r0   N
chunk_size   rR   r4   r1   r5   )r   r9   streamr   r6   rJ   
iter_bytesreadr
   r;   r<   r   r	   r=   r   r   r>   r   rD   r&   r@   _chunk_size_chunkrA   s          r   	get_audiozHistoryClient.get_audio   sS    < !!..55*?;<FC+ 6 
 	S W)//5#5M\Mh/"5"5lD"InrK"+"6"6+"6"N %$%	S 	S  ((C/2/*&9(1(8  "+!1 y'<'<>RR # W9+@+@y~~VVW/	S 	Ss;   6EEA	D	EA/D<E+D>>EE
Eoutput_formatr&   history_item_idsr]   c             #     K   | j                   j                  j                  dd||dddi|t              5 }	 d|j                  cxk  rdk  r>n n;||j                  d
d      nd}|j                  |      D ]  }|  	 d	d	d	       y	|j                          |j                  dk(  rvt        t        j                  t        j                  t        j                     t        t        j                  t        j                     |j                                           |j                  dk(  r@t        t        j                  t         t        t         |j                                           |j                         }t%        |j                  |      # t"        $ r" t%        |j                  |j&                        w xY w# 1 sw Y   y	xY ww)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.

        output_format : typing.Optional[str]
            Output format to transcode the audio file, can be wav or default.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Yields
        ------
        typing.Iterator[bytes]
            The requested audio file, or a zip file containing multiple audio files when multiple history items are requested.

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.history.download(
            history_item_ids=["HISTORY_ITEM_ID"],
        )
        v1/history/downloadPOSTr^   r]   content-typeapplication/jsonr-   r=   headersr&   omitr/   r0   NrR   rS   rT     r1   r4   r5   )r   r9   rU   OMITr6   rJ   rV   rW   r   r;   r<   OptionalAnyr	   r=   r
   r   r   r   r>   r   r^   r]   r&   r@   rY   rZ   rA   s           r   downloadzHistoryClient.download  s    J !!..55!$4!.
  2 , 6 
 +	S W)//5#5M\Mh/"5"5lD"InrK"+"6"6+"6"N %$%%+	S +	S&  ((C/)"OOFJJ7*&,oofjj&A(1(8  ((C/2/*&9(1(8  "+!1 y'<'<>RR # W9+@+@y~~VVWS+	S +	Ss;   5GGA	F	GC4F G+GGG
G)__name__
__module____qualname__r   r   r;   rj   intstrr   r   r   rB   r   rJ   r   rO   Iteratorbytesr[   ri   Sequencerm    r   r   r   r      s   .*; . +/<@)-'+>B;?QO ??3'QO &,__S%9	QO
 //#&QO $QO  :;QO  8QO 
"QOh [_9O"9O8>8W9O	"9Ox [_9O"9O8>8W9O	"9Ox [_7S"7S8>8W7S		7Sz /3;?PS !//#.PS s+	PS
  8PS 
	PSr   r   c                   &   e Zd ZdefdZdddddd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fdZddded
ej                  e
   defdZddded
ej                  e
   defdZddded
ej                  e
   dej"                  e   fdZedddej*                  e   dej                  e   d
ej                  e
   dej"                  e   fdZy)AsyncHistoryClientr   c                    || _         y r   r   r   s     r   r   zAsyncHistoryClient.__init__q  r   r   Nr    r!   r"   r#   r$   r%   r&   r'   c          
      d  K   | j                   j                  j                  dd|||||d|       d{   }	 d|j                  cxk  rdk  r:n n7t	        j
                  t        t        t        |j                                     S |j                  d	k(  r@t        t	        j
                  t        t        t        |j                                           |j                         }t        |j                  |
      7 # t        $ r" t        |j                  |j                  
      w xY ww)a  
        Returns a list of 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.

        search : typing.Optional[str]
            search term used for filtering

        source : typing.Optional[HistoryGetAllRequestSource]
            Source of the generated history item

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

        Returns
        -------
        GetSpeechHistoryResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.history.get_all()


        asyncio.run(main())
        r)   r*   r+   r,   Nr/   r0   r1   r4   r5   r8   r?   s	            r   rB   zAsyncHistoryClient.get_allt  s%    n ..;;CC&/J$   , D 
 
		Si++1c1{{,"6 ) 0  $$+.KK+&"5$-NN$4  '^^-N 9#8#8~NNE
@  	Sy'<'<9>>RR	Ss4   3D0D D0AD 	D0
AD )D0+D--D0rC   rD   c          
      n  K   | j                   j                  j                  dt        |       d|       d{   }	 d|j                  cxk  rdk  r:n n7t        j                  t        t        t        |j                                     S |j                  dk(  r@t        t        j                  t        t        t        |j                                           |j                         }t        |j                  |	      7 # t        $ r" t        |j                  |j                  	      w xY ww)
a-  
        Retrieves a 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.

        Returns
        -------
        SpeechHistoryItemResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.history.get(
                history_item_id="HISTORY_ITEM_ID",
            )


        asyncio.run(main())
        rF   r*   rG   Nr/   r0   r1   r4   r5   rH   rI   s        r   rJ   zAsyncHistoryClient.get  s    L ..;;CC*?;<=+ D 
 
	
	Si++1c1{{-"7 ) 0  $$+.KK+&"5$-NN$4  '^^-N 9#8#8~NN7
2  	Sy'<'<9>>RR	S5   8D5DD5 AD D5AD .D5+D22D5c          
      n  K   | j                   j                  j                  dt        |       d|       d{   }	 d|j                  cxk  rdk  r:n n7t        j                  t        t        t        |j                                     S |j                  dk(  r@t        t        j                  t        t        t        |j                                           |j                         }t        |j                  |	      7 # t        $ r" t        |j                  |j                  	      w xY ww)
a6  
        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.

        Returns
        -------
        DeleteHistoryItemResponse
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.history.delete(
                history_item_id="HISTORY_ITEM_ID",
            )


        asyncio.run(main())
        rF   rM   rG   Nr/   r0   r1   r4   r5   rN   rI   s        r   rO   zAsyncHistoryClient.delete  s    L ..;;CC*?;<=+ D 
 
	
	Si++1c1{{-"7 ) 0  $$+.KK+&"5$-NN$4  '^^-N 9#8#8~NN7
2  	Sy'<'<9>>RR	Sr|   c                 K   | j                   j                  j                  dt        |       dd|      4 d{   }	 d|j                  cxk  rdk  r:n n7||j                  dd	      nd	}|j                  |
      2 3 d{   }| |j                          d{    |j                  dk(  r@t        t        j                  t        t        t        |j                                           |j                         }t        |j                  |      7 7 6 	 ddd      d{  7   y7 # t        $ r" t        |j                  |j                         w xY w# 1 d{  7  sw Y   yxY ww)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. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Yields
        ------
        typing.AsyncIterator[bytes]
            The audio file of the history item.

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.history.get_audio(
                history_item_id="HISTORY_ITEM_ID",
            )


        asyncio.run(main())
        rF   rQ   r*   rG   Nr/   r0   rR   rS   rT   r4   r1   r5   )r   r9   rU   r   r6   rJ   aiter_bytesareadr
   r;   r<   r   r	   r=   r   r   r>   rX   s          r   r[   zAsyncHistoryClient.get_audioU  s    L ''44;;*?;<FC+ < 
 	S 	S W)//5#5M\Mh/"5"5lD"InrK(1(=(=(=(U % %f$oo'''((C/2/*&9(1(8  "+!1 y'<'<>RR3	S%(U	S 	S 	S ( # W9+@+@y~~VVW/	S 	S 	Ss   :E<DE< E'A D9D#D!D#
D9$D7%A#D9E'E<!D##D9%E<0D31E<7D99+E$$E''E9-E0.E95E<r\   r^   r]   c               
  K   | j                   j                  j                  dd||dddi|t              4 d{   }	 d|j                  cxk  rd	k  r:n n7||j                  d
d      nd}|j                  |      2 3 d{   }| |j                          d{    |j                  dk(  rvt        t        j                  t        j                  t        j                     t        t        j                  t        j                     |j                                           |j                  dk(  r@t        t        j                  t         t        t         |j                                           |j                         }t%        |j                  |      7 h7 !6 	 ddd      d{  7   y7 # t"        $ r" t%        |j                  |j&                        w xY w# 1 d{  7  sw Y   yxY ww)aV  
        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.

        output_format : typing.Optional[str]
            Output format to transcode the audio file, can be wav or default.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

        Yields
        ------
        typing.AsyncIterator[bytes]
            The requested audio file, or a zip file containing multiple audio files when multiple history items are requested.

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.history.download(
                history_item_ids=["HISTORY_ITEM_ID"],
            )


        asyncio.run(main())
        r`   ra   rb   rc   rd   re   Nr/   r0   rR   rS   rT   rh   r1   r4   r5   )r   r9   rU   ri   r6   rJ   r   r   r   r;   r<   rj   rk   r	   r=   r
   r   r   r   r>   rl   s           r   rm   zAsyncHistoryClient.download  s    Z ''44;;!$4!.
  2 , < 
 +	S +	S W)//5#5M\Mh/"5"5lD"InrK(1(=(=(=(U % %f$oo'''((C/)"OOFJJ7*&,oofjj&A(1(8  ((C/2/*&9(1(8  "+!1 y'<'<>RRW+	S %(U%+	S +	S +	S& (, # W9+@+@y~~VVWS+	S +	S +	Ss   9HF#HG.A G F)F&F)	G #F=$C(G G.#H&F))G +H6F97H=G  +G++G..H 4G75H <H)rn   ro   rp   r   r   r;   rj   rq   rr   r   r   r   rB   r   rJ   r   rO   AsyncIteratorrt   r[   ri   ru   rm   rv   r   r   rx   rx   p  s   .*< . +/<@)-'+>B;?YO ??3'YO &,__S%9	YO
 //#&YO $YO  :;YO  8YO 
"YOx [_AO"AO8>8WAO	"AOH [_AO"AO8>8WAO	"AOH [_?S"?S8>8W?S			e	$?SJ /3;?XS !//#.XS s+	XS
  8XS 
		e	$XSr   rx   )!r;   core.client_wrapperr   $types.history_get_all_request_sourcer   core.request_optionsr   !types.get_speech_history_responser   core.unchecked_base_modelr	   !errors.unprocessable_entity_errorr
   types.http_validation_errorr   json.decoderr   core.api_errorr   "types.speech_history_item_responser   core.jsonable_encoderr   "types.delete_history_item_responser   errors.bad_request_errorr   r   r<   rk   ri   r   rx   rv   r   r   <module>r      si     3 L 1 H 6 H = ( % J 4 J 6 4 v{{6::s#VS VSr
~S ~Sr   