Ë
    µŒjÊ  ã                   óª   — 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y)é    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y)ÚOpaquePromptsaj  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_community.chat_models import ChatOpenAI

            op_llm = OpaquePrompts(base_llm=ChatOpenAI())
    Úbase_llmÚforbid)ÚextraÚvaluesÚreturnc                 ó¦   — 	 ddl }|j                  €t        d«      ‚t	        |ddd¬«      }|st        d	«      ‚|S # t        $ r t        d«      ‚w xY w)
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       úp/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/llms/opaqueprompts.pyÚvalidate_environmentz"OpaquePrompts.validate_environment(   s�   € ð	Û&ð �>‰>Ð!Üð5óð ô
 'ØÐ+Ð-DÈbô
ˆñ Üð5óð ð ˆøô+ ò 	ÜðFóð ð	ús	   ‚; »ANÚpromptÚstopÚrun_managerÚkwargsc                 ó\  — ddl }|xs t        j                  «       }|j                  |g«      }|j                  d   }| j
                  j                  |¬«      j                  |«      }	t        |	t        «      r|	j                  }	|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Ñ&OÓ&Qˆð 24·±¸f¸XÓ1FÐØ%6×%FÑ%FÀqÑ%IÐ"ð —}‘}×)Ñ)¨tÐ)Ó4×;Ñ;Ø&ó
ˆô �l¤IÔ.Ø'×/Ñ/ˆLð 68·]±]ØØ,×;Ñ;ð 6Có 6
Ðð #×3Ñ3Ð3ó    c                  ó   — y)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ò ó ðð< %)Ø:>ñ	)4àð)4ð �t˜C‘yÑ!ð)4ð Ð6Ñ7ð	)4ð
 ð)4ð 
ó)4ðV ð˜3ò ó ñ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Ý -ß ?Ý à	ˆ×	Ñ	˜8Ó	$€ôg�Cõ gr9   