
    9i"                         S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJr  SSKJr  SSKr\R:                  " \5      rS r  " S S\
5      r!g)z3
This module provides a client class for infinite.
    N)utils)compat)bce_v1_signer)BceBaseClient)bce_http_client)handler)http_headers)http_content_types)http_methods)required)infinite)BceClientError)BceServerError)BceClientConfigurationc                    U R                   S-  [        R                  R                  S-  :X  a  [	        S5      eU R                   S-  [        R                  R
                  S-  :X  aE  U R                  5       nU(       a  UR                  R                  SU05        U R                  5         g[        U R                  UR                  R                  S9nU R                   Ul        U R                  5         Ue)Nd   z#Can not handle 1xx http status codeBodyT)
request_id)statushttpclientCONTINUEr   OKread__dict__updatecloser   reasonmetadatabce_request_idstatus_code)http_responseresponsebodybses       j/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/baidubce/services/infinite/infinite_client.py_parse_http_responser'   ,   s    c!T[[%9%9C%??BCCc!T[[^^c%99!!#$$fd^4
--(:K:K:Z:Z
[C#**CO
I    c                       \ rS rSrSrSS jr  SS jr   SS jrSS jrSS jr	\
SS	 j5       rS
 rSS jr    SS jrSrg)InfiniteClient;   z
Infinite sdk client
Nc                 0    [         R                  " X5        g N)r   __init__selfconfigs     r&   r.   InfiniteClient.__init__?   s    t,r(   c           	      
   0 nUb  X7S'   SUS'   XgS'   [         R                  nUS-   U-   n[        R                  U[        R                  [
        R                  " 5       0n	U R                  [        R                  US-   UU	UUS9$ )a  
predict

:param endpoint_name: endpoint name
:type endpoint_name: string

:param body: request data
:type body: binary string or dict

:param variant_name: variant name or None
:type variant_name: string

:param content_type: content type,supports application/json,x-image,and x-recordio-protobuf
:type content_type: string

:param config: None
:type config: BceClientConfiguration

:param interface: interface_name,
    several of predict/predict_proba/predict_log_proba/fit_predict/staged_predict/staged_predict are supported
    depend on frameworks and algorithm used

:return: response as following format
    {
        Body: 'predict result'
    }
:rtype: baidubce.bce_response.BceResponse
variantpredictaction	interface
; charset=/invocationshttp_methodfunction_namer$   headersparamsr1   
baidubceDEFAULT_ENCODINGr	   CONTENT_TYPEBCE_REQUEST_IDuuiduuid4_send_requestr   POST
r0   endpoint_namer$   variant_namecontent_typer1   r7   r>   default_encodingr=   s
             r&   r5   InfiniteClient.predictB   s    > # ,9$x'{#44#l25EE%%|''

 !!(--+n< "  	r(   c           	      
   0 nUb  X7S'   SUS'   XgS'   [         R                  nUS-   U-   n[        R                  U[        R                  [
        R                  " 5       0n	U R                  [        R                  US-   UU	UUS9$ )a  
debug

:param endpoint_name: endpoint name
:type endpoint_name: string

:param body: request data
:type body: binary or dict

:param variant_name: variant name or None
:type variant_name: string

:param content_type: content type,supports application/json,x-image,and x-recordio-protobuf
:type content_type: string

:param config: None
:type config: BceClientConfiguration

:param interface: interface_name,
    several of predict/predict_proba/predict_log_proba/fit_predict/staged_predict/staged_predict are supported
    depend on frameworks and algorithm used
:type config: string

:return: response as following format
    {
        Body: 'debug info'
    }
:rtype: baidubce.bce_response.BceResponse
r4   debugr6   r7   r8   r9   r:   r?   rH   s
             r&   rO   InfiniteClient.debugv   s    @ # ,9"x'{#44#l25EE%%|''

 !!(--+n< "  	r(   c                     [         R                  [        R                  [         R                  [
        R                  " 5       0nU R                  [        R                  SUUS9$ )z
get all endpoint

:param config: None
:type config: BceClientConfiguration

:return: response as following format
    {
        Body: '{"endpointList":["ep1_name","ep2_name"]}'
    }
:rtype: baidubce.bce_response.BceResponse
listr;   r<   r=   r1   
r	   rB   r
   JSONrC   rD   rE   rF   r   GET)r0   r1   r=   s      r&   get_endpoint_list InfiniteClient.get_endpoint_list   sZ     %%'9'>'>''
 !!(,,$	 "  	r(   c                     [         R                  [        R                  [         R                  [
        R                  " 5       0nU R                  [        R                  US-   UUS9$ )a  
get endpoint info

:param endpoint_name: endpoint name
:type endpoint_name: string

:param config: None
:type config: BceClientConfiguration

:return: response as following format
    {
        Body: '{
            "endpoint_uuid":"ep1",
            "variant_configs":[
                {
                    "variant_uuid":"v1",
                    "variant_name":"v1_name",
                    "...":"..."
                }
            ]
        }'
    }
:rtype: baidubce.bce_response.BceResponse
z/inforS   rT   )r0   rI   r1   r=   s       r&   get_endpoint_info InfiniteClient.get_endpoint_info   s_    4 %%'9'>'>''
 !!(,,+g5	 "  	r(   c                 t    [         R                  " [        R                  [        R
                  " U5      5      $ r-   )r   
append_urir   
URL_PREFIXr   convert_to_bytes)r1   r<   s     r&   	_get_pathInfiniteClient._get_path   s&     3 3V5L5L]5[\\r(   c                     Uc  U R                  U R                  5      $ [        R                  " U R                  5      nUR                  U5        U R                  U5      nU$ r-   )_convert_configr1   copymerge_non_none_values)r0   r1   
new_configs      r&   _merge_configInfiniteClient._merge_config   sR    >''444;;/J,,V4--j9Jr(   c                 n   Ub  UR                   b%  [        R                  " UR                   5      Ul         UR                  br  [        R                  " UR                  R                  5      UR                  l        [        R                  " UR                  R
                  5      UR                  l        U$ r-   )endpointr   r_   credentialsaccess_key_idsecret_access_keyr/   s     r&   rc   InfiniteClient._convert_config   s    *"("9"9&//"J!!-++F,>,>,L,LM ""0 ++F,>,>,P,PQ ""4r(   c           
          U R                  U5      n[        R                  Xb5      nUc  [        n[        R
                  " U[        R                  U/XX4U5      $ r-   )rg   r*   r`   r'   r   send_requestr   sign)	r0   r;   r<   r$   r=   r>   r1   body_parserpaths	            r&   rF   InfiniteClient._send_request   sX    
 ##F+''>.K++M&&tf6 	6r(    r-   )Nzapplication/jsonNr5   )NNNNNN)__name__
__module____qualname____firstlineno____doc__r.   r5   rO   rW   rZ   staticmethodr`   rg   rc   rF   __static_attributes__ru   r(   r&   r*   r*   ;   sk    - HL2h 7;483j.!F ] ]	 .2,0	6r(   r*   )"rz   rd   loggingwarningsr@   r   r   baidubce.authr   baidubce.bce_base_clientr   baidubce.httpr   r   r	   r
   r   baidubce.utilsr   baidubce.servicesr   http.clientr   baidubce.exceptionr   r   !baidubce.bce_client_configurationr   rD   	getLoggerrv   _loggerr'   r*   ru   r(   r&   <module>r      sk   "       ' 2 ) ! & , & # &  - - D 


H
%M6] M6r(   