
    Zi9              &          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j        d	          f         Zeee          ej        d	          f         ZdeddfdZe                    ddg          dej        ddfdededededdf
d            Ze                    ddg          ddddddddddedee ej        d	          f         d ee ej        d!	          f         d"ee ej        d#	          f         d$ee ej        d%	          f         d&ee ej        d'	          f         d(ee ej        d)	          f         d*ee ej        d+	          f         ded,eee          ej        d-	          f         ded.ee  ej        d/	          f         d0ee  ej        d1	          f         d2eee           ej        d3	          f         d4eee	          ej        d5	          f         d6eee!          ej        d7	          f         ddf"d8            Z"e                    dd9g          	 	 	 	 dYdee ej        d	          f         ded"eee          ej        d:	          f         dededdfd;            Z#	 dZdeddfd<Z$ e                    d=d>g          e$            e                    d?d@A          e$           e%                    edBC           e                    dDg          	 	 d[dedededdfdE            Z&e                    dFg          	 	 	 	 	 	 	 	 	 	 	 	 	 	 d\dededeee          ej        d	          f         d"eee          ej        d#	          f         d$eee          ej        d%	          f         d&eee          ej        d'	          f         d eee          ej        dG	          f         dHeee          ej        dI	          f         d,eee          ej        d-	          f         d.eee           ej        d/	          f         d0eee           ej        d1	          f         d2eee           ej        d3	          f         d4eee	          ej        d5	          f         d6eee!          ej        d7	          f         deddf dJ            Z'e                    dKg          	 	 	 d]dededLee( ej        dMdN	          f         deddf
dO            Z)e                    dPg          	 	 d[dedededdfdQ            Z*e                    dRg          	 	 	 d]dededSee( ej        dTdU	          f         deddf
dV            Z+e                    dWg          	 	 d[dedededdfdX            Z,dS )^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                 b    t          j        t          j        | j        dd                     d S )N   Tindent	sort_keys)typerechojsondumpsraw)r   s    b/root/projects/butler/venv/lib/python3.11/site-packages/huggingface_hub/cli/inference_endpoints.py_print_endpointr   ,   s+    	Jtz(,qDAAABBBBB    zhf endpoints lsz"hf endpoints ls --namespace my-org)examplesF	namespaceformatquiettokenc                    t          |          }	 |                    | |          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wd |D             }dt          t          t          f         dt          t                   fd	}t          |||d
g d|           dS )z6Lists all Inference Endpoints for the given namespace.r%   )r"   r%   zListing failed: codeNc                     g | ]	}|j         
S  )r   ).0r   s     r   
<listcomp>zls.<locals>.<listcomp>?   s    666x|666r    itemr   c                    |                      di           }|                      di           }|                      di           }|                      di           }t          |                      dd                    t          t          |t                    r|                     dd          nd          t          t          |t                    r|                     dd          nd          t          t          |t                    r|                     d	d          nd          t          t          |t                    r|                     d
d          nd          t          t          |t                    r|                     dd          nd          t          t          |t                    r|                     dd          nd          t          t          |t                    r|                     dd          nd          gS )Nstatusmodelcomputeprovidername 
repositorystatetask	frameworkinstanceTypevendorregion)getstr
isinstancedict)r.   r0   r1   r2   r3   s        r   row_fnzls.<locals>.row_fnA   s   (B''"%%((9b))88J++$$%%z%/F/FN		,+++BOO:fd+C+CK

7B'''LLE4)@)@H		&"%%%bIIj.E.EM		+r***2NN:gt3L3LTNB///RTUUj4.H.HPXr***bQQj4.H.HPXr***bQQ	
 		
r    r4   )NAMEMODELSTATUSTASK	FRAMEWORKINSTANCEVENDORREGION)itemsr#   r$   id_keyheadersrA   )r   list_inference_endpointsr   r   r   Exitresponsestatus_coder@   r>   r   listr   )	r"   r#   r$   r%   api	endpointserrorresultsrA   s	            r   lsrV   0   s    5
!
!
!CE009E0RR		 E E E
-e--...jen8999uDE 76I666G
T#s(^ 
S	 
 
 
 
  ```     s   * 
A07A++A0deployzChf endpoints deploy my-endpoint --repo gpt2 --framework pytorch ...)r4   r!   )r"   r8   r%   min_replicamax_replicascale_to_zero_timeoutscaling_metricscaling_thresholdr4   repozeThe name of the model repository associated with the Inference Endpoint (e.g. 'openai/gpt-oss-120b').r9   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').r<   zTThe cloud region in which the Inference Endpoint will be created (e.g. 'us-east-1').r;   zVThe cloud provider or vendor where the Inference Endpoint will be hosted (e.g. 'aws').r8   zCThe task on which to deploy the model (e.g. 'text-classification').rX   zVThe minimum number of replicas (instances) to keep running for the Inference Endpoint.rY   zRThe maximum number of replicas (instances) to scale to for the Inference Endpoint.rZ   zFThe duration in minutes before an inactive endpoint is scaled to zero.r[   z!The metric reference for scaling.r\   zeThe scaling metric threshold used to trigger a scale up. Ignored when scaling metric is not provided.c                    t          |
          }|                    | |||||||||	|
|||||          }t          |           dS )z3Deploy an Inference Endpoint from a Hub repository.r'   )r4   r6   r9   r^   r_   r`   r<   r;   r"   r8   r%   rX   rY   r[   r\   rZ   N)r   create_inference_endpointr   )r4   r]   r9   r^   r_   r`   r<   r;   r"   r8   r%   rX   rY   rZ   r[   r\   rR   r   s                     r   rW   rW   [   su    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          |          }	 |                    | ||||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          |           dS )z4Deploy an Inference Endpoint from the Model Catalog.r'   )repo_idr4   r^   r"   r%   zDeployment failed: r(   N)	r   &create_inference_endpoint_from_catalogr   r   r   rN   rO   rP   r   )r]   r4   r^   r"   r%   rR   r   rT   s           r   deploy_from_catalogrf      s    & 5
!
!
!C
E==# > 
 
  E E E
000111jen8999uDE H   - 
A37A..A3c                 >   t          |           }	 |                    |           }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          j        t          j	        d|idd                     dS )	zList available Catalog models.r'   zCatalog fetch failed: r(   Nmodelsr   Tr   )
r   list_inference_catalogr   r   r   rN   rO   rP   r   r   )r%   rR   ri   rT   s       r   list_catalogrk      s     5
!
!
!CE++%+88 E E E
3E33444jen8999uDE 
Jtz8V,Q$GGGHHHHHs   ) 
A/7A**A/rV   zhf endpoints catalog lszlist-catalogT)r4   hiddencatalog)r4   z!hf endpoints describe my-endpointc                 
   t          |          }	 |                    | ||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          |           dS )z+Get information about an existing endpoint.r'   r4   r"   r%   zFetch failed: r(   N)	r   get_inference_endpointr   r   r   rN   rO   rP   r   r4   r"   r%   rR   r   rT   s         r   describerr      s     5
!
!
!CE--49TY-ZZ E E E
+E++,,,jen8999uDE H   + 
A17A,,A1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          |          }	 |                    | |||||||||	|
||||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          |           dS )zUpdate an existing endpoint.r'   )r4   r"   r6   r9   rt   r8   r^   r_   r`   rX   rY   rZ   r[   r\   r%   zUpdate failed: r(   N)	r   update_inference_endpointr   r   r   rN   rO   rP   r   )r4   r"   r]   r^   r_   r`   r9   rt   r8   rX   rY   rZ   r[   r\   r%   rR   r   rT   s                     r   updaterw     s    ^ 5
!
!
!CE00#''##"7)/ 1 
 
"  E E E
,U,,---jen8999uDE Hs   $7 
A=7A88A=zhf endpoints delete my-endpointyesz--yeszSkip confirmation prompts.c                    |sGt          j        d|  d          }|| k    r)t          j        d           t          j        d          t	          |          }	 |                    | ||           nI# t          $ r<}t          j        d|            t          j        |j        j                  |d	}~ww xY wt          j        d
|  d           d	S )z)Delete an Inference Endpoint permanently.zDelete endpoint 'z'? Type the name to confirm.zAborted.r   r(   r'   ro   zDelete failed: Nz	Deleted 'z'.)	r   promptr   rN   r   delete_inference_endpointr   rO   rP   )r4   r"   rx   r%   confirmationrR   rT   s          r   deleter}   y  s     %|$Z$Z$Z$Z[[4Jz"""*!$$$$
5
!
!
!CE%%49E%RRRR E E E
,U,,---jen8999uDE 
J#4###$$$$$s   A4 4
B:>7B55B:zhf endpoints pause my-endpointc                 
   t          |          }	 |                    | ||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          |           dS )zPause an Inference Endpoint.r'   ro   zPause failed: r(   N)	r   pause_inference_endpointr   r   r   rN   rO   rP   r   rq   s         r   pauser     s     5
!
!
!CE//TYV[/\\ E E E
+E++,,,jen8999uDE Hrs   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          |          }	 |                    | |||           }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          |           dS )zResume an Inference Endpoint.r'   )r4   r"   r%   
running_okzResume failed: r(   N)	r   resume_inference_endpointr   r   r   rN   rO   rP   r   )r4   r"   r   r%   rR   r   rT   s          r   resumer     s     5
!
!
!C	E0022	 1 
 
  E E E
,U,,---jen8999uDE Hrg   z&hf endpoints scale-to-zero my-endpointc                 
   t          |          }	 |                    | ||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          |           dS )z$Scale an Inference Endpoint to zero.r'   ro   zScale To Zero failed: r(   N)	r    scale_to_zero_inference_endpointr   r   r   rN   rO   rP   r   rq   s         r   scale_to_zeror     s     5
!
!
!CE77TY^c7dd E E E
3E33444jen8999uDE Hrs   )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tablerV   intfloatrW   rf   rk   	add_typerrr   rw   boolr}   r   r   r   r+   r    r   <module>r      se   8 8  + + + + + + + + + +  b b b b b b b b 1 1 1 1 1 1                  
F	G	G	Gm!QRRR EN()))+ SMEL&''')
 SMELn  C/ CD C C C C +-QRSS"$*	' ''' ' 	'
 
' ' ' TS'T X)n(opp\ # 	 	
 	
 	 	 	ei i 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 i i qpiX (.s-tuu  	" 
x	
 	
 	
	  c	
 	
 	
	    
!   vuF I II	I I I I E  )B(C  D D\ R R R 0N4 0 0 > > >   9  - - - =>?? # 
  
	   @?  KLMM # 	 	 	 	 	 	 	 	 	 	 	 	Wd 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 d d NMdN ;<== # 	% %
%% 
W#?@@@	B
% % 
% % % >=%4 :;<< # 
  
	   =<  ;<== # 	 
 ''j	
 	
 	
	  
   >=6 BCDD # 
  
	   ED  r    