
    7|h              
       j    d dl mZmZ deeeeef   f   deeeeeeef   f   f   fdZdededefdZy)	    )DictUnioninputreturnc                    	 ddl }t        | t              r.|j	                  | g      }|j
                  d   |j                  dS t        | t              rqt               }| D ]  }|j                  | |           |j	                  |      }|j
                  }d}t               }| D ]  }||   ||<   |dz  } ||j                  dS t        dt        |              # t        $ r t        d      w xY w)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sanitizesanitized_textsr
   dictlistappend
ValueErrortype)	r   opsanitize_responsevalueskeysanitize_values_responsesanitized_input_valuesidxr	   s	            j/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/utilities/opaqueprompts.pyr   r      s%   D
" %13eW1E0@@C/>>
 	

 %  	&CMM%*%	& 9;F8K  ":!I!I& 	C#9##>OC 1HC	
  /6EE
 	

 -d5k];
<<M  
B
 	

s   C C1sanitized_textr
   c                 x    	 ddl }|j                  | |      }|j                  S # t        $ r t        d      w xY w)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   
desanitizedesanitized_text)r   r
   r   desanitize_responses       r   r!   r!   Q   sR    
" 242 ///  
B
 	

s   $ 9N)typingr   r   r   r   bytesr!        r   <module>r(      si    J=d38n$%J=	#uS$sCx.()
)*J=Z0s 0E 0c 0r'   