o
    wi                     @   sJ   d dl Z d dlmZ d dlT dd ZdddZdd	 Zd
d Zdd ZdS )    N)service_pb2)*c                 C   s   t |  t|  |  dS )zConvert a gRPC error to an :py:class:`InferenceServerException`.

    Parameters
    ----------
    rpc_error : grpc.RpcError
        The gRPC error

    Returns
    -------
    InferenceServerException
    )msgstatusdebug_details)InferenceServerExceptiondetailsstrcodedebug_error_string	rpc_error r   U/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/tritonclient/grpc/_utils.pyget_error_grpc"   s
   
r   c                 C   s   | sd} t | ddS )zGet :py:class:`InferenceServerException` object for a cancelled RPC.

    Returns
    -------
    InferenceServerException
    z!Locally cancelled by application!zStatusCode.CANCELLED)r   r   )r   )r   r   r   r   get_cancelled_error5   s   r   c                 C   s
   t | d)zRaise an :py:class:`InferenceServerException` from a gRPC error.

    Parameters
    ----------
    rpc_error : grpc.RpcError
        The gRPC error

    Raises
    -------
    InferenceServerException
    N)r   r   r   r   r   raise_error_grpcA   s   
r   c                 C   s  t  }| |_||_|dkr||_|D ]}|j| g | d ur-|j	| g q|d ur@|D ]}|j
| g q4|dkrf|dkrft|trT||jd _n||jd _||jd _||jd _|dkrp||jd _|	d urz|	|jd _|
r|
 D ]^\}}|dks|dks|dks|dks|dkrtd	| d
 qt|tr||j| _qt|tr||j| _qt|tr||j| _qt|tr||j| _qtdt| d| d q|S )N r   sequence_idsequence_startsequence_endprioritytimeoutbinary_data_outputzParameter "z2" is a reserved parameter and cannot be specified.zThe parameter datatype "z" for key "z" is not supported.)r   ModelInferRequest
model_namemodel_versionidinputsextend_get_tensor_get_contentraw_input_contentsoutputs
isinstancer	   
parametersstring_paramint64_param
bool_paramuint64_paramitemsraise_errorboolintfloatdouble_paramtype)r   r   r   
request_idr#   r   r   r   r   r   r%   requestinfer_inputinfer_outputkeyvaluer   r   r   _get_inference_requestP   sZ   





r7   c                 C   sH   | d u rt jjS |  dkrt jjS |  dkrt jjS td t jjS )NdeflategzipzWThe provided client-side compression algorithm is not supported... using no compression)grpcCompressionNoCompressionlowerDeflateGzipprint)algorithm_strr   r   r   _grpc_compression_type   s   rB   )N)	r:   tritonclient.grpcr   tritonclient.utilsr   r   r   r7   rB   r   r   r   r   <module>   s   
B