
    -:jbD              ?       
   d Z ddlZddlmZ ddlZddlmZmZ ddlm	Z	m
Z
 ddlmZmZmZmZmZmZmZmZmZmZ ddlmZ  ed	
      Z ed
      Zee ej6                  d
      f   Zeedz   ej:                  d
      f   Zeedz   ej:                  d
      f   ZejA                  dddg      	 	 djdededdfd       Z!ejA                  ddg      ddddddddddd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dz   ej:                  d*
      f   ded+ee" ej:                  d,
      f   d-ee" ej:                  d.
      f   d/ee"dz   ej:                  d0
      f   d1eedz   ej:                  d2
      f   d3ee#dz   ej:                  d4
      f   d5ed6eedz   ej:                  d7d8
      f   d9eedz   ej:                  d:
      f   d;ee"dz   ej:                  d<
      f   d=eedz   ej:                  d>d?
      f   d@eedz   ej:                  dAdB
      f   dCedDedEedFedGeedz   ej:                  dH ee      dIJ      f   ddf8dK       Z$ejA                  ddLg      	 	 	 	 dkdee ej:                  d
      f   dedeedz   ej:                  dM
      f   dededdfdN       Z%	 dldeddfdOZ& ejA                  ddPg      e&        ejA                  dQdRS      e&       ejO                  edTU       ejA                  dVg      	 	 djdedededdfdW       Z(ejA                  dXg      	 	 	 	 	 	 	 	 	 	 	 	 	 	 dmdededeedz   ej:                  d
      f   deedz   ej:                  d 
      f   d!eedz   ej:                  d"
      f   d#eedz   ej:                  d$
      f   deedz   ej:                  dY
      f   d5eedz   ej:                  dZ
      f   d)eedz   ej:                  d*
      f   d+ee"dz   ej:                  d,
      f   d-ee"dz   ej:                  d.
      f   d/ee"dz   ej:                  d0
      f   d1eedz   ej:                  d2
      f   d3ee#dz   ej:                  d4
      f   deddf d[       Z)ejA                  d\g      	 	 	 dndeded]ee* ej:                  d^d_
      f   deddf
d`       Z+ejA                  dag      	 	 djdedededdfdb       Z,ejA                  dcg      	 	 	 dndededdee* ej:                  dedf
      f   deddf
dg       Z-ejA                  dhg      	 	 djdedededdfdi       Z.y)oz2CLI commands for Hugging Face Inference Endpoints.    N)	Annotated)InferenceEndpointScalingMetricInferenceEndpointType)CLIErrorHfHubHTTPError   )

EnvFileOptEnvOptRevisionOptSecretsFileOpt
SecretsOpt
SoftChoiceTokenOpt
get_hf_apiparse_env_maptyper_factory)outz(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.z	list | lszhf endpoints lsz"hf endpoints ls --namespace my-org)examples	namespacetokenreturnc                    t        |      }	 |j                  | |      }g }|D ]o  }|j                  }|j                  di       }|j                  di       }	|j                  di       }
|j                  d	i       }|j                  |j                  d
d      t        |	t              r|	j                  dd      ndt        |t              r|j                  dd      ndt        |	t              r|	j                  dd      ndt        |	t              r|	j                  dd      ndt        |
t              r|
j                  dd      ndt        |t              r|j                  dd      ndt        |t              r|j                  dd      ndd       r t        j                  |d
       y# t        $ rH}t        j                  d|        t        j                  |j                  j                        |d}~ww xY w)z6Lists all Inference Endpoints for the given namespace.r   )r   r   zListing failed: codeNstatusmodelcomputeprovidername 
repositorystatetask	frameworkinstanceTypevendorregion)r!   r   r   r%   r&   instancer(   r)   )id_key)r   list_inference_endpointsr   r   errortyperExitresponsestatus_coderawgetappend
isinstancedicttable)r   r   api	endpointsr-   resultsendpointr2   r   r   r   r    s               i/var/www/html/tokenscope/api/venv/lib/python3.12/site-packages/huggingface_hub/cli/inference_endpoints.pylsr=   0   s    5
!CE009E0R	
 G 
ll2&$'')R(77:r*+8B5$8O<4UW5?5M&**Wb1SU1;E41H		&"-b;EeT;RUYY{B7XZ?I'SW?XGKK;^`8B8T8R(,,x4XZ8B8T8R(,,x4XZ		

$ IIgf%/  E		$UG,-jjenn889uDEs   F0 0	H9AG<<HdeployzChf endpoints deploy my-endpoint --repo gpt2 --framework pytorch ...)r!   r   )r   r%   r   min_replicamax_replicascale_to_zero_timeoutscaling_metricscaling_thresholdrevisioncustom_imagehealth_routeportcontainer_commandcontainer_argsenvenv_filesecretssecrets_fileendpoint_typer!   repozeThe name of the model repository associated with the Inference Endpoint (e.g. 'openai/gpt-oss-120b').r&   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').r%   zCThe task on which to deploy the model (e.g. 'text-classification').r?   zVThe minimum number of replicas (instances) to keep running for the Inference Endpoint.r@   zRThe maximum number of replicas (instances) to scale to for the Inference Endpoint.rA   zFThe duration in minutes before an inactive endpoint is scaled to zero.rB   z!The metric reference for scaling.rC   zeThe scaling metric threshold used to trigger a scale up. Ignored when scaling metric is not provided.rD   rE   z--custom-imagezfDocker image URL for a custom container (e.g. 'nexagi/sglang:v0.5.12'). Requires '--framework custom'.rF   z]Health check route exposed by the custom container (e.g. '/health'). Requires --custom-image.rG   zKPort the custom container listens on (e.g. 30000). Requires --custom-image.rH   z--container-commandzOverride the container entrypoint, as a quoted string split into tokens (e.g. "python -m sglang.launch_server"). Requires --custom-image.rI   z--container-argszArguments appended to the container entrypoint, as a quoted string split into tokens (e.g. "--tp 8 --reasoning-parser qwen3"). Requires --custom-image.rJ   rK   rL   rM   rN   z--typezTEndpoint access type. Defaults to 'authenticated' (token-gated, publicly reachable).)
click_typer   c                   ||||s|rt        d      d}|d|i}|||d<   |||d<   t        ||      j                         D ci c]  \  }}||xs d }}}t        ||      j                         D ci c]  \  }}||xs d }}}i } ||| d<   ||| d<   |rt        j                  |      | d	<   |rt        j                  |      | d
<   |r|| d<   |r|| d<   t        |
      }! |!j                  d!i d| d|d|d|d|d|d|d|d|d|	d|
d|d|d|d|d|d|| }"t        j                  |"j                         t        j                  d|  d        yc c}}w c c}}w )"z3Deploy an Inference Endpoint from a Hub repository.NzX--health-route, --port, --container-command and --container-args require --custom-image.urlhealthRouterG   r"   typerE   rH   rI   rJ   rL   r   r!   r#   r&   rP   rQ   rR   r)   r(   r   r%   r   r?   r@   rB   rC   rA   rD   zUse 'hf endpoints describe z!' to check the deployment status. )r   r   itemsshlexsplitr   create_inference_endpointr   r6   r2   hint)#r!   rO   r&   rP   rQ   rR   r)   r(   r   r%   r   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   custom_image_dictkeyvalueenv_mapsecrets_mapparamsr8   r;   s#                                      r<   r>   r>   S   s&   V !9T=MQbftqrr%)"L1#/;m,(,f%2?X2N2T2T2VWJCsEKRWGW6CG\6Z6`6`6bc
U3#cKc F &v$!2~&+kk2C&D"##(;;~#> u'y
5
!C,s,,    	
 $ $          & ,  4!" 
%H( HHX\\HH*4&0QRSQ Xcs   	E*:E0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                 0   t        |      }	 |j                  | ||||      }t        j                  |j                         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_idr!   rP   r   r   zDeployment failed: r   N)r   &create_inference_endpoint_from_catalogr   r   r-   r.   r/   r0   r1   r6   r2   )rO   r!   rP   r   r   r8   r;   r-   s           r<   deploy_from_catalogrg     s    & 5
!C
E==# > 
 HHX\\	  E		'w/0jjenn889uDE   A 	BABBc                    t        |       }	 |j                  |       }t        j                  d|i       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models)
r   list_inference_catalogr   r   r-   r.   r/   r0   r1   r6   )r   r8   rj   r-   s       r<   list_catalogrl   6  s}     5
!CE++%+8
 HHh 	  E		*5'23jjenn889uDEs   8 	B	ABB	zhf endpoints catalog lszlist-catalogT)r!   hiddencatalogr!   z!hf endpoints describe my-endpointc                 ,   t        |      }	 |j                  | ||      }t        j                  |j                         y# t        $ rH}t        j                  d|        t        j                  |j                  j                        |d}~ww xY w)z+Get information about an existing endpoint.r   r!   r   r   zFetch failed: r   N)r   get_inference_endpointr   r   r-   r.   r/   r0   r1   r6   r2   r!   r   r   r8   r;   r-   s         r<   describert   K  s     5
!CE--49TY-Z
 HHX\\	  E		N5'*+jjenn889uDE   A 	BABBz/hf endpoints update my-endpoint --min-replica 2zBThe machine learning framework used for the model (e.g. 'custom').zrThe specific model revision to deploy on the Inference Endpoint (e.g. '6c0e6080953db56375760c0471a8c5f2929baf11').c                 D   t        |      }	 |j                  | |||||||||	|
||||      }t        j                  |j                         y# t        $ rH}t        j                  d|        t        j                  |j                  j                        |d}~ww xY w)zUpdate an existing endpoint.r   )r!   r   r#   r&   rD   r%   rP   rQ   rR   r?   r@   rA   rB   rC   r   zUpdate failed: r   N)r   update_inference_endpointr   r   r-   r.   r/   r0   r1   r6   r2   )r!   r   rO   rP   rQ   rR   r&   rD   r%   r?   r@   rA   rB   rC   r   r8   r;   r-   s                     r<   updaterx   \  s    ^ 5
!CE00#''##"7)/ 1 
( HHX\\  E		OE7+,jjenn889uDEs    A 	BABBzhf endpoints delete my-endpointyesz--yeszSkip confirmation prompts.c                 Z   t        j                  d|  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'?)ry   r   rq   zDelete failed: r   Nz	Deleted 'z'.ro   )r   confirmr   delete_inference_endpointr   r-   r.   r/   r0   r1   result)r!   r   ry   r   r8   r-   s         r<   deleter~     s     KK#D6,#6
5
!CE%%49E%R
 JJ4&#$/	  E		OE7+,jjenn889uDEs   A 	B*"AB%%B*zhf endpoints pause my-endpointc                 ,   t        |      }	 |j                  | ||      }t        j                  |j                         y# t        $ rH}t        j                  d|        t        j                  |j                  j                        |d}~ww xY w)zPause an Inference Endpoint.r   rq   zPause failed: r   N)r   pause_inference_endpointr   r   r-   r.   r/   r0   r1   r6   r2   rs   s         r<   pauser     s     5
!CE//TYV[/\
 HHX\\	  E		N5'*+jjenn889uDEru   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                 0   t        |      }	 |j                  | |||       }t        j                  |j                         y# t        $ rH}t        j                  d|        t        j                  |j                  j                        |d}~ww xY w)zResume an Inference Endpoint.r   )r!   r   r   
running_okzResume failed: r   N)r   resume_inference_endpointr   r   r-   r.   r/   r0   r1   r6   r2   )r!   r   r   r   r8   r;   r-   s          r<   resumer     s     5
!C	E0022	 1 
 HHX\\  E		OE7+,jjenn889uDErh   z&hf endpoints scale-to-zero my-endpointc                 ,   t        |      }	 |j                  | ||      }t        j                  |j                         y# t        $ rH}t        j                  d|        t        j                  |j                  j                        |d}~ww xY w)z$Scale an Inference Endpoint to zero.r   rq   zScale To Zero failed: r   N)r    scale_to_zero_inference_endpointr   r   r-   r.   r/   r0   r1   r6   r2   rs   s         r<   scale_to_zeror     s     5
!CE77TY^c7d
 HHX\\	  E		*5'23jjenn889uDEru   )NN)NNNN)N)NNNNNNNNNNNNNN)NFN)/__doc__rZ   typingr   r.   $huggingface_hub._inference_endpointsr   r   huggingface_hub.errorsr   r   
_cli_utilsr	   r
   r   r   r   r   r   r   r   r   _outputr   ie_clicatalog_appstrArgumentNameArgOptionNameOptNamespaceOptcommandr=   intfloatr>   rg   rl   	add_typerrt   rx   boolr~   r   r   r   rX       r<   <module>r      sB   8    f ;    
F	G!QR ENN()+ $JELL&')
 $JELLn '8:^&_`"&&& 
& a&D X)n(op\ # 	 	
 	
 	 	 	  	 	 	 	 	#' 	M|T
|T
x	
	|T S	
	|T R	
	|T( a	
	)|T4 l	
	5|T@ g	
	A|TL i	
	M|TZ [|T\ d
V	
	]|Th i|Tj i	
	k|Tv e	
	w|TB %d
Y	
	C|TN &-4	
	O|TZ !x	
	[|Tf g|Th d
y	
	i|Tv d
p	
	w|TB d
^	
	C|TN !d
!T	
		O|Tb d
U	
		c|Tv 
w|Tx y|Tz {|T| !}|T~ d
!"78g	
	|TN 
O|T q|T~ (.s-tu  	"
x	
	  d
c	
	    
! vF !!	! L  0I/J  KL Y 0N4 0 >   9  - =>? #
  
	 @  KLM # 	 	 	 	 	 	 	 	 	 	 	 	Wd
dd d
x	
	d d
R	
	d d
a	
	d* d
l	
	+d6 d
U	
	7dB d
 F	
	CdN d
V	
	OdZ d
i	
	[df d
e	
	gdr %d
Y	
	sd~ &-4	
	dJ !x	
	KdV WdX 
Yd NdN ;<= # 	0
00 
W#?@	B
0 0 
0 >0, :;< #
  
	 =  ;<= # 	
 ''j	
	  
 >6 BCD #
  
	 Er   