§
    æ˜ºhŒ  ã                   ó¢   — d dl Z d dlmZmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZ  e j        e¦  «        Z G d„ d	e¦  «        ZdS )
é    N)ÚAnyÚDictÚListÚOptional)ÚCallbackManagerForLLMRun)ÚBaseLanguageModel)ÚLLM)ÚExtraÚroot_validator)Úget_from_dict_or_envc                   óÌ   — e Zd ZU dZeed<   	  G d„ d¦  «        Z e¦   «         dedefd„¦   «         Z		 	 dd	e
d
eee
                  dee         dede
f
d„Zede
fd„¦   «         ZdS )ÚOpaquePromptsau  An LLM wrapper that uses OpaquePrompts to sanitize prompts.

    Wraps another LLM and sanitizes prompts before passing it to the LLM, then
        de-sanitizes the response.

    To use, you should have the ``opaqueprompts`` python package installed,
    and the environment variable ``OPAQUEPROMPTS_API_KEY`` set with
    your API key, or pass it as a named parameter to the constructor.

    Example:
        .. code-block:: python

            from langchain_community.llms import OpaquePrompts
            from langchain_community.chat_models import ChatOpenAI

            op_llm = OpaquePrompts(base_llm=ChatOpenAI())
    Úbase_llmc                   ó    — e Zd ZdZej        ZdS )úOpaquePrompts.Configz'Configuration for this pydantic object.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   ÚforbidÚextra© ó    ún/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/langchain_community/llms/opaqueprompts.pyÚConfigr   #   s   € € € € € Ø5Ð5à”ˆˆˆr   r   ÚvaluesÚreturnc                 óÀ   — 	 ddl }n# t          $ r t          d¦  «        ‚w xY w|j        €t          d¦  «        ‚t	          |ddd¬¦  «        }|st          d	¦  «        ‚|S )
zFValidates that the OpaquePrompts API key and the Python package exist.r   NzhCould not import the `opaqueprompts` Python package, please install it with `pip install opaqueprompts`.zMCould not properly import `opaqueprompts`, opaqueprompts.__package__ is None.Úopaqueprompts_api_keyÚOPAQUEPROMPTS_API_KEYÚ )ÚdefaultzËCould not find OPAQUEPROMPTS_API_KEY in the environment. Please set it to your OpaquePrompts API key.You can get it by creating an account on the OpaquePrompts website: https://opaqueprompts.opaque.co/ .)ÚopaquepromptsÚImportErrorÚ__package__Ú
ValueErrorr   )Úclsr   ÚopÚapi_keys       r   Úvalidate_environmentz"OpaquePrompts.validate_environment(   s³   € ð	Ø&Ð&Ð&Ð&Ð&øÝð 	ð 	ð 	ÝðFñô ð ð	øøøð
 Œ>Ð!Ýð5ñô ð õ
 'ØÐ+Ð-DÈbð
ñ 
ô 
ˆð ð 	Ýð5ñô ð ð ˆs   ‚ ‡!NÚpromptÚstopÚrun_managerÚkwargsc                 óø   — ddl }|pt          j        ¦   «         }|                     |g¦  «        }|j        d         }| j                             ||¬¦  «        }	|                     |	|j        ¬¦  «        }
|
j	        S )a<  Call base LLM with sanitization before and de-sanitization after.

        Args:
            prompt: The prompt to pass into the model.

        Returns:
            The string generated by the model.

        Example:
            .. code-block:: python

                response = op_llm("Tell me a joke.")
        r   N)r,   )Úsecure_context)
r#   r   Úget_noop_managerÚsanitizeÚsanitized_textsr   ÚpredictÚ
desanitizer0   Údesanitized_text)Úselfr+   r,   r-   r.   r(   Ú_run_managerÚsanitize_responseÚsanitized_prompt_value_strÚllm_responseÚdesanitize_responses              r   Ú_callzOpaquePrompts._callD   sœ   € ð( 	#Ð"Ð"Ð"à"ÐQÕ&>Ô&OÑ&QÔ&Qˆð 24·²¸f¸XÑ1FÔ1FÐØ%6Ô%FÀqÔ%IÐ"ð ”}×,Ò,Ø&Øð -ñ 
ô 
ˆð 68·]²]ØØ,Ô;ð 6Cñ 6
ô 6
Ðð #Ô3Ð3r   c                 ó   — dS )zSReturn type of LLM.

        This is an override of the base class method.
        r#   r   )r7   s    r   Ú	_llm_typezOpaquePrompts._llm_typen   s	   € ð ˆr   )NN)r   r   r   r   r   Ú__annotations__r   r   r   r*   Ústrr   r   r   r   r=   Úpropertyr?   r   r   r   r   r      s  € € € € € € ðð ð$  ÐÐÑØðð ð ð ð ñ ô ð ð
 €^ÑÔð¨$ð °4ð ð ð ñ Ôðð< %)Ø:>ð	(4ð (4àð(4ð �t˜C”yÔ!ð(4ð Ð6Ô7ð	(4ð
 ð(4ð 
ð(4ð (4ð (4ð (4ðT ð˜3ð ð ð ñ „Xðð ð r   r   )ÚloggingÚtypingr   r   r   r   Úlangchain_core.callbacksr   Úlangchain_core.language_modelsr   Ú#langchain_core.language_models.llmsr	   Úlangchain_core.pydantic_v1r
   r   Úlangchain_core.utilsr   Ú	getLoggerr   Úloggerr   r   r   r   ú<module>rL      sâ   ðØ €€€Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,à =Ð =Ð =Ð =Ð =Ð =Ø <Ð <Ð <Ð <Ð <Ð <Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5à	ˆÔ	˜8Ñ	$Ô	$€ðgð gð gð gð g�Cñ gô gð gð gð gr   