ó
    Ú°›j{$  ã                   ó�   • S r SSKrSSKJrJrJr  SSKrSSKJrJ	r	  SSK
JrJrJrJr   " S S5      r " S S	5      r " S
 S5      rg)z#
Runpod | Python | Endpoint Runner
é    N)ÚAnyÚDictÚOptional)ÚHTTPAdapterÚRetry)ÚAPI_KEY_NOT_SET_MSGÚFINAL_STATESÚUNAUTHORIZED_MSGÚis_completedc            	       óˆ   • \ rS rSrSrSS\\   4S jjr  SS\S\S\\   S	\	4S
 jjr
SS\S\S	\	4S jjrSS\S	\	4S jjrSrg)ÚRunPodClienté   z$A client for running endpoint calls.NÚapi_keyc                 ó:  • SSK JnJn  U=(       d    UU l        U R                  c  [        [        5      e[
        R                  " 5       U l        [        SSSS/S9nU R                  R                  S	[        US
95        SSU R                   3S.U l        X0l        g)zµ
Initialize a RunPodClient instance.

Args:
    api_key: Optional API key. If not provided, uses global api_key.

Raises:
    RuntimeError: If the API key has not been initialized.
r   )r   Úendpoint_url_baseNé   é   i˜  i­  )ÚtotalÚbackoff_factorÚstatus_forcelistzhttp://)Úmax_retrieszapplication/jsonzBearer )zContent-TypeÚAuthorization)Úrunpodr   r   ÚRuntimeErrorr   ÚrequestsÚSessionÚ
rp_sessionr   Úmountr   Úheaders)Úselfr   Úglobal_api_keyr   Úretriess        ÚS/home/mande/repo/quber/.venv/lib/python3.13/site-packages/runpod/endpoint/runner.pyÚ__init__ÚRunPodClient.__init__   sŠ   € ÷	
ð ×0 .ˆŒà�<‰<ÑÜÔ2Ó3Ð3ä"×*Ò*Ó,ˆŒÜ˜a°ÀSÈ#ÀJÑOˆØ�‰×Ñ˜i¬ÀÑ)IÔJð /Ø& t§|¡| nÐ5ñ
ˆŒð
 "3Õó    ÚmethodÚendpointÚdataÚtimeoutc                 óì   • U R                    SU 3nU R                  R                  XU R                  X4S9nUR                  S:X  a  [        [        5      eUR                  5         UR                  5       $ )a"  
Make a request to the specified endpoint using the given HTTP method.

Args:
    method: The HTTP method to use ('GET' or 'POST').
    endpoint: The endpoint path to which the request will be made.
    data: The JSON payload to send with the request.
    timeout: The number of seconds to wait for the server to send data before giving up.

Returns:
    The JSON response from the server.

Raises:
    RuntimeError: If the response returns a 401 Unauthorized status.
    requests.HTTPError: If the response contains an unsuccessful status code.
Ú/)r   Újsonr*   i‘  )	r   r   Úrequestr   Ústatus_coder   r
   Úraise_for_statusr-   )r    r'   r(   r)   r*   ÚurlÚresponses          r#   Ú_requestÚRunPodClient._request9   ss   € ð( ×'Ñ'Ð(¨¨(¨Ð4ˆØ—?‘?×*Ñ*Ø §¡°Dð +ð 
ˆð ×Ñ 3Ó&ÜÔ/Ó0Ð0à×!Ñ!Ô#Ø�}‰}‹Ðr&   c                 ó(   • U R                  SXU5      $ )zPost to the endpoint.ÚPOST©r3   )r    r(   r)   r*   s       r#   ÚpostÚRunPodClient.postX   s   € à�}‰}˜V X°WÓ=Ð=r&   c                 ó"   • U R                  SXS9$ )zGet from the endpoint.ÚGET©r*   r7   )r    r(   r*   s      r#   ÚgetÚRunPodClient.get\   s   € à�}‰}˜U Hˆ}Ð>Ð>r&   )r   r   r   r   ©N)Né
   )r@   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ústrr$   ÚdictÚintr3   r8   r=   Ú__static_attributes__© r&   r#   r   r      s{   † Ù.ñ3 ¨¡õ 3ðB BFØñØðØ%(ðØ08¸±ðàõñ>>˜Sð >¨ð >°sõ >ñ?˜Cð ?¨#÷ ?ð ?r&   r   c                   óŽ   • \ rS rSrSrS\S\S\4S jrSS\S\\\	4   4S	 jjr
S
 rSS\S\	4S jjrS\	4S jrSS\S\	4S jjrSrg)ÚJobéd   z1Represents a job to be run on the Runpod service.Úendpoint_idÚjob_idÚclientc                 óD   • Xl         X l        X0l        SU l        SU l        g)zæ
Initialize a Job instance with the given endpoint ID and job ID.

Args:
    endpoint_id: The identifier for the endpoint.
    job_id: The identifier for the job.
    client: An instance of the RunPodClient to make requests with.
N)rN   rO   Ú	rp_clientÚ
job_statusÚ
job_output)r    rN   rO   rP   s       r#   r$   ÚJob.__init__g   s"   € ð 'ÔØŒØŒàˆŒØˆ�r&   ÚsourceÚreturnc                 óÜ   • U R                    SU SU R                   3nU R                  R                  US9n[	        US   5      (       a!  US   U l        UR                  SS5      U l        U$ )zBReturns the raw json of the status, raises an exception if invalidr,   )r(   ÚstatusÚoutputN)rN   rO   rR   r=   r   rS   rT   )r    rV   Ú
status_urlÚ	job_states       r#   Ú
_fetch_jobÚJob._fetch_jobw   sn   € à×(Ñ(Ð)¨¨6¨(°!°D·K±K°=ÐAˆ
Ø—N‘N×&Ñ&°
Ð&Ð;ˆ	ä˜	 (Ñ+×,Ñ,Ø'¨Ñ1ˆDŒOØ'Ÿm™m¨H°dÓ;ˆDŒOàÐr&   c                 óZ   • U R                   b  U R                   $ U R                  5       S   $ )z&Returns the status of the job request.rY   )rS   r]   )r    s    r#   rY   Ú
Job.status‚   s(   € à�?‰?Ñ&Ø—?‘?Ð"à�‰Ó  Ñ*Ð*r&   r*   c                 óT  • US:”  aj  [        U R                  5       5      (       dL  [        R                  " S5        US-  nUS::  a  [	        S5      e[        U R                  5       5      (       d  ML  U R
                  b  U R
                  $ U R                  5       R                  SS5      $ )zˆ
Returns the output of the job request.

Args:
    timeout: The number of seconds to wait for the server to send data before giving up.
r   r   zJob timed out.NrZ   )r   rY   ÚtimeÚsleepÚTimeoutErrorrT   r]   r=   ©r    r*   s     r#   rZ   Ú
Job.output‰   s†   € ð �Q‹;Ü" 4§;¡;£=×1Ñ1Ü—
’
˜1”Ø˜1‘�Ø˜a“<Ü&Ð'7Ó8Ð8ô	 # 4§;¡;£=×1Ó1ð �?‰?Ñ&Ø—?‘?Ð"à�‰Ó ×$Ñ$ X¨tÓ4Ð4r&   c              #   óö   #   •  [         R                  " S5        U R                  SS9nUS   [        ;  d  [	        US   5      S:”  a!  UR                  S/ 5       H
  nUS   v •  M     OUS   [        ;   a  gMu  7f)z>Returns a generator that yields the output of the job request.r   Ústream)rV   rY   r   rZ   N)rb   rc   r]   r	   Úlenr=   )r    Ústream_partialÚchunks      r#   rh   Ú
Job.streamœ   sx   é € àÜ�JŠJ�qŒMØ!Ÿ_™_°H˜_Ð=ˆNà˜xÑ(´Ó<Ü�~ hÑ/Ó0°1Ó4à+×/Ñ/°¸"Ö=�EØ ™/Ô)ò >à Ñ)¬\Ó9Øñ ùs   ‚A7A9c                 ój   • U R                   R                  U R                   SU R                   3SUS9$ )z£
Cancels the job and returns the result of the cancellation request.

Args:
    timeout: The number of seconds to wait for the server to respond before giving up.
z/cancel/N©r)   r*   )rR   r8   rN   rO   re   s     r#   ÚcancelÚ
Job.cancelª   s?   € ð �~‰~×"Ñ"Ø×ÑÐ  ¨¯©¨Ð6ØØð #ð 
ð 	
r&   )rN   rO   rT   rS   rR   N)rY   )r   ©é   )rA   rB   rC   rD   rE   rF   r   r$   r   r   r]   rY   rH   rZ   rh   ro   rI   rJ   r&   r#   rL   rL   d   sv   † Ù;ð Cð °ð ¸lô ñ 	 ð 	°D¸¸c¸±Nõ 	ò+ñ5˜cð 5¨#õ 5ð&˜ô ñ
˜cð 
¨#÷ 
ð 
r&   rL   c            	       óÀ   • \ rS rSrSrSS\S\\   4S jjrS\\\	4   S\
4S	 jr SS\\\	4   S
\S\\\	4   4S jjrSS
\S\\\	4   4S jjrSS
\S\\\	4   4S jjrSrg)ÚEndpointé»   z6Manages an endpoint to run jobs on the Runpod service.NrN   r   c                 ó,   • Xl         [        US9U l        g)a‹  
Initialize an Endpoint instance with the given endpoint ID.

Args:
    endpoint_id: The identifier for the endpoint.
    api_key: Optional API key for this endpoint instance.

Example:
    >>> endpoint = runpod.Endpoint("ENDPOINT_ID")
    >>> run_request = endpoint.run({"your_model_input_key": "your_model_input_value"})
    >>> print(run_request.status())
    >>> print(run_request.output())
)r   N)rN   r   rR   )r    rN   r   s      r#   r$   ÚEndpoint.__init__¾   s   € ð 'ÔÜ%¨gÑ6ˆ�r&   Úrequest_inputrW   c                 óÐ   • UR                  S5      (       d  SU0nU R                  R                  U R                   S3U5      n[	        U R                  US   U R                  5      $ )z™
Run the endpoint with the given input.

Args:
    request_input: The input to pass into the endpoint.

Returns:
    A Job instance for the run request.
Úinputz/runÚid)r=   rR   r8   rN   rL   )r    rx   Újob_requests      r#   ÚrunÚEndpoint.runÏ   sg   € ð × Ñ  ×)Ñ)Ø$ mÐ4ˆMà—n‘n×)Ñ)Ø×ÑÐ  Ð%Øó
ˆô �4×#Ñ# [°Ñ%6¸¿¹ÓGÐGr&   r*   c                 ó&  • UR                  S5      (       d  SU0nU R                  R                  U R                   S3UUS9nUS   [        ;   a  UR                  SS5      $ [        U R                  US   U R                  5      R                  US9$ )z°
Run the endpoint with the given input synchronously.

Args:
    request_input: The input to pass into the endpoint.
    timeout: Maximum time to wait for the job to complete.
rz   z/runsyncr<   rY   rZ   Nr{   )r=   rR   r8   rN   r	   rL   rZ   )r    rx   r*   r|   s       r#   Úrun_syncÚEndpoint.run_syncâ   sž   € ð × Ñ  ×)Ñ)Ø$ mÐ4ˆMà—n‘n×)Ñ)Ø×ÑÐ  Ð)ØØð *ð 
ˆð �xÑ ¤LÓ0Ø—?‘? 8¨TÓ2Ð2äØ×Ñ˜k¨$Ñ/°·±ó
ç
‰&˜ˆ&Ð
!ð	"r&   c                 óP   • U R                   R                  U R                   S3US9$ )zµ
Check the health of the endpoint (number/state of workers, number/state of requests).

Args:
    timeout: The number of seconds to wait for the server to respond before giving up.
z/healthr<   )rR   r=   rN   re   s     r#   ÚhealthÚEndpoint.healthü   s4   € ð �~‰~×!Ñ!Ø×ÑÐ  Ð(Øð "ð 
ð 	
r&   c                 óR   • U R                   R                  U R                   S3SUS9$ )z¬
Purges the endpoint's job queue and returns the result of the purge request.

Args:
    timeout: The number of seconds to wait for the server to respond before giving up.
z/purge-queueNrn   )rR   r8   rN   re   s     r#   Úpurge_queueÚEndpoint.purge_queue  s7   € ð �~‰~×"Ñ"Ø×ÑÐ  Ð-ØØð #ð 
ð 	
r&   )rN   rR   r?   )i€Q rq   )rA   rB   rC   rD   rE   rF   r   r$   r   r   rL   r}   rH   r€   rƒ   r†   rI   rJ   r&   r#   rt   rt   »   s¨   † Ù@ñ7 Cð 7°(¸3±-õ 7ð"H  c¨3 h¡ð H°Cô Hð( =Bñ"Ø! # s (™^ð"Ø69ð"à	ˆc�3ˆh‰õ"ñ4

˜cð 

¨$¨s°C¨x©.õ 

ñ
 3ð 
¨t°C¸°H©~÷ 
ð 
r&   rt   )rE   rb   Útypingr   r   r   r   Úrequests.adaptersr   r   Úrunpod.endpoint.helpersr   r	   r
   r   r   rL   rt   rJ   r&   r#   Ú<module>r‹      sK   ðñó ß &Ñ &ã ß 0÷ó ÷H?ñ H?÷\Q
ñ Q
÷nX
ò X
r&   