wL iD ddlZddlmZmZddlmZddlmZddlmZm Z m Z m Z ddl m Z mZddlmZmZmZerdd lmZdd lmZdd lmZej2eZGd d eeZGddeeZeGddZy)N) dataclassfield)datetime)Enum) TYPE_CHECKINGDictOptionalUnion)InferenceEndpointErrorInferenceEndpointTimeoutError) get_sessionloggingparse_datetimeHfApiInferenceClientAsyncInferenceClientc,eZdZdZdZdZdZdZdZdZ dZ y ) InferenceEndpointStatuspending initializingupdating updateFailedrunningpausedfailed scaledToZeroN) __name__ __module__ __qualname__PENDING INITIALIZINGUPDATING UPDATE_FAILEDRUNNINGPAUSEDFAILEDSCALED_TO_ZEROj/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/huggingface_hub/_inference_endpoints.pyrrs*G!LH"MG F F#Nr-rceZdZdZdZdZy)InferenceEndpointTypepublic protectedprivateN)r!r"r#PUBlIC PROTECTEDPRIVATEr,r-r.r0r0s FIGr-r0c.eZdZUdZedZeed<eed<edZeed<edZ e ed<edZ eed<edZ e eed <edd Zeed <edd Zeed <edd Zeed <edd Zeed<edd Zeed<edd Zeed<edZeed<eddZeeedfed<eddZded<e d3dededeeedfde dddf dZd4dZed5dZ ed6dZ!d7de e"d e"ddfd!Z#d8d"Z$ddddddddddddd# d$e ed%e ed&e ed'e e"d(e e"d)e e"de ed e ed e ed e ed*e ed+e eeefddfd,Z%d8d-Z&d9d.eddfd/Z'd8d0Z(d4d1Z)d4d2Z*y):InferenceEndpointa Contains information about a deployed Inference Endpoint. Args: name (`str`): The unique name of the Inference Endpoint. namespace (`str`): The namespace where the Inference Endpoint is located. repository (`str`): The name of the model repository deployed on this Inference Endpoint. status ([`InferenceEndpointStatus`]): The current status of the Inference Endpoint. url (`str`, *optional*): The URL of the Inference Endpoint, if available. Only a deployed Inference Endpoint will have a URL. framework (`str`): The machine learning framework used for the model. revision (`str`): The specific model revision deployed on the Inference Endpoint. task (`str`): The task associated with the deployed model. created_at (`datetime.datetime`): The timestamp when the Inference Endpoint was created. updated_at (`datetime.datetime`): The timestamp of the last update of the Inference Endpoint. type ([`InferenceEndpointType`]): The type of the Inference Endpoint (public, protected, private). raw (`Dict`): The raw dictionary data returned from the API. token (`str` or `bool`, *optional*): Authentication token for the Inference Endpoint, if set when requesting the API. Will default to the locally saved token if not provided. Pass `token=False` if you don't want to send your token to the server. Example: ```python >>> from huggingface_hub import get_inference_endpoint >>> endpoint = get_inference_endpoint("my-text-to-image") >>> endpoint InferenceEndpoint(name='my-text-to-image', ...) # Get status >>> endpoint.status 'running' >>> endpoint.url 'https://my-text-to-image.region.vendor.endpoints.huggingface.cloud' # Run inference >>> endpoint.client.text_to_image(...) # Pause endpoint to save $$$ >>> endpoint.pause() # ... # Resume and wait for deployment >>> endpoint.resume() >>> endpoint.wait() >>> endpoint.client.text_to_image(...) ``` F)initname namespace repositorystatus health_routeurl)reprr9 frameworkrevisiontask created_at updated_attype)r@raw)r@compareN_tokenr_apitokenapireturncT| ddlm}|}| |j}|||||S)z&Initialize object from raw dictionary.r r)rGr;rIrJ)hf_apirrK)clsrGr;rKrLrs r.from_rawzInferenceEndpoint.from_rawys4 ; %'C =IIEsiCHHr-c$|jy)z$Populate fields from raw dictionary.N)_populate_from_rawselfs r. __post_init__zInferenceEndpoint.__post_init__s !r-cx|j tdddlm}||j|jS)aReturns a client to make predictions on this Inference Endpoint. Returns: [`InferenceClient`]: an inference client pointing to the deployed endpoint. Raises: [`InferenceEndpointError`]: If the Inference Endpoint is not yet deployed. Cannot create a client for this Inference Endpoint as it is not yet deployed. Please wait for the Inference Endpoint to be deployed using `endpoint.wait()` and try again.r rmodelrK)r?r inference._clientrrI)rUrs r.clientzInferenceEndpoint.clientsA 88 (o  7((++  r-cx|j tdddlm}||j|jS)a3Returns a client to make predictions on this Inference Endpoint. Returns: [`AsyncInferenceClient`]: an asyncio-compatible inference client pointing to the deployed endpoint. Raises: [`InferenceEndpointError`]: If the Inference Endpoint is not yet deployed. rXr rrY)r?r "inference._generated._async_clientrrI)rUrs r. async_clientzInferenceEndpoint.async_clientsB 88 (o  M#((++  r-timeout refresh_everyc||dkr td|dkr tdtj} |jtjk(rt d|j d|jtjk(rt d|j d|jtjk(r|j|jjdd|jjd}tj||jj!|j" }|j$d k(rt&j)d |S|%tj|z |kDr t+d t&j)d |jd|dtj,||j/)a+Wait for the Inference Endpoint to be deployed. Information from the server will be fetched every 1s. If the Inference Endpoint is not deployed after `timeout` seconds, a [`InferenceEndpointTimeoutError`] will be raised. The [`InferenceEndpoint`] will be mutated in place with the latest data. Args: timeout (`int`, *optional*): The maximum time to wait for the Inference Endpoint to be deployed, in seconds. If `None`, will wait indefinitely. refresh_every (`int`, *optional*): The time to wait between each fetch of the Inference Endpoint status, in seconds. Defaults to 5s. Returns: [`InferenceEndpoint`]: the same Inference Endpoint, mutated in place with the latest data. Raises: [`InferenceEndpointError`] If the Inference Endpoint ended up in a failed state. [`InferenceEndpointTimeoutError`] If the Inference Endpoint is not deployed after `timeout` seconds. rz`timeout` cannot be negative.z!`refresh_every` must be positive.zInference Endpoint z> failed to deploy. Please check the logs for more information.z> failed to update. Please check the logs for more information./)rK)headersz'Inference Endpoint is ready to be used.zlstriprgetrJ_build_hf_headersrI status_codeloggerinfor sleepfetch)rUr`rastart _health_urlresponses r.waitzInferenceEndpoint.waits.  7Q;<= = A @A A {{5<<<,)$))4rs{{5CCC,)$))4rs{{5===$((BV!%!5 6a8I8I8P8PQT8U7VW &=,,[$))B]B]dhdodoB]Bp,q''3.KK IJK"99;&078vww KKB4;;-{[hZiimn o JJ} % JJL-r-c|jj|j|j|j}|j |_|j |S)zFetch latest information about the Inference Endpoint. Returns: [`InferenceEndpoint`]: the same Inference Endpoint, mutated in place with the latest data. r:r;rK)rJget_inference_endpointr:r;rIrGrSrUobjs r.rpzInferenceEndpoint.fetchsJ ii..DII_c_j_j.k77 ! r-) accelerator instance_size instance_type min_replica max_replicascale_to_zero_timeoutr<rArBrC custom_imagesecretsrzr{r|r}r~rrrc |jj|j|j||||||||| | | | |j} | j |_|j |S)a Update the Inference Endpoint. This method allows the update of either the compute configuration, the deployed model, or both. All arguments are optional but at least one must be provided. This is an alias for [`HfApi.update_inference_endpoint`]. The current object is mutated in place with the latest data from the server. Args: accelerator (`str`, *optional*): The hardware accelerator to be used for inference (e.g. `"cpu"`). instance_size (`str`, *optional*): The size or type of the instance to be used for hosting the model (e.g. `"x4"`). instance_type (`str`, *optional*): The cloud instance type where the Inference Endpoint will be deployed (e.g. `"intel-icl"`). min_replica (`int`, *optional*): The minimum number of replicas (instances) to keep running for the Inference Endpoint. max_replica (`int`, *optional*): The maximum number of replicas (instances) to scale to for the Inference Endpoint. scale_to_zero_timeout (`int`, *optional*): The duration in minutes before an inactive endpoint is scaled to zero. repository (`str`, *optional*): The name of the model repository associated with the Inference Endpoint (e.g. `"gpt2"`). framework (`str`, *optional*): The machine learning framework used for the model (e.g. `"custom"`). revision (`str`, *optional*): The specific model revision to deploy on the Inference Endpoint (e.g. `"6c0e6080953db56375760c0471a8c5f2929baf11"`). task (`str`, *optional*): The task on which to deploy the model (e.g. `"text-classification"`). custom_image (`Dict`, *optional*): A custom Docker image to use for the Inference Endpoint. This is useful if you want to deploy an Inference Endpoint running on the `text-generation-inference` (TGI) framework (see examples). secrets (`Dict[str, str]`, *optional*): Secret values to inject in the container environment. Returns: [`InferenceEndpoint`]: the same Inference Endpoint, mutated in place with the latest data. )r:r;rzr{r|r}r~rr<rArBrCrrrK)rJupdate_inference_endpointr:r;rIrGrS)rUrzr{r|r}r~rr<rArBrCrrrys r.updatezInferenceEndpoint.updatesurii11nn#''##"7!%++2 &77 ! r-c|jj|j|j|j}|j |_|j |S)aoPause the Inference Endpoint. A paused Inference Endpoint will not be charged. It can be resumed at any time using [`InferenceEndpoint.resume`]. This is different than scaling the Inference Endpoint to zero with [`InferenceEndpoint.scale_to_zero`], which would be automatically restarted when a request is made to it. This is an alias for [`HfApi.pause_inference_endpoint`]. The current object is mutated in place with the latest data from the server. Returns: [`InferenceEndpoint`]: the same Inference Endpoint, mutated in place with the latest data. rv)rJpause_inference_endpointr:r;rIrGrSrxs r.pausezInferenceEndpoint.pauseHsJii00dii4>>aealal0m77 ! r- running_okc|jj|j|j||j}|j |_|j |S)aResume the Inference Endpoint. This is an alias for [`HfApi.resume_inference_endpoint`]. The current object is mutated in place with the latest data from the server. Args: running_ok (`bool`, *optional*): If `True`, the method will not raise an error if the Inference Endpoint is already running. Defaults to `True`. Returns: [`InferenceEndpoint`]: the same Inference Endpoint, mutated in place with the latest data. )r:r;rrK)rJresume_inference_endpointr:r;rIrGrS)rUrrys r.resumezInferenceEndpoint.resumeZsSii11dnnSWS^S^2 77 ! r-c|jj|j|j|j}|j |_|j |S)azScale Inference Endpoint to zero. An Inference Endpoint scaled to zero will not be charged. It will be resume on the next request to it, with a cold start delay. This is different than pausing the Inference Endpoint with [`InferenceEndpoint.pause`], which would require a manual resume with [`InferenceEndpoint.resume`]. This is an alias for [`HfApi.scale_to_zero_inference_endpoint`]. The current object is mutated in place with the latest data from the server. Returns: [`InferenceEndpoint`]: the same Inference Endpoint, mutated in place with the latest data. rv)rJ scale_to_zero_inference_endpointr:r;rIrGrSrxs r. scale_to_zerozInferenceEndpoint.scale_to_zeroosMii88diiSWSaSaimitit8u77 ! r-c||jj|j|j|jy)aTDelete the Inference Endpoint. This operation is not reversible. If you don't want to be charged for an Inference Endpoint, it is preferable to pause it with [`InferenceEndpoint.pause`] or scale it to zero with [`InferenceEndpoint.scale_to_zero`]. This is an alias for [`HfApi.delete_inference_endpoint`]. rvN)rJdelete_inference_endpointr:r;rIrTs r.deletezInferenceEndpoint.deletes, ++dnn\`\g\g+hr-c(|jd|_|jdd|_|jdd|_|jdj d|_|jd|_|jdd|_|jdd |_|jdd |_ t|jdd |_ t|jdd |_ |jd |_ y)z}Populate fields from raw dictionary. Called in __post_init__ + each time the Inference Endpoint is updated. r:rZr<r=stater? healthRouterArBrC createdAt updatedAtrFN)rGr:r<r=rjr?r>rArBrCrrDrErFrTs r.rSz$InferenceEndpoint._populate_from_raws HHV$ ((7+L9hhx(1 88H%))%0 HH]3'*;7)*5 HHW%f- (();K)HI(();K)HIHHV$ r-)NN)rMN)rMr)rMr)N)rMr8)T)+r!r"r#__doc__rr:str__annotations__r<r=rr>r?r rArBrCrDrrErFr0rGrrIr boolrJ classmethodrQrVpropertyr\r_intrtrprrrrrrSr,r-r.r8r8%s9x5!D#!N'J'&+&7F #75)L#)E*C#*E2Is2u51Hc15u-D#- e%8J8 e%8J8"'U"?D ?5!C!&+u%EFE#tT/ "Eue4D'4gk I I#& I/4S$_/E IS[\cSd I  I I"  *  *3HSM33M`3j &*'+'+%)%)/3$(#'"&"'+,0!Nc] N  } N  } Nc]Nc]N (}NSMNC=N3-NsmNtnN $sCx.)!N" #N`$1D*$i%r-r8) rg dataclassesrrrenumrtypingrrr r huggingface_hub.errorsr r utilsrrrrOrr[rr^r get_loggerr!rmrrr0r8r,r-r.rsx (77X772H   H %$c4$C  w%w% w%r-