
    ^j
D              ?       "	   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mZ dd	lmZ  ed
      Z ed      Zee ed      f   Zeedz   ed      f   Zeedz   ed      f   Z ejC                  dddg      	 	 dkde deddfd       Z"ejC                  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d      f   dee ed      f   d ee ed!      f   d"ee ed#      f   d$ee ed%      f   d&ee ed'      f   d(ee ed)      f   de d*eedz   ed+      f   ded,ee# ed-      f   d.ee# ed/      f   d0ee#dz   ed1      f   d2eedz   ed3      f   d4ee$dz   ed5      f   d6ed7eedz   ed8d9      f   d:eedz   ed;      f   d<ee#dz   ed=      f   d>eedz   ed?d@      f   dAeedz   edBdC      f   dDedEedFedGedHeedz   edI ee      dJK      f   ddf8dL       Z%ejC                  ddMg      	 	 	 	 dldee ed      f   ded eedz   edN      f   de deddfdO       Z&	 dmdeddfdPZ' ejC                  ddQg      e'        ejC                  dRdST      e'       ejQ                  edUV       ejC                  dWg      	 	 dkdede deddfdX       Z)ejC                  dYg      	 	 	 	 	 	 	 	 	 	 	 	 	 	 dndede deedz   ed      f   d eedz   ed!      f   d"eedz   ed#      f   d$eedz   ed%      f   deedz   edZ      f   d6eedz   ed[      f   d*eedz   ed+      f   d,ee#dz   ed-      f   d.ee#dz   ed/      f   d0ee#dz   ed1      f   d2eedz   ed3      f   d4ee$dz   ed5      f   deddf d\       Z*ejC                  d]g      	 	 	 dodede d^ee+ ed_d`      f   deddf
da       Z,ejC                  dbg      	 	 dkdede deddfdc       Z-ejC                  ddg      	 	 	 dodede deee+ edfdg      f   deddf
dh       Z.ejC                  dig      	 	 dkdede deddfdj       Z/y)pz2CLI 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)ArgumentOption)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        $ rR}t        j                  d|        t
        j                  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click
exceptionsExitresponsestatus_coderawgetappend
isinstancedicttable)r   r   api	endpointsr/   resultsendpointr5   r   r    r!   r"   s               r/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/huggingface_hub/cli/inference_endpoints.pylsr@   1   s    5
!CP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%/  P		$UG,-##)C)C#D%OPs   F0 0	H9AH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').rB   zVThe minimum number of replicas (instances) to keep running for the Inference Endpoint.rC   zRThe maximum number of replicas (instances) to scale to for the Inference Endpoint.rD   zFThe duration in minutes before an inactive endpoint is scaled to zero.rE   z!The metric reference for scaling.rF   zeThe scaling metric threshold used to trigger a scale up. Ignored when scaling metric is not provided.rG   rH   z--custom-imagezfDocker image URL for a custom container (e.g. 'nexagi/sglang:v0.5.12'). Requires '--framework custom'.rI   z]Health check route exposed by the custom container (e.g. '/health'). Requires --custom-image.rJ   zKPort the custom container listens on (e.g. 30000). Requires --custom-image.rK   z--container-commandzOverride the container entrypoint, as a quoted string split into tokens (e.g. "python -m sglang.launch_server"). Requires --custom-image.rL   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.rM   rN   rO   rP   rQ   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healthRouterJ   r$   typerH   rK   rL   rM   rO   r   r#   r%   r(   rS   rT   rU   r+   r*   r   r'   r   rB   rC   rE   rF   rD   rG   zUse 'hf endpoints describe z!' to check the deployment status. )r   r   itemsshlexsplitr   create_inference_endpointr   r9   r5   hint)#r#   rR   r(   rS   rT   rU   r+   r*   r   r'   r   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   custom_image_dictkeyvalueenv_mapsecrets_mapparamsr;   r>   s#                                      r?   rA   rA   T   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                 D   t        |      }	 |j                  | ||||      }t        j                  |j                         y# t        $ rR}t        j                  d|        t
        j                  j                  |j                  j                        |d}~ww xY w)z4Deploy an Inference Endpoint from the Model Catalog.r   )repo_idr#   rS   r   r   zDeployment failed: r   N)r   &create_inference_endpoint_from_catalogr   r   r/   r0   r1   r2   r3   r4   r9   r5   )rR   r#   rS   r   r   r;   r>   r/   s           r?   deploy_from_catalogrj     s    & 5
!C
P==# > 
 HHX\\	  P		'w/0##)C)C#D%OP   A 	BABBc                 ,   t        |       }	 |j                  |       }t        j                  d|i       y# t        $ rR}t        j                  d|        t
        j                  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/   r0   r1   r2   r3   r4   r9   )r   r;   rm   r/   s       r?   list_catalogro   7  s     5
!CP++%+8
 HHh 	  P		*5'23##)C)C#D%OP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        $ rR}t        j                  d|        t
        j                  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/   r0   r1   r2   r3   r4   r9   r5   r#   r   r   r;   r>   r/   s         r?   describerw   L  s     5
!CP--49TY-Z
 HHX\\	  P		N5'*+##)C)C#D%OP   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                 X   t        |      }	 |j                  | |||||||||	|
||||      }t        j                  |j                         y# t        $ rR}t        j                  d|        t
        j                  j                  |j                  j                        |d}~ww xY w)zUpdate an existing endpoint.r   )r#   r   r%   r(   rG   r'   rS   rT   rU   rB   rC   rD   rE   rF   r   zUpdate failed: r   N)r   update_inference_endpointr   r   r/   r0   r1   r2   r3   r4   r9   r5   )r#   r   rR   rS   rT   rU   r(   rG   r'   rB   rC   rD   rE   rF   r   r;   r>   r/   s                     r?   updater{   ]  s    ^ 5
!CP00#''##"7)/ 1 
( HHX\\  P		OE7+,##)C)C#D%OPs    A 	B)AB$$B)zhf endpoints delete my-endpointyesz--yeszSkip confirmation prompts.c                 n   t        j                  d|  d|       t        |      }	 |j                  | ||       t        j                  d	|  d
|        y# t        $ rR}t        j
                  d|        t        j                  j                  |j                  j                        |d}~ww xY w)z)Delete an Inference Endpoint permanently.zDelete endpoint 'z'?)r|   r   rt   zDelete failed: r   Nz	Deleted 'z'.rr   )r   confirmr   delete_inference_endpointr   r/   r0   r1   r2   r3   r4   result)r#   r   r|   r   r;   r/   s         r?   deleter     s     KK#D6,#6
5
!CP%%49E%R
 JJ4&#$/	  P		OE7+,##)C)C#D%OPs   A 	B4"AB//B4zhf endpoints pause my-endpointc                 @   t        |      }	 |j                  | ||      }t        j                  |j                         y# t        $ rR}t        j                  d|        t
        j                  j                  |j                  j                        |d}~ww xY w)zPause an Inference Endpoint.r   rt   zPause failed: r   N)r   pause_inference_endpointr   r   r/   r0   r1   r2   r3   r4   r9   r5   rv   s         r?   pauser     s     5
!CP//TYV[/\
 HHX\\	  P		N5'*+##)C)C#D%OPrx   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                 D   t        |      }	 |j                  | |||       }t        j                  |j                         y# t        $ rR}t        j                  d|        t
        j                  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/   r0   r1   r2   r3   r4   r9   r5   )r#   r   r   r   r;   r>   r/   s          r?   resumer     s     5
!C	P0022	 1 
 HHX\\  P		OE7+,##)C)C#D%OPrk   z&hf endpoints scale-to-zero my-endpointc                 @   t        |      }	 |j                  | ||      }t        j                  |j                         y# t        $ rR}t        j                  d|        t
        j                  j                  |j                  j                        |d}~ww xY w)z$Scale an Inference Endpoint to zero.r   rt   zScale To Zero failed: r   N)r    scale_to_zero_inference_endpointr   r   r/   r0   r1   r2   r3   r4   r9   r5   rv   s         r?   scale_to_zeror   	  s     5
!CP77TY^c7d
 HHX\\	  P		*5'23##)C)C#D%OPrx   )NN)NNNN)N)NNNNNNNNNNNNNN)NFN)0__doc__r]   typingr   r0   $huggingface_hub._inference_endpointsr   r   huggingface_hub.errorsr   r   
_cli_utilsr	   r
   r   r   r   r   r   r   r   r   
_frameworkr   r   _outputr   ie_clicatalog_appstrNameArgNameOptNamespaceOptcommandr@   intfloatrA   rj   ro   	add_grouprw   r{   boolr   r   r   r   r[       r?   <module>r      s`
   8    f ;   )  
F	G!QR "#% $J
 !#
 $J
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9:	<
0 0 
0 >0, :;< #
  
	 =  ;<= # 	
 ''j	
	  
 >6 BCD #
  
	 Er   