o
    Zh                     @   s   d dl mZmZmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZmZ d dlmZmZmZ d dlmZmZ G dd de
Zd	S )
    )AnyDictListOptionalUnioncast)CallbackManagerForLLMRun)LLM)convert_to_secret_strget_from_dict_or_env)
ConfigDict	SecretStrmodel_validator)ArceeWrapper
DALMFilterc                       s  e Zd ZU dZdZee ed< 	 dZe	e
edf ed< 	 eed< 	 dZeed< 	 dZeed	< 	 d
Zeed< 	 dZeed< 	 dZeeeef  ed< 	 eddZedefddZdeddf fddZeddededefddZ		d"dedeee  dee dedef
d d!Z  ZS )#Arceea  Arcee's Domain Adapted Language Models (DALMs).

    To use, set the ``ARCEE_API_KEY`` environment variable with your Arcee API key,
    or pass ``arcee_api_key`` as a named parameter.

    Example:
        .. code-block:: python

            from langchain_community.llms import Arcee

            arcee = Arcee(
                model="DALM-PubMed",
                arcee_api_key="ARCEE-API-KEY"
            )

            response = arcee("AI-driven music therapy")
    N_clientarcee_api_keymodelzhttps://api.arcee.aiarcee_api_urlv2arcee_api_versionzhttps://app.arcee.aiarcee_app_url model_idmodel_kwargsZforbid)extrareturnc                 C   s   dS )zReturn type of llm.Zarcee )selfr   r   U/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/llms/arcee.py	_llm_type:   s   zArcee._llm_typedatac                    s>   t  jdi | tt| j}t|| j| j| j| j	d| _
dS )zInitializes private fields.)r   r   r   r   Z
model_nameNr   )super__init__r   r   r   r   r   r   r   r   r   )r   r"   Zapi_key	__class__r   r    r$   ?   s   zArcee.__init__before)modevaluesc                 C   s   t t|dd|d< t|dd|d< t|dd|d< t|dd|d< |d	r_|d	 }|d
dur=|d
dks=td|ddur_t|dtsPtd|dD ]	}tdi | qU|S )z%Validate Arcee environment variables.r   ZARCEE_API_KEYr   ZARCEE_API_URLr   ZARCEE_APP_URLr   ZARCEE_API_VERSIONr   sizeNr   z`size` must be positivefiltersz`filters` must be a listr   )r
   r   get
ValueError
isinstancer   r   )clsr)   kwfr   r   r    validate_environmentsL   sB   
zArcee.validate_environmentspromptstoprun_managerkwargsc              
   K   sP   z| j std| j jdd|i|W S  ty' } ztd| |d}~ww )a)  Generate text from Arcee DALM.

        Args:
            prompt: Prompt to generate text from.
            size: The max number of context results to retrieve.
            Defaults to 3. (Can be less if filters are provided).
            filters: Filters to apply to the context dataset.
        zClient is not initialized.r3   zFailed to generate text: Nr   )r   r-   generate	Exception)r   r3   r4   r5   r6   er   r   r    _call}   s   zArcee._call)NN)__name__
__module____qualname____doc__r   r   r   __annotations__r   r   r   strr   r   r   r   r   r   r   r   Zmodel_configpropertyr!   r$   r   classmethodr2   r   r   r:   __classcell__r   r   r%   r    r      sP   
 2
r   N)typingr   r   r   r   r   r   Zlangchain_core.callbacksr   Z#langchain_core.language_models.llmsr	   Zlangchain_core.utilsr
   r   Zpydanticr   r   r   Z#langchain_community.utilities.arceer   r   r   r   r   r   r    <module>   s     