§
    æ˜ºh§!  ã                   ó†   — 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mZ d dlmZ d dlmZ d dlmZ  G d„ de¦  «        Zd	S )
é    )ÚAnyÚAsyncIteratorÚDictÚIteratorÚListÚOptionalÚUnion)Úroot_validator)ÚAsyncCallbackManagerForLLMRunÚCallbackManagerForLLMRun)ÚLLM)Úenforce_stop_tokens)ÚGenerationChunkc                   ó0  — 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_configÚgeneration_configFÚ	streamingÚreturnc                 ó8   — | j         | j        | j        | j        dœS )zGet the identifying parameters.©r   r   r   r   r   ©Úselfs    úk/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/langchain_community/llms/deepsparse.pyÚ_identifying_paramszDeepSparse._identifying_params+   s)   € ð ”ZØ Ô-Ø!%Ô!7Øœð	
ð 
ð 	
ó    c                 ó   — dS )zReturn type of llm.Ú
deepsparse© r   s    r   Ú	_llm_typezDeepSparse._llm_type5   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ñô ð ð	øøøð ˜nÔ-Ð3°ˆà,˜Xœ_ð 
Ø"Ø˜g”ð
ð 
ð ð
ð 
ˆˆzÑð
 ˆs   ‚	 ‰#ÚpromptÚstopÚrun_managerÚkwargsc                 óÆ   — | j         r#d} | j        d|||dœ|¤ŽD ]}||j        z  }Œ|}n$ | j        dd|i| j        ¤Ž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("Tell me a joke.")
        Ú ©r-   r.   r/   Ú	sequencesr   Nr!   )r   Ú_streamÚtextr   r   Úgenerationsr   ©r   r-   r.   r/   r0   Úcombined_outputÚchunkr7   s           r   Ú_callzDeepSparse._callN   s­   € ð& Œ>ð 	Ø ˆOØ%˜œð Ø D°kðð ØEKðð ð .ð .�ð   5¤:Ñ-��Ø"ˆDˆDð �”ÐIÐI¨ÐI°$Ô2HÐIÐIÜ˜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| j        ¤Žj        d         j        }|�t          ||¦  «        }|S )r2   r3   r4   Nr5   r   r!   )r   Ú_astreamr7   r   r   r8   r   r9   s           r   Ú_acallzDeepSparse._acallt   sÑ   è è € ð& Œ>ð 	Ø ˆOØ,˜tœ}ð  Ø D°kð ð  ØEKð ð  ð .ð .ð .ð .ð .ð .ð .�eð   5¤:Ñ-��ð ð #ˆDˆDð �”ÐIÐI¨ÐI°$Ô2HÐIÐIÜ˜Qô äð ð ÐÝ& t¨TÑ2Ô2ˆDàˆs   �/c              +   óÀ   K  —  | j         d|ddœ| j        ¤Ž}|D ]C}t          |j        d         j        ¬¦  «        }|V — |r|                     |j        ¬¦  «         Œ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)
        T)r5   r   r   )r7   )ÚtokenNr!   ©r   r   r   r8   r7   Úon_llm_new_token©r   r-   r.   r/   r0   Ú	inferencerB   r;   s           r   r6   zDeepSparse._streamš   s–   è è € ð8 "�D”Mð 
Ø¨ð
ð 
Ø04Ô0Fð
ð 
ˆ	ð ð 	?ð 	?ˆEÝ#¨Ô):¸1Ô)=Ô)BÐCÑCÔCˆEØˆKˆKˆKàð ?Ø×,Ò,°5´:Ð,Ñ>Ô>Ð>øð	?ð 	?r   c                óÎ   K  —  | j         d|ddœ| j        ¤Ž}|D ]J}t          |j        d         j        ¬¦  «        }|W V — |r!|                     |j        ¬¦  «        ƒ d{V —† ŒKdS rA   rC   rE   s           r   r>   zDeepSparse._astreamÀ   s¯   è è € ð8 "�D”Mð 
Ø¨ð
ð 
Ø04Ô0Fð
ð 
ˆ	ð ð 	Eð 	EˆEÝ#¨Ô):¸1Ô)=Ô)BÐCÑCÔCˆEØˆKˆKˆKˆKàð EØ!×2Ò2¸¼Ð2ÑDÔDÐDÐDÐDÐDÐDÐDÐDøð	Eð 	Er   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__Ústrr   r   r   r   r	   r   ÚboolÚpropertyr   r"   r
   r,   r   r   r<   r   r?   r   r   r6   r   r>   r!   r   r   r   r      s¶  € € € € € € ð	ð 	ð €M€M�Mà€J€J�JØVà-1€L�(˜4  S œ>Ô*Ð1Ð1Ñ1ðEð 15Ð�u˜T 3¨˜_Ô-Ð4Ð4Ñ4ð)ð
 €IˆtÐÐÑØ8àð
 T¨#¨s¨(¤^ð 
ð 
ð 
ñ „Xð
ð ð˜3ð ð ð ñ „Xðð €^ÑÔð¨$ð °4ð ð ð ñ Ôðð, %)Ø:>ð	$ð $àð$ð �t˜C”yÔ!ð$ð Ð6Ô7ð	$ð
 ð$ð 
ð$ð $ð $ð $ðR %)Ø?Cð	$ð $àð$ð �t˜C”yÔ!ð$ð Ð;Ô<ð	$ð
 ð$ð 
ð$ð $ð $ð $ðR %)Ø:>ð	$?ð $?àð$?ð �t˜C”yÔ!ð$?ð Ð6Ô7ð	$?ð
 ð$?ð 
�/Ô	"ð$?ð $?ð $?ð $?ðR %)Ø?Cð	$Eð $Eàð$Eð �t˜C”yÔ!ð$Eð Ð;Ô<ð	$Eð
 ð$Eð 
�Ô	'ð$Eð $Eð $Eð $Eð $Eð $Er   r   N)Útypingr   r   r   r   r   r   r	   Úlangchain_core.pydantic_v1r
   Úlangchain_core.callbacksr   r   Ú#langchain_core.language_models.llmsr   Úlangchain_community.llms.utilsr   Úlangchain_core.outputsr   r   r!   r   r   ú<module>rV      sõ   ðà LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LØ 5Ð 5Ð 5Ð 5Ð 5Ð 5ðð ð ð ð ð ð ð ð 4Ð 3Ð 3Ð 3Ð 3Ð 3Ø >Ð >Ð >Ð >Ð >Ð >Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2ðWEð WEð WEð WEð WE�ñ WEô WEð WEð WEð WEr   