Ë
    µŒjÈ"  ã                   óÆ   — 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y
)é    )Ú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y)Ú
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                 ó`   — | j                   | j                  | j                  | j                  dœS )zGet the identifying parameters.)r   Úmodel_configr   r   )r   r   r   r   ©Úselfs    úm/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/llms/deepsparse.pyÚ_identifying_paramszDeepSparse._identifying_params1   s.   € ð —Z‘ZØ ×4Ñ4Ø!%×!7Ñ!7ØŸ™ñ	
ð 	
ó    c                  ó   — y)zReturn type of llm.Ú
deepsparse© r   s    r   Ú	_llm_typezDeepSparse._llm_type;   s   € ð r   Úvaluesc                 óŒ   — 	 ddl m} |d   xs i } |j                  d	d|d   dœ|¤Ž|d<   |S # t        $ r t        d«      ‚w xY w)
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@   su   € ð	Ý+ð Ð3Ñ4Ò:¸ˆà,˜XŸ_™_ð 
Ø"Ø˜g‘ñ
ð ñ
ˆˆzÑð
 ˆøô ò 	ÜðGóð ð	ús	   ‚. ®AÚpromptÚstopÚrun_managerÚkwargsc                 ó  — | j                   r/d} | j                  d|||dœ|¤ŽD ]  }||j                  z  }Œ |}n5 | 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.invoke("Tell me a joke.")
        Ú ©r.   r/   r0   Ú	sequencesr   r"   )r   Ú_streamÚtextr   r   Úgenerationsr   ©r   r.   r/   r0   r1   Úcombined_outputÚchunkr8   s           r   Ú_callzDeepSparse._callT   s�   € ð& �>Š>Ø ˆOØ%˜Ÿ™ð Ø D°kñØEKô�ð   5§:¡:Ñ-‘ðð #‰Dð �—‘ÑI¨ÐI°$×2HÑ2HÑIß‘˜Qñ ç‘ð ð ÐÜ& t¨TÓ2ˆDàˆr   c              ‹   ó  K  — | j                   r1d} | j                  d|||dœ|¤Ž2 3 d{  –—† }||j                  z  }Œ | j                  dd|i| j                  ¤Žj
                  d   j                  }|�t        ||«      }|S 7 ŒY6 |}Œ­w)r3   r4   r5   Nr6   r   r"   )r   Ú_astreamr8   r   r   r9   r   r:   s           r   Ú_acallzDeepSparse._acallz   s¬   è ø€ ð& �>Š>Ø ˆOØ,˜tŸ}™}ð  Ø D°kñ ØEKò ÷ .�eð   5§:¡:Ñ-‘ð �—‘ÑI¨ÐI°$×2HÑ2HÑIß‘˜Qñ ç‘ð ð ÐÜ& t¨TÓ2ˆDàˆð.øð  ð #‰Dùs&   ‚%B§B«B¬B¯ABÂBÂBc              +   óâ   K  —  | j                   d|ddœ| j                  ¤Ž}|D ]G  }t        |j                  d   j                  ¬«      }|r|j                  |j                  ¬«       |–— ŒI y­w©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   r   r   r9   r8   Úon_llm_new_token©r   r.   r/   r0   r1   Ú	inferencerC   r<   s           r   r7   zDeepSparse._stream    st   è ø€ ð8 "�D—M‘Mð 
Ø¨ñ
Ø04×0FÑ0Fñ
ˆ	ó ˆEÜ#¨×):Ñ):¸1Ñ)=×)BÑ)BÔCˆEáØ×,Ñ,°5·:±:Ð,Ô>Ø‹Kñ ùs   ‚A-A/c                óø   K  —  | j                   d|ddœ| j                  ¤Ž}|D ]P  }t        |j                  d   j                  ¬«      }|r$|j                  |j                  ¬«      ƒ d{  –—†  |­–— ŒR y7 Œ­wrB   rD   rF   s           r   r?   zDeepSparse._astreamÆ   s€   è ø€ ð8 "�D—M‘Mð 
Ø¨ñ
Ø04×0FÑ0Fñ
ˆ	ó ˆEÜ#¨×):Ñ):¸1Ñ)=×)BÑ)BÔCˆEáØ!×2Ñ2¸¿¹Ð2ÓD×DÐDØŒKñ ð Eús   ‚A)A:Á+A8Á,A:)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   r7   r   r?   r"   r   r   r   r      sû  … ñ	ð ƒMàƒJØVà48Ð˜ $ s¨C x¡.Ñ1Ó8ðEð 15Ð�u˜T 3¨˜_Ñ-Ó4ð)ð
 €IˆtÓØ8àð
 T¨#¨s¨(¡^ò 
ó ð
ð ð˜3ò ó ðð ð¨$ð °4ò ó ðð, %)Ø:>ñ	$àð$ð �t˜C‘yÑ!ð$ð Ð6Ñ7ð	$ð
 ð$ð 
ó$ðR %)Ø?Cñ	$àð$ð �t˜C‘yÑ!ð$ð Ð;Ñ<ð	$ð
 ð$ð 
ó$ðR %)Ø:>ñ	$àð$ð �t˜C‘yÑ!ð$ð Ð6Ñ7ð	$ð
 ð$ð 
�/Ñ	"ó$ðR %)Ø?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>rX      sA   ðå )ß L× LÑ LÝ )Ý #Ý )÷õ *Ý 3Ý )Ý >Ý )Ý 2ôW�õ Wr   