o
    ii+                     @   sd  d Z ddlZddlmZmZ ddlZddl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 		dOdededdfddZej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dfd)dZejdd			dPdeeejdd	f dedededdf
d*d+Z	dQdeddfd,d-Zejdde ejd.d/d0d1e ejed2d e 		dOdedededdfd3d4Ze 												dRd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d5d	f d6eee ejd7d	f d'eee ejd(d	f d8eee ejd9d	f d:eee ejd;d	f d<eee ejd=d	f deddfd>d?Ze 		@	dSdededAee ejdBdCd	f deddf
dDdEZ!e 		dOdedededdfdFdGZ"e 		@	dSdededHee ejdIdJd	f deddf
dKdLZ#e 		dOdedededdfdMdNZ$dS )Tz2CLI commands for Hugging Face Inference Endpoints.    N)	AnnotatedOptional)InferenceEndpoint)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   m/var/www/html/karishye-ai-python/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   r*   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').c                C   s6   t |
d}|j| |||||||||	|
d}t| dS )z3Deploy an Inference Endpoint from a Hub repository.r   )r*   
repositoryr-   r.   r/   r0   r1   r2   r   r+   r   N)r   create_inference_endpointr   )r*   r,   r-   r.   r/   r0   r1   r2   r   r+   r   r%   r   r   r   r   r)   =   s   
8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   )r,   r*   r   r   r%   r   r'   r   r   r   deploy_from_catalog   s   

r7   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%   r9   r'   r   r   r   list_catalog   s   
r;   zlist-catalogr8   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      
rB   zBThe machine learning framework used for the model (e.g. 'custom').revisionzrThe specific model revision to deploy on the Inference Endpoint (e.g. '6c0e6080953db56375760c0471a8c5f2929baf11').min_replicazVThe minimum number of replicas (instances) to keep running for the Inference Endpoint.max_replicazRThe maximum number of replicas (instances) to scale to for the Inference Endpoint.scale_to_zero_timeoutzFThe duration in minutes before an inactive endpoint is scaled to zero.c                 C   sz   t |d}z|j| |||||||||	|
||d}W n ty6 } ztd|  tj|jjd|d}~ww t| dS )zUpdate an existing endpoint.r   )r*   r   r3   r-   rD   r+   r.   r/   r0   rE   rF   rG   r   zUpdate failed: r   N)	r   update_inference_endpointr   r   r   r"   r#   r$   r   )r*   r   r,   r.   r/   r0   r-   rD   r+   rE   rF   rG   r   r%   r   r'   r   r   r   update   s.   
C
rI   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   r?   zDelete failed: Nz	Deleted 'z'.)	r   promptr   r"   r   delete_inference_endpointr   r#   r$   )r*   r   rJ   r   confirmationr%   r'   r   r   r   delete#  s   

rN   c              
   C   r>   )zPause an Inference Endpoint.r   r?   zPause failed: r   N)	r   pause_inference_endpointr   r   r   r"   r#   r$   r   rA   r   r   r   pause>  rC   rP   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   rQ   r   r%   r   r'   r   r   r   resumeO  s   

rT   c              
   C   r>   )z$Scale an Inference Endpoint to zero.r   r?   zScale To Zero failed: r   N)	r    scale_to_zero_inference_endpointr   r   r   r"   r#   r$   r   rA   r   r   r   scale_to_zerok  rC   rV   )NN)NNN)N)NNNNNNNNNNNN)NFN)%__doc__r   typingr   r   r   $huggingface_hub._inference_endpointsr   huggingface_hub.errorsr   
_cli_utilsr   r   r	   ie_clicatalog_appstrArgumentNameArgOptionNameOptNamespaceOptr   commandr(   r)   r7   r;   	add_typerrB   intrI   boolrN   rP   rT   rV   r   r   r   r   <module>   s   




. &-.45
I	

	!'-39?@Y
