§
    šŠtjm%  ã                   óÎ   — d dl mZ d dlmZ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 d dlmZ d dl mZ d dlmZ d dl mZ d dlmZ  G d„ d	e¦  «        Zd
S )é    )Úpre_init)ÚAnyÚAsyncIteratorÚDictÚIteratorÚListÚOptionalÚUnion)Úroot_validator)ÚAsyncCallbackManagerForLLMRunÚCallbackManagerForLLMRun)ÚLLM)Úenforce_stop_tokens)ÚGenerationChunkc                   ó   — e Zd ZU dZeed<   eed<   	 dZee	eef                  ed<   	 dZ
edee	f         ed<   	 dZeed<   	 ed	e	eef         fd
„¦   «         Zed	efd„¦   «         Zede	d	e	fd„¦   «         Z	 	 ddedeee                  dee         ded	ef
d„Z	 	 ddedeee                  dee         ded	ef
d„Z	 	 ddedeee                  dee         ded	ee         f
d„Z	 	 ddedeee                  dee         ded	ee         f
d„ZdS )Ú
DeepSparseaH  Neural Magic DeepSparse LLM interface.
    To use, you should have the ``deepsparse`` or ``deepsparse-nightly``
    python package installed. See https://github.com/neuralmagic/deepsparse
    This interface let's you deploy optimized LLMs straight from the
    [SparseZoo](https://sparsezoo.neuralmagic.com/?useCase=text_generation)
    Example:
        .. code-block:: python
            from langchain_community.llms import DeepSparse
            llm = DeepSparse(model="zoo:nlg/text_generation/codegen_mono-350m/pytorch/huggingface/bigpython_bigquery_thepile/base_quant-none")
    ÚpipelineÚmodelNÚmodel_configurationÚgeneration_configFÚ	streamingÚreturnc                 ó8   — | j         | j        | j        | j        dœS )zGet the identifying parameters.)r   Úmodel_configr   r   )r   r   r   r   ©Úselfs    úa/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/llms/deepsparse.pyÚ_identifying_paramszDeepSparse._identifying_params1   s)   € ð ”ZØ Ô4Ø!%Ô!7Øœð	
ð 
ð 	
ó    c                 ó   — dS )zReturn type of llm.Ú
deepsparse© r   s    r   Ú	_llm_typezDeepSparse._llm_type;   s	   € ð ˆ|r   Úvaluesc                 ó–   — 	 ddl m} n# t          $ r t          d¦  «        ‚w xY w|d         pi } |j        d	d|d         dœ|¤Ž|d<   |S )
z2Validate that ``deepsparse`` package is installed.r   )ÚPipelinez[Could not import `deepsparse` package. Please install it with `pip install deepsparse[llm]`r   Útext_generationr   )ÚtaskÚ
model_pathr   r"   )r!   r&   ÚImportErrorÚcreate)Úclsr$   r&   r   s       r   Úvalidate_environmentzDeepSparse.validate_environment@   sž   € ð	Ø+Ð+Ð+Ð+Ð+Ð+Ð+øÝð 	ð 	ð 	ÝðGñô ð ð	øøøð Ð3Ô4Ð:¸ˆà,˜Xœ_ð 
Ø"Ø˜g”ð
ð 
ð ð
ð 
ˆˆzÑð
 ˆs   ‚	 ‰#ÚpromptÚstopÚrun_managerÚkwargsc                 óþ   — | j         r#d} | j        d|||dœ|¤ŽD ]}||j        z  }Œ|}n@ | j        dd|it	          | j        t          ¦  «        r| j        ni ¤Žj        d         j        }|�t          ||¦  «        }|S )á  Generate text from a prompt.
        Args:
            prompt: The prompt to generate text from.
            stop: A list of strings to stop generation when encountered.
        Returns:
            The generated text.
        Example:
            .. code-block:: python
                from langchain_community.llms import DeepSparse
                llm = DeepSparse(model="zoo:nlg/text_generation/codegen_mono-350m/pytorch/huggingface/bigpython_bigquery_thepile/base_quant-none")
                llm.invoke("Tell me a joke.")
        Ú ©r.   r/   r0   Ú	sequencesr   Nr"   )	r   Ú_streamÚtextr   Ú
isinstancer   ÚdictÚgenerationsr   ©r   r.   r/   r0   r1   Úcombined_outputÚchunkr8   s           r   Ú_callzDeepSparse._callT   sÙ   € ð& Œ>ð 	Ø ˆOØ%˜œð Ø D°kðð ØEKðð ð .ð .�ð   5¤:Ñ-��Ø"ˆDˆDð �”ð ð Ø$ðõ & dÔ&<½dÑCÔCð ˜Ô.Ð.àðð ô ˜Qô ô ð ð ÐÝ& t¨TÑ2Ô2ˆDàˆr   c              ‹   ó  K  — | j         r)d} | j        d|||dœ|¤Ž2 3 d{V —†}||j        z  }Œ6 |}n@ | j        dd|it	          | j        t          ¦  «        r| j        ni ¤Žj        d         j        }|�t          ||¦  «        }|S )r3   r4   r5   Nr6   r   r"   )	r   Ú_astreamr8   r   r9   r   r:   r;   r   r<   s           r   Ú_acallzDeepSparse._acall�   sý   è è € ð& Œ>ð 	Ø ˆOØ,˜tœ}ð  Ø D°kð ð  ØEKð ð  ð .ð .ð .ð .ð .ð .ð .�eð   5¤:Ñ-��ð ð #ˆDˆDð �”ð ð Ø$ðõ & dÔ&<½dÑCÔCð ˜Ô.Ð.àðð ô ˜Qô ô ð ð ÐÝ& t¨TÑ2Ô2ˆDàˆs   �/c              +   óø   K  —  | j         d|ddœt          | j        t          ¦  «        r| j        ni ¤Ž}|D ]C}t	          |j        d         j        ¬¦  «        }|r|                     |j        ¬¦  «         |V — ŒDdS ©a  Yields results objects as they are generated in real time.
        It also calls the callback manager's on_llm_new_token event with
        similar parameters to the OpenAI LLM class method of the same name.
        Args:
            prompt: The prompt to pass into the model.
            stop: Optional list of stop words to use when generating.
        Returns:
            A generator representing the stream of tokens being generated.
        Yields:
            A dictionary like object containing a string token.
        Example:
            .. code-block:: python
                from langchain_community.llms import DeepSparse
                llm = DeepSparse(
                    model="zoo:nlg/text_generation/codegen_mono-350m/pytorch/huggingface/bigpython_bigquery_thepile/base_quant-none",
                    streaming=True
                )
                for chunk in llm.stream("Tell me a joke",
                        stop=["'","
"]):
                    print(chunk, end='', flush=True)  # noqa: T201
        T)r6   r   r   )r8   )ÚtokenNr"   ©r   r9   r   r:   r   r;   r8   Úon_llm_new_token©r   r.   r/   r0   r1   Ú	inferencerE   r>   s           r   r7   zDeepSparse._stream®   s´   è è € ð8 "�D”Mð 
ØØð
ð 
õ
 ˜dÔ4µdÑ;Ô;ð�Ô&Ð&àð
ð 
ˆ	ð ð 	ð 	ˆEÝ#¨Ô):¸1Ô)=Ô)BÐCÑCÔCˆEàð ?Ø×,Ò,°5´:Ð,Ñ>Ô>Ð>ØˆKˆKˆKˆKð	ð 	r   c                ó  K  —  | j         d|ddœt          | j        t          ¦  «        r| j        ni ¤Ž}|D ]J}t	          |j        d         j        ¬¦  «        }|r!|                     |j        ¬¦  «        ƒ d{V —† |W V — ŒKdS rD   rF   rH   s           r   rA   zDeepSparse._astreamÚ   sÉ   è è € ð8 "�D”Mð 
ØØð
ð 
õ
 ˜dÔ4µdÑ;Ô;ð�Ô&Ð&àð
ð 
ˆ	ð ð 	ð 	ˆEÝ#¨Ô):¸1Ô)=Ô)BÐCÑCÔCˆEàð EØ!×2Ò2¸¼Ð2ÑDÔDÐDÐDÐDÐDÐDÐDÐDØˆKˆKˆKˆKˆKð	ð 	r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__Ústrr   r	   r   r   r
   r   ÚboolÚpropertyr   r#   r   r-   r   r   r?   r   rB   r   r   r7   r   rA   r"   r   r   r   r      s¢  € € € € € € ð	ð 	ð €M€M�Mà€J€J�JØVà48Ð˜ $ s¨C x¤.Ô1Ð8Ð8Ñ8ðEð 15Ð�u˜T 3¨˜_Ô-Ð4Ð4Ñ4ð)ð
 €IˆtÐÐÑØ8àð
 T¨#¨s¨(¤^ð 
ð 
ð 
ñ „Xð
ð ð˜3ð ð ð ñ „Xðð ð¨$ð °4ð ð ð ñ „Xðð, %)Ø:>ð	+ð +àð+ð �t˜C”yÔ!ð+ð Ð6Ô7ð	+ð
 ð+ð 
ð+ð +ð +ð +ð` %)Ø?Cð	+ð +àð+ð �t˜C”yÔ!ð+ð Ð;Ô<ð	+ð
 ð+ð 
ð+ð +ð +ð +ð` %)Ø:>ð	*ð *àð*ð �t˜C”yÔ!ð*ð Ð6Ô7ð	*ð
 ð*ð 
�/Ô	"ð*ð *ð *ð *ð^ %)Ø?Cð	*ð *àð*ð �t˜C”yÔ!ð*ð Ð;Ô<ð	*ð
 ð*ð 
�Ô	'ð*ð *ð *ð *ð *ð *r   r   N)Úlangchain_core.utilsr   Útypingr   r   r   r   r   r	   r
   Úpydanticr   Úlangchain_core.callbacksr   r   Ú#langchain_core.language_models.llmsr   Úlangchain_community.llms.utilsr   Úlangchain_core.outputsr   r   r"   r   r   ú<module>rZ      sW  ðà )Ð )Ð )Ð )Ð )Ð )Ø LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LØ )Ð )Ð )Ð )Ð )Ð )Ø #Ð #Ð #Ð #Ð #Ð #Ø )Ð )Ð )Ð )Ð )Ð )ðð ð ð ð ð ð ð ð *Ð )Ð )Ð )Ð )Ð )Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø )Ð )Ð )Ð )Ð )Ð )Ø >Ð >Ð >Ð >Ð >Ð >Ø )Ð )Ð )Ð )Ð )Ð )Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2ðqð qð qð qð q�ñ qô qð qð qð qr   