
    Ng                         d dl mZ 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 d dlmZmZ d dlmZ  G d d	e          Zd
S )    )partial)AnyDictListMappingOptionalSet)CallbackManagerForLLMRun)LLM)pre_init)
ConfigDictField)enforce_stop_tokensc                   .   e Zd ZU dZeed<   	  edd          Zee         ed<    edd          Z	e
ed<   	  edd	          Ze
ed	<   	  ed
d          Ze
ed<   	  edd          Zeed<   	  edd          Zeed<   	  edd          Zeed<   	  edd          Zeed<   	  edd          Zeed<   	  edd          Zee
         ed<   	 dZee
         ed<   	 dZee         ed<   	 dZee         ed<   	 dZee
         ed<   	 dZee         ed<   	 g Zeee                  ed<   	 dZee
         ed<   	 d Zee         ed!<   	  ed"d#          Ze
ed#<   	 dZeed$<   	 dZ eed%<   	  ed&d'          Z!ee         ed'<   	 dZ"e#ed(<    e$d)*          Z%e&d+e'e         fd,            Z(d+e)ee#f         fd-Z*e+d.e)d+e)fd/            Z,e-d+e.ee#f         fd0            Z/e-d+efd1            Z0	 	 d6d2edeee                  d3ee1         d4e#d+ef
d5Z2dS )7GPT4Alla  GPT4All language models.

    To use, you should have the ``gpt4all`` python package installed, the
    pre-trained model file, and the model's config information.

    Example:
        .. code-block:: python

            from langchain_community.llms import GPT4All
            model = GPT4All(model="./models/gpt4all-model.bin", n_threads=8)

            # Simplest invocation
            response = model.invoke("Once upon a time, ")
    modelNbackend)alias   
max_tokensn_partsr   seedFf16_kv
logits_all
vocab_only	use_mlock	embedding   	n_threads   	n_predictgffffff?tempg?top_p(   top_kechostop@   repeat_last_ngzG?repeat_penalty   n_batch	streamingallow_downloadcpudeviceclientforbid)extrareturnc                  
    h dS )N>	   r#   r&   r$   r-   r"   r.   r   r*   r+    r7       \/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/llms/gpt4all.py_model_param_nameszGPT4All._model_param_namesg   s    

 

 

 
	
r8   c           
      t    | j         | j        | j        | j        | j        | j        | j        | j        | j        d	S )N	r   r"   r&   r$   r#   r-   r+   r*   r.   r<   selfs    r9   _default_paramszGPT4All._default_paramsu   s@    /ZZI|"1!/

 

 
	
r8   valuesc                    	 ddl m} n# t          $ r t          d          w xY w|d         }|                    d          \  }}}||z  } |||pd|d         |d         |d	         
          |d<   |d         &|d         j                            |d                    	 |d         j        |d<   n%# t          $ r |d         j        j        |d<   Y nw xY w|S )z;Validate that the python package exists in the environment.r   )r   zVCould not import gpt4all python package. Please install it with `pip install gpt4all`.r   /Nr   r/   r1   )
model_path
model_typer/   r1   r2   r    )gpt4allr   ImportError
rpartitionr   set_thread_countrD   AttributeError)clsr@   GPT4AllModel	full_pathrC   	delimiter
model_names          r9   validate_environmentzGPT4All.validate_environment   sG   	7777777 	 	 	@  	 7O	,5,@,@,E,E)
Izi
'<!)Ti(!"23(#
 
 
x +*8"33F;4GHHH	B &x 0 ;F9 	B 	B 	B &x 0 6 AF9	B s   	 #"B3 3CCc                      d j         i                                  fd j                                        D             S )zGet the identifying parameters.r   c                 H    i | ]\  }}|                                 v ||S r7   )r:   ).0kvr>   s      r9   
<dictcomp>z/GPT4All._identifying_params.<locals>.<dictcomp>   s<       A!t?V?V?X?X:X:X1:X:X:Xr8   )r   r?   __dict__itemsr=   s   `r9   _identifying_paramszGPT4All._identifying_params   sc     TZ
""$$
   !%!4!4!6!6  
 	
r8   c                     dS )zReturn the type of llm.rE   r7   r=   s    r9   	_llm_typezGPT4All._llm_type   s	     yr8   promptrun_managerkwargsc                     d}|rt          |j        | j                  }d}i |                                 |} | j        j        |fi |D ]}|r ||           ||z  }|t          ||          }|S )a  Call out to GPT4All's generate method.

        Args:
            prompt: The prompt to pass into the model.
            stop: A list of strings to stop generation when encountered.

        Returns:
            The string generated by the model.

        Example:
            .. code-block:: python

                prompt = "Once upon a time, "
                response = model.invoke(prompt, n_predict=55)
        N)verbose )r   on_llm_new_tokenr_   r?   r2   generater   )	r>   r[   r(   r\   r]   text_callbacktextparamstokens	            r9   _callzGPT4All._call   s    ,  	X#K$@$,WWWM5D((**5f5)T[)&;;F;; 	 	E %e$$$EMDD&tT22Dr8   )NN)3__name__
__module____qualname____doc__str__annotations__r   r   r   r   intr   r   r   boolr   r   r   r   r    r"   r#   floatr$   r&   r'   r(   r   r*   r+   r-   r.   r/   r1   r2   r   r   model_configstaticmethodr	   r:   r   r?   r   rO   propertyr   rX   rZ   r
   rg   r7   r8   r9   r   r      s          JJJ5"U4y999GXc]999eC|444J44459---GS---? av&&&D#&&&-5h///FD///1uU,777J777@uU,777J777/eE555It555,eE555It555"$uQk:::Ix}:::#"Ix}"""3D(5/. E8E?   .E8C=. D(4.   % "D(49
"""@#%M8C=%%%&*NHUO***25),,,GS,,,+It/ ND   D!E%x888FHSM888BFC:  L 
C 
 
 
 \

c3h 
 
 
 
 $ 4    XB 
WS#X%6 
 
 
 X
 3    X %):>	! !! tCy!! 67	!
 ! 
! ! ! ! ! !r8   r   N)	functoolsr   typingr   r   r   r   r   r	   langchain_core.callbacksr
   #langchain_core.language_models.llmsr   langchain_core.utilsr   pydanticr   r   langchain_community.llms.utilsr   r   r7   r8   r9   <module>r{      s          : : : : : : : : : : : : : : : : = = = = = = 3 3 3 3 3 3 ) ) ) ) ) ) & & & & & & & & > > > > > >I I I I Ic I I I I Ir8   