
    qi9              &       
   d Z ddlZddlmZmZmZ ddlZddlmZm	Z	 ddl
mZ ddlmZmZmZmZmZmZmZ  ed	      Z ed
	      Zee ej.                  d	      f   Zeee    ej2                  d	      f   Zeee    ej2                  d	      f   ZdeddfdZej;                  ddg      dej<                  ddfdededededdf
d       Zej;                  ddg      ddddddddddedee ej2                  d	      f   d ee ej2                  d!	      f   d"ee ej2                  d#	      f   d$ee ej2                  d%	      f   d&ee ej2                  d'	      f   d(ee ej2                  d)	      f   d*ee ej2                  d+	      f   ded,eee    ej2                  d-	      f   ded.ee  ej2                  d/	      f   d0ee  ej2                  d1	      f   d2eee     ej2                  d3	      f   d4eee	    ej2                  d5	      f   d6eee!    ej2                  d7	      f   ddf"d8       Z"ej;                  dd9g      	 	 	 	 dYdee ej2                  d	      f   ded"eee    ej2                  d:	      f   dededdfd;       Z#	 dZdeddfd<Z$ ej;                  d=d>g      e$        ej;                  d?d@A      e$       ejK                  edBC       ej;                  dDg      	 	 d[dedededdfdE       Z&ej;                  dFg      	 	 	 	 	 	 	 	 	 	 	 	 	 	 d\dededeee    ej2                  d	      f   d"eee    ej2                  d#	      f   d$eee    ej2                  d%	      f   d&eee    ej2                  d'	      f   d eee    ej2                  dG	      f   dHeee    ej2                  dI	      f   d,eee    ej2                  d-	      f   d.eee     ej2                  d/	      f   d0eee     ej2                  d1	      f   d2eee     ej2                  d3	      f   d4eee	    ej2                  d5	      f   d6eee!    ej2                  d7	      f   deddf dJ       Z'ej;                  dKg      	 	 	 d]dededLee( ej2                  dMdN	      f   deddf
dO       Z)ej;                  dPg      	 	 d[dedededdfdQ       Z*ej;                  dRg      	 	 	 d]dededSee( ej2                  dTdU	      f   deddf
dV       Z+ej;                  dWg      	 	 d[dedededdfdX       Z,y)^z2CLI commands for Hugging Face Inference Endpoints.    N)	AnnotatedAnyOptional)InferenceEndpointInferenceEndpointScalingMetric)HfHubHTTPError   )	FormatOptOutputFormatQuietOptTokenOpt
get_hf_apiprint_list_outputtyper_factoryz(Manage Hugging Face Inference Endpoints.)helpz.Interact with the Inference Endpoints catalog.zEndpoint name.z_The namespace associated with the Inference Endpoint. Defaults to the current user's namespace.endpointreturnc                 n    t        j                  t        j                  | j                  dd             y )N   Tindent	sort_keys)typerechojsondumpsraw)r   s    Y/opt/pipecat/venv/lib/python3.12/site-packages/huggingface_hub/cli/inference_endpoints.py_print_endpointr   ,   s    	JJtzz(,,qDAB    zhf endpoints lsz"hf endpoints ls --namespace my-org)examplesF	namespaceformatquiettokenc                    t        |      }	 |j                  | |      }|D cg c]  }|j                   }}dt        t        t        f   dt        t           fd}	t        |||d	g d
|	       y# t        $ rH}t        j                  d|        t        j
                  |j                  j                        |d}~ww xY wc c}w )z6Lists all Inference Endpoints for the given namespace.r%   )r"   r%   zListing failed: codeNitemr   c                 <   | j                  di       }| j                  di       }| j                  di       }| j                  di       }t        | j                  dd            t        t        |t              r|j                  dd      nd      t        t        |t              r|j                  dd      nd      t        t        |t              r|j                  d	d      nd      t        t        |t              r|j                  d
d      nd      t        t        |t              r|j                  dd      nd      t        t        |t              r|j                  dd      nd      t        t        |t              r|j                  dd            gS d      gS )Nstatusmodelcomputeprovidername 
repositorystatetask	frameworkinstanceTypevendorregion)getstr
isinstancedict)r*   r,   r-   r.   r/   s        r   row_fnzls.<locals>.row_fnA   sD   (B'"%((9b)88J+$%z%/F		,+BO:fd+C

7B'LE4)@		&"%bIj.E		+r*2N:gt3LNB/RTUj4.HXr*bQj4.HXr*Q	
 		
 OQQ	
 		
r    r0   )NAMEMODELSTATUSTASK	FRAMEWORKINSTANCEVENDORREGION)itemsr#   r$   id_keyheadersr=   )r   list_inference_endpointsr   r   r   Exitresponsestatus_coder   r<   r:   r   listr   )
r"   r#   r$   r%   api	endpointserrorr   resultsr=   s
             r   lsrR   0   s     5
!CE009E0R	
 -66x||6G6
T#s(^ 
S	 
  `-  E

%eW-.jjenn889uDE 7s   A2 C2	C;AB>>CdeployzChf endpoints deploy my-endpoint --repo gpt2 --framework pytorch ...)r0   r!   )r"   r4   r%   min_replicamax_replicascale_to_zero_timeoutscaling_metricscaling_thresholdr0   repozeThe name of the model repository associated with the Inference Endpoint (e.g. 'openai/gpt-oss-120b').r5   z@The machine learning framework used for the model (e.g. 'vllm').acceleratorz?The hardware accelerator to be used for inference (e.g. 'cpu').instance_sizezNThe size or type of the instance to be used for hosting the model (e.g. 'x4').instance_typezYThe cloud instance type where the Inference Endpoint will be deployed (e.g. 'intel-icl').r8   zTThe cloud region in which the Inference Endpoint will be created (e.g. 'us-east-1').r7   zVThe cloud provider or vendor where the Inference Endpoint will be hosted (e.g. 'aws').r4   zCThe task on which to deploy the model (e.g. 'text-classification').rT   zVThe minimum number of replicas (instances) to keep running for the Inference Endpoint.rU   zRThe maximum number of replicas (instances) to scale to for the Inference Endpoint.rV   zFThe duration in minutes before an inactive endpoint is scaled to zero.rW   z!The metric reference for scaling.rX   zeThe scaling metric threshold used to trigger a scale up. Ignored when scaling metric is not provided.c                t    t        |
      }|j                  | |||||||||	|
|||||      }t        |       y)z3Deploy an Inference Endpoint from a Hub repository.r'   )r0   r2   r5   rZ   r[   r\   r8   r7   r"   r4   r%   rT   rU   rW   rX   rV   N)r   create_inference_endpointr   )r0   rY   r5   rZ   r[   r\   r8   r7   r"   r4   r%   rT   rU   rV   rW   rX   rN   r   s                     r   rS   rS   [   s^    l 5
!C,,##%+3! - H& Hr    zChf endpoints catalog deploy --repo meta-llama/Llama-3.2-1B-InstructzPThe hardware accelerator to be used for inference (e.g. 'cpu', 'gpu', 'neuron').c                    t        |      }	 |j                  | ||||      }t        |       y# t        $ rH}t        j                  d|        t        j
                  |j                  j                        |d}~ww xY w)z4Deploy an Inference Endpoint from the Model Catalog.r'   )repo_idr0   rZ   r"   r%   zDeployment failed: r(   N)	r   &create_inference_endpoint_from_catalogr   r   r   rJ   rK   rL   r   )rY   r0   rZ   r"   r%   rN   r   rP   s           r   deploy_from_catalogrb      s    & 5
!C
E==# > 
 H	  E

(01jjenn889uDE   0 	BAA<<Bc                 D   t        |       }	 |j                  |       }t        j                  t        j                  d|idd             y# t        $ rH}t        j                  d|        t        j
                  |j                  j                        |d}~ww xY w)	zList available Catalog models.r'   zCatalog fetch failed: r(   Nmodelsr   Tr   )
r   list_inference_catalogr   r   r   rJ   rK   rL   r   r   )r%   rN   re   rP   s       r   list_catalogrg      s     5
!CE++%+8
 
JJtzz8V,Q$GH	  E

+E734jjenn889uDEs   A 	BABBrR   zhf endpoints catalog lszlist-catalogT)r0   hiddencatalog)r0   z!hf endpoints describe my-endpointc                    t        |      }	 |j                  | ||      }t        |       y# t        $ rH}t        j                  d|        t        j
                  |j                  j                        |d}~ww xY w)z+Get information about an existing endpoint.r'   r0   r"   r%   zFetch failed: r(   N)	r   get_inference_endpointr   r   r   rJ   rK   rL   r   r0   r"   r%   rN   r   rP   s         r   describern      sx     5
!CE--49TY-Z
 H	  E

^E7+,jjenn889uDE   . 	A?AA::A?z/hf endpoints update my-endpoint --min-replica 2zBThe machine learning framework used for the model (e.g. 'custom').revisionzrThe specific model revision to deploy on the Inference Endpoint (e.g. '6c0e6080953db56375760c0471a8c5f2929baf11').c                    t        |      }	 |j                  | |||||||||	|
||||      }t        |       y# t        $ rH}t        j                  d|        t        j
                  |j                  j                        |d}~ww xY w)zUpdate an existing endpoint.r'   )r0   r"   r2   r5   rp   r4   rZ   r[   r\   rT   rU   rV   rW   rX   r%   zUpdate failed: r(   N)	r   update_inference_endpointr   r   r   rJ   rK   rL   r   )r0   r"   rY   rZ   r[   r\   r5   rp   r4   rT   rU   rV   rW   rX   r%   rN   r   rP   s                     r   updaters     s    ^ 5
!CE00#''##"7)/ 1 
( H  E

_UG,-jjenn889uDEs    : 	BABBzhf endpoints delete my-endpointyesz--yeszSkip confirmation prompts.c                    |sIt        j                  d|  d      }|| k7  r+t        j                  d       t        j                  d      t	        |      }	 |j                  | ||       t        j                  d
|  d       y	# t        $ rH}t        j                  d|        t        j                  |j                  j                        |d	}~ww xY w)z)Delete an Inference Endpoint permanently.zDelete endpoint 'z'? Type the name to confirm.zAborted.r   r(   r'   rk   zDelete failed: Nz	Deleted 'z'.)	r   promptr   rJ   r   delete_inference_endpointr   rK   rL   )r0   r"   rt   r%   confirmationrN   rP   s          r   deletery   y  s     ||&7v=Y$Z[4JJz"**!$$
5
!CE%%49E%R
 
JJ4&#$	  E

_UG,-jjenn889uDEs   B 	CACCzhf endpoints pause my-endpointc                    t        |      }	 |j                  | ||      }t        |       y# t        $ rH}t        j                  d|        t        j
                  |j                  j                        |d}~ww xY w)zPause an Inference Endpoint.r'   rk   zPause failed: r(   N)	r   pause_inference_endpointr   r   r   rJ   rK   rL   r   rm   s         r   pauser|     sx     5
!CE//TYV[/\
 H	  E

^E7+,jjenn889uDEro   zhf endpoints resume my-endpointfail_if_already_runningz--fail-if-already-runningzWIf `True`, the method will raise an error if the Inference Endpoint is already running.c                    t        |      }	 |j                  | |||       }t        |       y# t        $ rH}t        j                  d|        t        j
                  |j                  j                        |d}~ww xY w)zResume an Inference Endpoint.r'   )r0   r"   r%   
running_okzResume failed: r(   N)	r   resume_inference_endpointr   r   r   rJ   rK   rL   r   )r0   r"   r}   r%   rN   r   rP   s          r   resumer     s     5
!C	E0022	 1 
 H  E

_UG,-jjenn889uDErc   z&hf endpoints scale-to-zero my-endpointc                    t        |      }	 |j                  | ||      }t        |       y# t        $ rH}t        j                  d|        t        j
                  |j                  j                        |d}~ww xY w)z$Scale an Inference Endpoint to zero.r'   rk   zScale To Zero failed: r(   N)	r    scale_to_zero_inference_endpointr   r   r   rJ   rK   rL   r   rm   s         r   scale_to_zeror     sy     5
!CE77TY^c7d
 H	  E

+E734jjenn889uDEro   )NNNN)N)NN)NNNNNNNNNNNNNN)NFN)-__doc__r   typingr   r   r   r   $huggingface_hub._inference_endpointsr   r   huggingface_hub.errorsr   
_cli_utilsr
   r   r   r   r   r   r   ie_clicatalog_appr:   ArgumentNameArgOptionNameOptNamespaceOptr   commandtablerR   intfloatrS   rb   rg   	add_typerrn   rs   boolry   r|   r   r    r    r   <module>r      s	   8  + +  b 1   
F	G!QR ENN()+ SMELL&')
 SMELLnC/ CD C +-QRS"$**	''' ' 	'
 
' T'T X)n(op\ # 	 	
 	
 	 	 	ei
i
x	
	i S	
	i R	
	i( a	
	)i4 l	
	5i@ g	
	AiL i	
	MiZ [i\ V	
	]ih iij i	
	kiv e	
	wiB %Y	
	CiN /04	
	OiZ !x	
	[if 
gi qiX (.s-tu  	"
x	
	  c	
	    
! vF II	I E  )B(C  D\ R 0N4 0 >   9  - =>? #
  
	 @  KLM # 	 	 	 	 	 	 	 	 	 	 	 	Wd
dd x	
	d R	
	d a	
	d* l	
	+d6 U	
	7dB  F	
	CdN V	
	OdZ i	
	[df e	
	gdr %Y	
	sd~ /04	
	dJ !x	
	KdV WdX 
Yd NdN ;<= # 	%
%% 
W#?@	B
% % 
% >%4 :;< #
  
	 =  ;<= # 	
 ''j	
	  
 >6 BCD #
  
	 Er    