+
    &j:                       a  R= tK0 t R t^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	 ^ RI
Ht ^ RIHt ^ RIHtHtHtHtHtHtHt ^ RIt^ RIHtHtHtHtHtHtHt ^RIH t H!t!H"t" ^RI#H$t$H%t% ]'       d   ^ R	I&H't' ](t)]](]3,          t*]]+]]*])R
],]-3,          t.RR0t/]P`                  ! ]14      t2] ! R R4      4       t3 ! R R]+4      t4R t5R t6]R R l4       t7]R R l4       t7R R lt7R R lt8R R lt9R R lt:R R  lt;R! R" lt<R# R$ lt=R% R& lt>R' R( lt?R) R* lt@R+ R, ltAR- R. ltBR/ R0 ltCR1 R2 ltDR3 R4 ltE/ tF] ^ k R5 R6 ltGR7 R8 ltHR9 R: ltIR; R< ltJR# )>zEContains utilities used by both the sync and async inference clients.N)AsyncIterableIterable)	dataclass)Path)TYPE_CHECKINGAnyBinaryIOLiteralNoReturnUnionoverload)GenerationErrorHfHubHTTPErrorIncompleteGenerationErrorOverloadedErrorTextGenerationErrorUnknownErrorValidationError)get_sessionis_numpy_availableis_pillow_available)ChatCompletionStreamOutputTextGenerationStreamOutputImager   ztext-to-imagezimage-to-imagec                   ,   a  ] tR t^8t o V 3R ltRtV tR# )RequestParametersc                   < V ^8  d   Qh/ S[ ;R&   S[ ;R&   S[ R,          ;R&   S[ S[,          S[,          R,          ;R&   S[R,          ;R&   S[S[ S[3,          ;R&   # )   urltaskNmodeljsondataheaders)strdictlistbytesr   )format__classdict__s   "y/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/huggingface_hub/inference/_common.py__annotate__RequestParameters.__annotate__8   sm     	H  I  :	 
 *t
d
""  $,  #s(^      N)__name__
__module____qualname____firstlineno____annotate_func____static_attributes____classdictcell__)r*   s   @r+   r   r   8   s      r.   r   c                   R   a a ] tR t^Bt oRtRV3R lV 3R llltV3R ltRtVtV ;t	# )	MimeBytesz
A bytes object with a mime type.
To be returned by `_prepare_payload_open_as_mime_bytes` in subclasses.

Example:
```python
    >>> b = MimeBytes(b"hello", "text/plain")
    >>> isinstance(b, bytes)
    True
    >>> b.mime_type
    'text/plain'
```
c                4   < V ^8  d   QhRS[ RS[R,          /# )r   r#   	mime_typeN)r(   r%   )r)   r*   s   "r+   r,   MimeBytes.__annotate__S   s      5 S4Z r.   c                   < \         SV `  W4      pW#n        \        V\        4      '       d   Vf   VP                  Vn        V# N)super__new__r:   
isinstancer8   )clsr#   r:   obj	__class__s   &&& r+   r?   MimeBytes.__new__S   s8    goc(!dI&&9+< NNCM
r.   c                4   < V ^8  d   Qh/ S[ R,          ;R&   # )r   Nr:   r%   )r)   r*   s   "r+   r,   r;   B   s      Tz r.   r/   r=   )
r0   r1   r2   r3   __doc__r?   r4   r5   r6   __classcell__)rC   r*   s   @@r+   r8   r8   B   s       #  r.   r8   c                 D    \        4       '       g   \        R4      h^ RIp V # )z.Make sure `numpy` is installed on the machine.zGPlease install numpy to use deal with embeddings (`pip install numpy`).N)r   ImportErrornumpy)rK   s    r+   _import_numpyrL   ^   s    cddLr.   c                 H    \        4       '       g   \        R4      h^ RIHp  V # )z,Make sure `PIL` is installed on the machine.zPlease install Pillow to use deal with images (`pip install Pillow`). If you don't want the image to be post-processed, use `client.post(...)` and get the raw response from the server.r   )r   rJ   PILr   r   s    r+   _import_pil_imagerO   g   s(      `
 	
 Lr.   c                0    V ^8  d   QhR\         R\        /# r   contentreturnContentTr8   )r)   s   "r+   r,   r,   w   s     < < <i <r.   c                     R # r=   r/   rR   s   &r+   _open_as_mime_bytesrX   v   s    9<r.   c                L    V ^8  d   QhR\         R,          R\         R,          /# r   rR   NrS   )r	   )r)   s   "r+   r,   r,   {   s     E E E74= Er.   c                     R # r=   r/   rW   s   &r+   rX   rX   z   s    BEr.   c                L    V ^8  d   QhR\         R,          R\        R,          /# rZ   rT   )r)   s   "r+   r,   r,   ~   s#     ? ?D ?Y5E ?r.   c                F   V f   R# \        V \        4      '       d   \        V 4      # \        V \        \        34      '       d   \        \        V 4      4      # \        V R4      '       d   \        P                  R4       V P                  4       p\        V R4      '       d1   \        P                  ! \        V P                  4      4      ^ ,          MRp\        V\        4      '       d   \        R4      h\        WR7      # \        V \        4      '       d   V P                  R4      '       g   V P                  R4      '       d   \        P                  R	V  24       \        4       P!                  V 4      pVP"                  P!                  R
4      pVf   \        P                  ! V 4      ^ ,          p\        VP$                  VR7      # \'        V 4      p V P)                  4       '       g   \+        RV  R24      h\        V \&        4      '       dO   \        P                  RV  24       \        V P-                  4       \        P                  ! V 4      ^ ,          R7      # \/        4       '       d   ^ RIHp \        WP2                  4      '       d   \        P                  R4       \4        P6                  ! 4       pV P8                  ;'       g    RpV P;                  WVR7       \        VP=                  4       RVP?                  4        2R7      # \        R\A        V 4       R24      h)zOpen `content` as a binary file, either from a URL, a local path, raw bytes, or a PIL Image.

Do nothing if `content` is None.
NreadzReading content from BinaryIOnamez3Expected binary stream (bytes), but got text stream)r:   https://http://zDownloading content from zContent-TypezFile not found at z. If `data` is a string, it must either be a URL or a path to a local file. To pass raw content, please encode it as bytes first.zOpening content from r   zConverting PIL Image to bytesPNG)r)   zimage/zUnsupported content type: zl. Expected one of: bytes, bytearray, BinaryIO, memoryview, Path, str (URL or file path), or PIL.Image.Image.)!r@   r(   r8   	bytearray
memoryviewhasattrloggerdebugr^   	mimetypes
guess_typer%   r_   	TypeError
startswithr   getr$   rR   r   existsFileNotFoundError
read_bytesr   rN   r   ioBytesIOr)   savegetvaluelowertype)rR   r#   r:   responser   bufferr)   s   &      r+   rX   rX   ~   sx     '5!!!! 'Iz233w(( w45||~BI'SYBZBZI((W\\):;A>`d	dC  QRR33 '3j))W-?-?	-J-JLL4WI>?"}((1H ((,,^<I %009!<	X--CCw-~~#$WI .O O  '4  ,WI67++-9M9Mg9VWX9YZZ g{{++LL89ZZ\F^^,,uFLLL/V__.F6<<>BR:STT 
$T']O 4u 	u r.   c                0    V ^8  d   QhR\         R\        /# rQ   rU   r%   )r)   s   "r+   r,   r,      s     0 0 0c 0r.   c                `    \        V 4      p\        P                  ! V4      P                  4       # )z\Encode a raw file (image, audio) into base64. Can be bytes, an opened file, a path or a URL.)rX   base64	b64encodedecode)rR   	raw_bytess   & r+   _b64_encoder      s&    #G,II&--//r.   c                <    V ^8  d   QhR\         R\        R\        /# )r   rR   default_mime_typerS   ry   )r)   s   "r+   r,   r,      s!     5 5X 5# 5# 5r.   c                     \        V \        4      '       d   V P                  R4      '       d   V # \        V 4      pVP                  ;'       g    Tp\
        P                  ! V4      P                  4       pRV RV 2# )ra   data:z;base64,)ra   r`   r   )r@   r%   rk   rX   r:   r{   r|   r}   )rR   r   r~   r:   encoded_datas   &&   r+   _as_urlr      sw    '3G$6$67W$X$X $G,I ##88'8I ##I.557L 9+Xl^44r.   c                (    V ^8  d   QhR\         RR/# )r   encoded_imagerS   r   rF   )r)   s   "r+   r,   r,      s     C C C Cr.   c                    \        4       pVP                  ! \        P                  ! \        P
                  ! V 4      4      4      # )z/Parse a base64-encoded string into a PIL Image.)rO   openrp   rq   r{   	b64decode)r   r   s   & r+   _b64_to_imager      s-    E::bjj!1!1-!@ABBr.   c                0    V ^8  d   QhR\         R\        /# rQ   )r(   r'   )r)   s   "r+   r,   r,           ( (E (d (r.   c                J    \         P                  ! V P                  4       4      # )aS  Parse bytes from a Response object into a Python list.

Expects the response body to be JSON-encoded data.

NOTE: This is exactly the same implementation as `_bytes_to_dict` and will not complain if the returned data is a
dictionary. The only advantage of having both is to help the user (and mypy) understand what kind of data to expect.
r"   loadsr}   rW   s   &r+   _bytes_to_listr           ::gnn&''r.   c                0    V ^8  d   QhR\         R\        /# rQ   r(   r&   )r)   s   "r+   r,   r,      r   r.   c                J    \         P                  ! V P                  4       4      # )aS  Parse bytes from a Response object into a Python dictionary.

Expects the response body to be JSON-encoded data.

NOTE: This is exactly the same implementation as `_bytes_to_list` and will not complain if the returned data is a
list. The only advantage of having both is to help the user (and mypy) understand what kind of data to expect.
r   rW   s   &r+   _bytes_to_dictr      r   r.   c                (    V ^8  d   QhR\         RR/# )r   rR   rS   r   )r(   )r)   s   "r+   r,   r,      s     + +U +w +r.   c                b    \        4       pVP                  ! \        P                  ! V 4      4      # )zParse bytes from a Response object into a PIL Image.

Expects the response body to be raw bytes. To deal with b64 encoded images, use `_b64_to_image` instead.
)rO   r   rp   rq   )rR   r   s   & r+   _bytes_to_imager      s$    
 E::bjj)**r.   c                F    V ^8  d   QhR\         \        ,          R\        /# )r   rv   rS   r   )r)   s   "r+   r,   r,      s"     M Mut| M Mr.   c                 ^    \        V \        4      '       d   \        P                  ! V 4      # T # r=   )r@   r(   r"   r   )rv   s   &r+   _as_dictr      s"    #-h#>#>4::hLHLr.   c                    V ^8  d   QhR\         \        ,          R\        R\         \        ,          \         \        ,          ,          /# r   output_linesdetailsrS   )r   r%   boolr   )r)   s   "r+   r,   r,     s7      3-*.c]X899r.   c              #  r   "   V  F  p \        W!4      pTf   K  Tx  K  	  R#   \         d      R# i ; i5i)z*Used in `InferenceClient.text_generation`.N%_format_text_generation_stream_outputStopIterationr   r   lineoutputs   &&  r+    _stream_text_generation_responser     s@     
 	:4IF L   		    7$7
74747c                    V ^8  d   QhR\         \        ,          R\        R\         \        ,          \         \        ,          ,          /# r   )r   r%   r   r   )r)   s   "r+   r,   r,     s9      $/33-(BCCr.   c                  "   V   Rj  xL
  p \        W!4      pTf   K  T5x  K#   L  \         d      R# i ; iD2R# 5i)z/Used in `AsyncInferenceClient.text_generation`.Nr   r   s   &&  r+   &_async_stream_text_generation_responser     sP     
 #  d	:4IF L  		 #:   A =(=A *A A =:A :A c                `    V ^8  d   QhR\         R\        R\         \        ,          R,          /# )r   r   r   rS   N)r%   r   r   )r)   s   "r+   r,   r,     s-     8 8 8d 8sMgGgjnGn 8r.   c                    V P                  R 4      '       g   R# V P                  4       R8X  d   \        R4      hV P                  R 4      P	                  R4      p\
        P                  ! V4      pVP                  R4      e#   \        VR,          VP                  R4      4      h\        P                  ! V4      pV'       g   VP                  P                  # T# )r   Ndata: [DONE][DONE] signal received.z/nerror
error_type)rk   stripr   lstriprstripr"   r   rl   _parse_text_generation_errorr   parse_obj_as_instancetokentext)r   r   payloadjson_payloadr   s   &&   r+   r   r     s    ??7##zz|~%566 kk'"))$/G::g&L  ,*<+@,BRBRS_B`aa (==lKF$+6<<77r.   c                \    V ^8  d   QhR\         \        ,          R\         \        ,          /# r   linesrS   )r   r%   r   )r)   s   "r+   r,   r,   3  s&     
 
C=
()
r.   c              #  r   "   V  F  p \        V4      pTf   K  Tx  K  	  R#   \         d      R# i ; i5i)zFUsed in `InferenceClient.chat_completion` if model is served with TGI.N%_format_chat_completion_stream_outputr   r   r   r   s   &  r+    _stream_chat_completion_responser   3  s@      	:4@F L   		r   c                \    V ^8  d   QhR\         \        ,          R\         \        ,          /# r   )r   r%   r   )r)   s   "r+   r,   r,   @  s'     
 

-.
r.   c                  "   V   Rj  xL
  p \        V4      pTf   K  T5x  K#   L  \         d      R# i ; iD2R# 5i)z/Used in `AsyncInferenceClient.chat_completion`.Nr   r   s   &  r+   &_async_stream_chat_completion_responser   @  sP        d	:4@F L  		 r   c                >    V ^8  d   QhR\         R\        R,          /# )r   r   rS   N)r%   r   )r)   s   "r+   r,   r,   M  s%     J J
J$&Jr.   c                 p   V P                  R 4      '       g   R# V P                  4       R8X  d   \        R4      h\        P                  ! V P                  R 4      P                  4       4      pVP                  R4      e#   \        VR,          VP                  R4      4      h\        P                  ! V4      # )r   Nr   r   r   r   )
rk   r   r   r"   r   r   rl   r   r   r   )r   r   s   & r+   r   r   M  s     ??7##zz|~%566 ::dkk'288:;L  ,*<+@,BRBRS_B`aa &;;LIIr.   c                z    V ^8  d   QhR\         P                  R\         P                  R\        \        ,          /# )r   clientrv   rS   )httpxAsyncClientResponser   r%   )r)   s   "r+   r,   r,   a  s2      E$5$5  TabeTf r.   c                r   "   VP                  4         R j  xL
  pVP                  4       5x  K   LDR # 5ir=   )aiter_linesr   )r   rv   r   s   && r+   _async_yield_fromr   a  s1     **,  djjl,s   7424747c                X    V ^8  d   QhR\         R,          R\        \         ,          RR/# )r   r!   Nunsupported_kwargsrS   r%   r'   )r)   s   "r+   r,   r,   {  s2     Y Y3: YSWX[S\ Yae Yr.   c                 P    \         P                  V . 4      P                  V4       R # r=   )#_UNSUPPORTED_TEXT_GENERATION_KWARGS
setdefaultextend)r!   r   s   &&r+   '_set_unsupported_text_generation_kwargsr   {  s    '225"=DDEWXr.   c                T    V ^8  d   QhR\         R,          R\        \         ,          /# )r   r!   NrS   r   )r)   s   "r+   r,   r,     s"     > >3: >$s) >r.   c                 .    \         P                  V . 4      # r=   )r   rl   )r!   s   &r+   '_get_unsupported_text_generation_kwargsr     s    .225"==r.   c                0    V ^8  d   QhR\         R\        /# )r   
http_errorrS   )r   r
   )r)   s   "r+   r,   r,     s      N x r.   c                   V P                   f   V h \        V RR4      ;'       g    V P                   P                  4       pVP                  R4      pVP                  R4      pTe   \        Y#4      pY@hT h  \         d    T hi ; i)z
Try to parse text-generation-inference error message and raise HTTPError in any case.

Args:
    error (`HTTPError`):
        The HTTPError that have been raised.
Nresponse_error_payloadr   r   )rv   getattrr"   rl   	Exceptionr   )r   r   r   r   	exceptions   &    r+   raise_text_generation_errorr     s     "*&>EccI\I\IaIaIcG$[[.

 0C	'   s   A6 =A6 6Bc                X    V ^8  d   QhR\         R,          R\         R,          R\        /# )r   r   Nr   rS   )r%   r   )r)   s   "r+   r,   r,     s*     	 	d
 	d
 	Ob 	r.   c                     VR 8X  d   \        V 4      # VR8X  d   \        V 4      # VR8X  d   \        V 4      # VR8X  d   \        V 4      # \	        V 4      # )
generationincomplete_generation
overloaded
validation)r   r   r   r   r   )r   r   s   &&r+   r   r     sZ    \!u%%,,(//\!u%%\!u%%r.   c                    V ^8  d   Qh/ ^ \         9   d-   \        \        R,          \        \        ,          3,          ;R&   # )r   Nr   )__conditional_annotations__r&   r%   r'   )r)   s   "r+   r,   r,      s0     K KT F ET#*d3i*?%@ EU Lr.   )Lr   rG   r{   rp   r"   loggingrh   collections.abcr   r   dataclassesr   pathlibr   typingr   r   r   r	   r
   r   r   r   huggingface_hub.errorsr   r   r   r   r   r   r   utilsr   r   r   _generated.typesr   r   	PIL.Imager   r%   UrlTPathTr(   rc   rd   rU   TASKS_EXPECTING_IMAGES	getLoggerr0   rf   r   r8   rL   rO   rX   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r,   )r   s   @r+   <module>r      s_   L  	    3 !  S S S    I H T  c4i%w	:MN *+;< 			8	$    8	 
 < 
 < 
 E 
 E?D05"C((+M8(

J(. DF # EY>:	r.   