U
    h                     @   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 d dlmZmZ G dd de
Zd	S )
    )AnyDictListOptionalUnioncast)CallbackManagerForLLMRun)LLM)	SecretStrroot_validator)convert_to_secret_strget_from_dict_or_env)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< G dd dZeedddZedd fddZeddeedddZdeeee  ee eed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_urlZv2arcee_api_versionzhttps://app.arcee.aiarcee_app_url model_idmodel_kwargsc                   @   s   e Zd ZdZdZdS )zArcee.ConfigZforbidTN)__name__
__module____qualname__extraZunderscore_attrs_are_private r   r   B/tmp/pip-unpacked-wheel-9gdii04g/langchain_community/llms/arcee.pyConfig6   s   r    )returnc                 C   s   dS )zReturn type of llm.Zarceer   )selfr   r   r   	_llm_type:   s    zArcee._llm_type)datar!   c                    s:   t  jf | tt| j}t|| j| j| j| j	d| _
dS )zInitializes private fields.)r   r   r   r   Z
model_nameN)super__init__r   r
   r   r   r   r   r   r   r   )r"   r$   Zapi_key	__class__r   r   r&   ?   s    zArcee.__init__T)pre)valuesr!   c                 C   s   t t|dd|d< t|dd|d< t|dd|d< t|dd|d< |d	r|d	 }|d
dk	rz|d
dksztd|ddk	rt|dtstd|dD ]}tf | q|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 list)r   r   get
ValueError
isinstancer   r   )clsr*   kwfr   r   r   validate_environmentsL   sB    
zArcee.validate_environments)promptstoprun_managerkwargsr!   c              
   K   s^   z&| j std| j jf d|i|W S  tk
rX } ztd| |W 5 d}~X Y nX dS )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.r4   zFailed to generate text: N)r   r.   generate	Exception)r"   r4   r5   r6   r7   er   r   r   _call|   s    zArcee._call)NN)r   r   r   __doc__r   r   r   __annotations__r   r   r
   strr   r   r   r   r   r   r   r    propertyr#   r&   r   r3   r   r   r;   __classcell__r   r   r'   r   r      s0   
2  
r   N)typingr   r   r   r   r   r   Zlangchain_core.callbacksr   Z#langchain_core.language_models.llmsr	   Zlangchain_core.pydantic_v1r
   r   Zlangchain_core.utilsr   r   Z#langchain_community.utilities.arceer   r   r   r   r   r   r   <module>   s    