
    7|h                         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y
)    )partial)AnyDictListMappingOptionalSet)CallbackManagerForLLMRun)LLM)pre_init)
ConfigDictField)enforce_stop_tokensc                   Z   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Z2y)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/test/engine/venv/lib/python3.12/site-packages/langchain_community/llms/gpt4all.py_model_param_nameszGPT4All._model_param_namesg   s    

 
	
r8   c           
          | 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   sO    //ZZZZII||"11!//

 
	
r8   valuesc                    	 ddl m} |d   }|j                  d      \  }}}||z  } |||xs d|d   |d   |d	   
      |d<   |d   !|d   j                  j                  |d          	 |d   j                  |d<   |S # t        $ r t        d      w xY w# t        $ r  |d   j                  j                  |d<   Y |S w xY w)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   s   	7 7O	,5,@,@,E)
Izi
'!)Ti(!"23(#
x +*8""33F;4GH	B &x 0 ; ;F9
 7  	@ 	.  	B &x 0 6 6 A AF9		Bs   A? +B ?B%C ?C c                     d| j                   i| j                         | j                  j                         D ci c]  \  }}|| j	                         v s|| c}}S c c}}w )zGet the identifying parameters.r   )r   r?   __dict__itemsr:   )r>   kvs      r9   _identifying_paramszGPT4All._identifying_params   sl     TZZ
""$
 "&!4!4!6A!t?V?V?X:X1
 	
s   A A c                      y)zReturn the type of llm.rE   r7   r=   s    r9   	_llm_typezGPT4All._llm_type   s     r8   promptrun_managerkwargsc                     d}|r!t        |j                  | j                        }d}i | j                         |} | 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>   rX   r(   rY   rZ   text_callbacktextparamstokens	            r9   _callzGPT4All._call   s    , #K$@$@$,,WM5D((*5f5)T[[))&;F; 	Ee$EMD	 &tT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   rU   rW   r
   rd   r7   r8   r9   r   r      s    J5"4y9GXc]9C|4J49-GS-? av&D#&-h/FD/1U,7J7@U,7J7/E5It5,E5It5"$Qk:Ix}:#"Ix}"3D(5/. E8E? .E8C=. D(4. % "D(49
"@#%M8C=%&*NHUO*2),GS,+It/ ND D!%x8FHSM8BFCL 
C 
 

c3h 
 $ 4  B 
WS#X%6 
 
 3   %):>	!! 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>rx      s+     : : = 3 ) & >Ic Ir8   