a
    dgs                     @  s   d Z ddlmZ ddl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 ddlmZmZ erzddlZdd	lmZ n$zdd	lmZ W n ey   Y n0 d
dddZG dd de
ZdS )z1Experimental implementation of RELLM wrapped LLM.    )annotations)TYPE_CHECKINGAnyListOptionalcast)HuggingFacePipeline)enforce_stop_tokens)CallbackManagerForLLMRun)Fieldmodel_validatorN)Patternrellm)returnc                  C  s,   zddl } W n ty&   tdY n0 | S )z#Lazily import of the rellm package.r   NzRCould not import rellm python package. Please install it with `pip install rellm`.)r   ImportError)r    r   w/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_experimental/llms/rellm_decoder.pyimport_rellm   s    
r   c                   @  sp   e Zd ZU dZedddZded< eddd	Zd
ed< edde	dddddZ
dddddddddZdS )RELLMz1RELLM wrapped LLM using HuggingFace Pipeline API..z"The structured format to complete.)descriptionRegexPatternregex   z)Maximum number of new tokens to generate.)defaultr   intmax_new_tokensbefore)modedictr   )valuesr   c                 C  s
   t   |S )N)r   )clsr   r   r   r   check_rellm_installation*   s    zRELLM.check_rellm_installationNstrzOptional[List[str]]z"Optional[CallbackManagerForLLMRun])promptstoprun_managerkwargsr   c           	      K  sP   t  }ddlm} t|| j}|j|| j|j|j| j	d}|d urLt
||}|S )Nr   )Text2TextGenerationPipeline)	tokenizermodelr   )r   Ztransformersr'   r   pipelineZcomplete_rer   r(   r)   r   r	   )	selfr#   r$   r%   r&   r   r'   r*   textr   r   r   _call0   s    
zRELLM._call)NN)__name__
__module____qualname____doc__r   r   __annotations__r   r   classmethodr!   r-   r   r   r   r   r   "   s   
  r   )r1   
__future__r   typingr   r   r   r   r   Z-langchain_community.llms.huggingface_pipeliner   Zlangchain_community.llms.utilsr	   Z langchain_core.callbacks.managerr
   Zpydanticr   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s   