a
    bg                     @   s^   d dl mZmZ eeeeef f eeeeeeef f f dddZeeedddZdS )	    )DictUnion)inputreturnc           	      C   s   zddl }W n ty&   tdY n0 t| trP|| g}|jd |jdS t| trt }| D ]}|	| |  qd||}|j}d}t }| D ]}|| ||< |d7 }q||jdS t
dt|  dS )a  
    Sanitize input string or dict of strings by replacing sensitive data with
    placeholders.

    It returns the sanitized input string or dict of strings and the secure
    context as a dict following the format:
    {
        "sanitized_input": <sanitized input string or dict of strings>,
        "secure_context": <secure context>
    }

    The secure context is a bytes object that is needed to de-sanitize the response
    from the LLM.

    Args:
        input: Input string or dict of strings.

    Returns:
        Sanitized input string or dict of strings and the secure context
        as a dict following the format:
        {
            "sanitized_input": <sanitized input string or dict of strings>,
            "secure_context": <secure context>
        }

        The `secure_context` needs to be passed to the `desanitize` function.

    Raises:
        ValueError: If the input is not a string or dict of strings.
        ImportError: If the `opaqueprompts` Python package is not installed.
    r   NhCould not import the `opaqueprompts` Python package, please install it with `pip install opaqueprompts`.)sanitized_inputsecure_context   zUnexpected input type )opaquepromptsImportError
isinstancestrsanitizeZsanitized_textsr   dictlistappend
ValueErrortype)	r   opZsanitize_responsevalueskeyZsanitize_values_responseZsanitized_input_valuesidxr    r   y/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/utilities/opaqueprompts.pyr      s4    "




r   )sanitized_textr   r   c                 C   s:   zddl }W n ty&   tdY n0 || |}|jS )z
    Restore the original sensitive data from the sanitized text.

    Args:
        sanitized_text: Sanitized text.
        secure_context: Secure context returned by the `sanitize` function.

    Returns:
        De-sanitized text.
    r   Nr   )r
   r   
desanitizeZdesanitized_text)r   r   r   Zdesanitize_responser   r   r   r   Q   s    
r   N)typingr   r   r   r   bytesr   r   r   r   r   <module>   s   M