o
    vi'2                  &   @   s  d Z ddlZddl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 edd	Zed
d	Zeeejdd	f Zeee ejdd	f Zeee ejdd	f ZdeddfddZe 		dSdededdfddZejddddddddddddedeeejdd	f deeejdd	f deeejdd	f deeejd d	f d!eeejd"d	f d#eeejd$d	f d%eeejd&d	f ded'eee ejd(d	f ded)eeejd*d	f d+eeejd,d	f d-eee ejd.d	f d/eee ejd0d	f d1eee ejd2d	f ddf"d3dZejdd			dTdeeejdd	f dedededdf
d4d5Z	dUdeddfd6d7Zejdde ejd8d9d:d;e ejed<d e 		dSdedededdfd=d>Z e 														dVdededeee ejdd	f deee ejdd	f deee ejd d	f d!eee ejd"d	f deee ejd?d	f d@eee ejdAd	f d'eee ejd(d	f d)eee ejd*d	f d+eee ejd,d	f d-eee ejd.d	f d/eee ejd0d	f d1eee ejd2d	f deddf dBdCZ!e 		D	dWdededEee"ejdFdGd	f deddf
dHdIZ#e 		dSdedededdfdJdKZ$e 		D	dWdededLee"ejdMdNd	f deddf
dOdPZ%e 		dSdedededdfdQdRZ&dS )Xz2CLI commands for Hugging Face Inference Endpoints.    N)	AnnotatedOptional)InferenceEndpointInferenceEndpointScalingMetric)HfHubHTTPError   )TokenOpt
get_hf_api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                 C   s   t tj| jddd d S )N   Tindent	sort_keys)typerechojsondumpsraw)r    r   f/home/air/biblejyuku/back/venv/lib/python3.10/site-packages/huggingface_hub/cli/inference_endpoints.py_print_endpoint#   s   r   	namespacetokenc              
   C   s   t |d}z	|j| |d}W n ty+ } ztd|  tj|jjd|d}~ww ttj	ddd |D id	d
d dS )z6Lists all Inference Endpoints for the given namespace.r   )r   r   zListing failed: codeNitemsc                 S   s   g | ]}|j qS r   )r   ).0r   r   r   r   
<listcomp>6   s    zls.<locals>.<listcomp>r   Tr   )
r	   list_inference_endpointsr   r   r   Exitresponsestatus_coder   r   )r   r   api	endpointserrorr   r   r   ls'   s   
r)   deploy)name)r   taskr   min_replicamax_replicascale_to_zero_timeoutscaling_metricscaling_thresholdr+   repozeThe name of the model repository associated with the Inference Endpoint (e.g. 'openai/gpt-oss-120b').	frameworkz@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').regionzTThe cloud region in which the Inference Endpoint will be created (e.g. 'us-east-1').vendorzVThe 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.r/   zFThe duration in minutes before an inactive endpoint is scaled to zero.r0   z!The metric reference for scaling.r1   zeThe scaling metric threshold used to trigger a scale up. Ignored when scaling metric is not provided.c                C   s   t |
d}|jdi d| d|d|d|d|d|d|d	|d
|d|	d|
d|d|d|d|d|}t| dS )z3Deploy an Inference Endpoint from a Hub repository.r   r+   
repositoryr3   r4   r5   r6   r7   r8   r   r,   r   r-   r.   r0   r1   r/   Nr   )r	   create_inference_endpointr   )r+   r2   r3   r4   r5   r6   r7   r8   r   r,   r   r-   r.   r/   r0   r1   r&   r   r   r   r   r*   =   sF   
V
	
c              
   C   sh   t |d}z|j| |||d}W n ty- } ztd|  tj|jjd|d}~ww t| dS )z4Deploy an Inference Endpoint from the Model Catalog.r   )repo_idr+   r   r   zDeployment failed: r   N)	r	   &create_inference_endpoint_from_catalogr   r   r   r#   r$   r%   r   )r2   r+   r   r   r&   r   r(   r   r   r   deploy_from_catalog   s   

r=   c              
   C   st   t | d}z|j| d}W n ty* } ztd|  tj|jjd|d}~ww ttj	d|iddd dS )	List available Catalog models.r   zCatalog fetch failed: r   Nmodelsr   Tr   )
r	   list_inference_catalogr   r   r   r#   r$   r%   r   r   )r   r&   r?   r(   r   r   r   list_catalog   s   
rA   zlist-catalogr>   T)r+   r   hiddencatalogc              
   C   f   t |d}z
|j| ||d}W n ty, } ztd|  tj|jjd|d}~ww t| dS )z+Get information about an existing endpoint.r   r+   r   r   zFetch failed: r   N)	r	   get_inference_endpointr   r   r   r#   r$   r%   r   r+   r   r   r&   r   r(   r   r   r   describe      
rH   zBThe machine learning framework used for the model (e.g. 'custom').revisionzrThe specific model revision to deploy on the Inference Endpoint (e.g. '6c0e6080953db56375760c0471a8c5f2929baf11').c                 C   s~   t |d}z|j| |||||||||	|
||||d}W n ty8 } ztd|  tj|jjd|d}~ww t| dS )zUpdate an existing endpoint.r   )r+   r   r9   r3   rJ   r,   r4   r5   r6   r-   r.   r/   r0   r1   r   zUpdate failed: r   N)	r	   update_inference_endpointr   r   r   r#   r$   r%   r   )r+   r   r2   r4   r5   r6   r3   rJ   r,   r-   r.   r/   r0   r1   r   r&   r   r(   r   r   r   update   s2   
O
rL   Fyesz--yeszSkip confirmation prompts.c              
   C   s   |st d|  d}|| krt d t jddt|d}z
|j| ||d W n tyF } zt d|  t j|jjd|d	}~ww t d
|  d d	S )z)Delete an Inference Endpoint permanently.zDelete endpoint 'z'? Type the name to confirm.zAborted.r   r   r   rE   zDelete failed: Nz	Deleted 'z'.)	r   promptr   r#   r	   delete_inference_endpointr   r$   r%   )r+   r   rM   r   confirmationr&   r(   r   r   r   deleteT  s   

rQ   c              
   C   rD   )zPause an Inference Endpoint.r   rE   zPause failed: r   N)	r	   pause_inference_endpointr   r   r   r#   r$   r%   r   rG   r   r   r   pauseo  rI   rS   fail_if_already_runningz--fail-if-already-runningzWIf `True`, the method will raise an error if the Inference Endpoint is already running.c              
   C   sj   t |d}z|j| ||| d}W n ty. } ztd|  tj|jjd|d}~ww t| dS )zResume an Inference Endpoint.r   )r+   r   r   
running_okzResume failed: r   N)	r	   resume_inference_endpointr   r   r   r#   r$   r%   r   )r+   r   rT   r   r&   r   r(   r   r   r   resume  s   

rW   c              
   C   rD   )z$Scale an Inference Endpoint to zero.r   rE   zScale To Zero failed: r   N)	r	    scale_to_zero_inference_endpointr   r   r   r#   r$   r%   r   rG   r   r   r   scale_to_zero  rI   rY   )NN)NNN)N)NNNNNNNNNNNNNN)NFN)'__doc__r   typingr   r   r   $huggingface_hub._inference_endpointsr   r   huggingface_hub.errorsr   
_cli_utilsr   r	   r
   ie_clicatalog_appstrArgumentNameArgOptionNameOptNamespaceOptr   commandr)   intfloatr*   r=   rA   	add_typerrH   rL   boolrQ   rS   rW   rY   r   r   r   r   <module>   s   




. &-.45;AGMS
l	

	!'-39?EKLg
