
    Ng              
           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dS )	    )DictUnioninputreturnc                 "   	 ddl }n# t          $ r t          d          w xY wt          | t                    r+|                    | g          }|j        d         |j        dS t          | t                    ryt                      }| D ]}|	                    | |                    |                    |          }|j        }d}t                      }| D ]}||         ||<   |dz  }||j        dS t          dt          |                      )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	            g/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/utilities/opaqueprompts.pyr   r      sh   D
""""" 
 
 
B
 
 	

 % 
13eW1E1E0@C/>
 
 	

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

 ;d5kk;;
<
<<    !sanitized_textr
   c                     	 ddl }n# t          $ r t          d          w xY w|                    | |          }|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   
desanitizedesanitized_text)r    r
   r   desanitize_responses       r   r"   r"   Q   so    
""""" 
 
 
B
 
 	


 242 2 //r   N)typingr   r   r   r   bytesr"        r   <module>r)      s           J=d38n$%J=	#uS$sCx.()
)*J= J= J= J=Z0s 0E 0c 0 0 0 0 0 0r(   