§
    šŠtj»  ã                   ó®   — 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 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)Ú	AIMessage)Úget_from_dict_or_envÚpre_init)Ú
ConfigDictc                   óº   — e Zd ZU dZeed<   	  e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 )ÚOpaquePromptsa[  LLM 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_openai import ChatOpenAI

            op_llm = OpaquePrompts(base_llm=ChatOpenAI())
    Úbase_llmÚforbid)ÚextraÚ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       úd/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/llms/opaqueprompts.pyÚvalidate_environmentz"OpaquePrompts.validate_environment(   s³   € ð	Ø&Ð&Ð&Ð&Ð&øÝð 	ð 	ð 	ÝðFñô ð ð	øøøð
 Œ>Ð!Ýð5ñô ð õ
 'ØÐ+Ð-DÈbð
ñ 
ô 
ˆð ð 	Ýð5ñô ð ð ˆs   ‚ ‡!NÚpromptÚstopÚrun_managerÚkwargsc                 óT  — ddl }|pt          j        ¦   «         }|                     |g¦  «        }|j        d         }| j                             |¬¦  «                             |¦  «        }	t          |	t          ¦  «        r|	j
        }	|                     |	|j        ¬¦  «        }
|
j        S )aC  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.invoke("Tell me a joke.")
        r   N)r$   )Úsecure_context)r   r   Úget_noop_managerÚsanitizeÚsanitized_textsr   ÚbindÚinvokeÚ
isinstancer
   ÚcontentÚ
desanitizer(   Ú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Ð"ð ”}×)Ò)¨tÐ)Ñ4Ô4×;Ò;Ø&ñ
ô 
ˆõ �l¥IÑ.Ô.ð 	0Ø'Ô/ˆLð 68·]²]ØØ,Ô;ð 6Cñ 6
ô 6
Ðð #Ô3Ð3ó    c                 ó   — dS )zSReturn type of LLM.

        This is an override of the base class method.
        r   © )r2   s    r!   Ú	_llm_typezOpaquePrompts._llm_typeo   s	   € ð ˆr9   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   Úmodel_configr   r   r"   Ústrr   r   r   r   r8   Úpropertyr<   r;   r9   r!   r   r      s   € € € € € € ðð ð$  ÐÐÑØà�:Øðñ ô €Lð ð¨$ð °4ð ð ð ñ „Xðð< %)Ø:>ð	)4ð )4àð)4ð �t˜C”yÔ!ð)4ð Ð6Ô7ð	)4ð
 ð)4ð 
ð)4ð )4ð )4ð )4ðV ð˜3ð ð ð ñ „Xðð ð r9   r   )ÚloggingÚtypingr   r   r   r   Úlangchain_core.callbacksr   Úlangchain_core.language_modelsr   Ú#langchain_core.language_models.llmsr	   Úlangchain_core.messagesr
   Úlangchain_core.utilsr   r   Úpydanticr   Ú	getLoggerr=   Úloggerr   r;   r9   r!   ú<module>rO      sô   ðØ €€€Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,à =Ð =Ð =Ð =Ð =Ð =Ø <Ð <Ð <Ð <Ð <Ð <Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø -Ð -Ð -Ð -Ð -Ð -Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø Ð Ð Ð Ð Ð à	ˆÔ	˜8Ñ	$Ô	$€ðgð gð gð gð g�Cñ gô gð gð gð gr9   