Ë
    µŒjÅ!  ã                  óZ  — d dl mZ d dlZd dl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mZmZ d d	lmZmZmZ d d
lmZmZmZmZmZ d dl m!Z!  ejD                  e#«      Z$dd„Z%dd„Z&dd„Z' e
ddd¬«       G d„ de«      «       Z( e
ddd¬«       G d„ dee(«      «       Z)y)é    )ÚannotationsN)ÚAnyÚCallableÚDictÚListÚOptional)Ú
deprecated)ÚAsyncCallbackManagerForLLMRunÚCallbackManagerForLLMRun)ÚLLM)ÚSerializable)Úconvert_to_secret_strÚget_from_dict_or_envÚpre_init)Ú
ConfigDictÚFieldÚ	SecretStr)Úbefore_sleep_logÚretryÚretry_if_exception_typeÚstop_after_attemptÚwait_exponential)Úenforce_stop_tokensc           
     ó  — dd l }t        |d«      rt        |j                  j                  «      nt        t
        «      }d}d}t        dt        | «      t        d||¬«      |t        t        t        j                  «      ¬«      S )	Nr   Úerroré   é
   Té   )Ú
multiplierÚminÚmax)ÚreraiseÚstopÚwaitr   Úbefore_sleep)ÚcohereÚhasattrr   r   ÚCohereErrorÚ	Exceptionr   r   r   r   ÚloggerÚloggingÚWARNING)Úmax_retriesr&   Úretry_conditionsÚmin_secondsÚmax_secondss        úi/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/llms/cohere.pyÚ_create_retry_decoratorr2      su   € Ûô
 �6˜7Ô#ô 	  §¡× 8Ñ 8Ô9ä$¤YÓ/ð ð €KØ€Kô ØÜ Ó,Ü¨°ÀÔMØÜ%¤f¬g¯o©oÓ>ôð ó    ÚCoherec                óT   ‡ — t        ‰ j                  «      }|dˆ fd„«       } |di |¤ŽS )ú*Use tenacity to retry the completion call.c                 ó<   •—  ‰j                   j                  di | ¤ŽS ©N© )ÚclientÚgenerate©ÚkwargsÚllms    €r1   Ú_completion_with_retryz5completion_with_retry.<locals>._completion_with_retry7   s   ø€ à"ˆs�z‰z×"Ñ"Ñ, VÑ,Ð,r3   ©r=   r   Úreturnr   r9   ©r2   r-   ©r>   r=   Úretry_decoratorr?   s   `   r1   Úcompletion_with_retryrE   3   s3   ø€ ä-¨c¯o©oÓ>€Oàô-ó ð-ñ "Ñ+ FÑ+Ð+r3   c                óT   ‡ — t        ‰ j                  «      }|dˆ fd„«       } |di |¤ŽS )r6   c               ›  óX   •K  —  ‰j                   j                  di | ¤Žƒ d {  –—† S 7 Œ­wr8   )Úasync_clientr;   r<   s    €r1   r?   z6acompletion_with_retry.<locals>._completion_with_retryB   s)   øè ø€ à.�S×%Ñ%×.Ñ.Ñ8°Ñ8×8Ð8Ð8ús   ƒ *£(¤*r@   r9   rB   rC   s   `   r1   Úacompletion_with_retryrI   >   s3   ø€ ä-¨c¯o©oÓ>€Oàô9ó ð9ñ "Ñ+ FÑ+Ð+r3   z0.0.30z1.0zlangchain_cohere.BaseCohere)ÚsinceÚremovalÚalternative_importc                  óº   — e Zd ZU dZdZded<   dZded<    ed¬«      Zded<   	 d	Z	d
ed<   	 dZ
ded<   	 dZded<    ed¬«      Zded<   	 dZded<   	 edd„«       Zy)Ú
BaseCoherezBase class for Cohere models.Nr   r:   rH   )ÚdefaultúOptional[str]Úmodelg      è?ÚfloatÚtemperaturezOptional[SecretStr]Úcohere_api_keyúOptional[List[str]]r#   FÚboolÚ	streamingÚ	langchainÚstrÚ
user_agentc                ó  — 	 ddl }t        t        |dd«      «      |d<   |d   }|j                  |d   j	                  «       |¬«      |d<   |j                  |d   j	                  «       |¬«      |d<   |S # t        $ r t        d	«      ‚w xY w)
z?Validate that api key and python package exists in environment.r   NrT   ÚCOHERE_API_KEYrZ   )Úapi_keyÚclient_namer:   rH   zTCould not import cohere python package. Please install it with `pip install cohere`.)r&   r   r   ÚClientÚget_secret_valueÚAsyncClientÚImportError)ÚclsÚvaluesr&   r^   s       r1   Úvalidate_environmentzBaseCohere.validate_environmentb   s¾   € ð	Ûô (=Ü$ VÐ-=Ð?OÓPó(ˆFÐ#Ñ$ð ! Ñ.ˆKØ%Ÿ}™}ØÐ/Ñ0×AÑAÓCØ'ð  -ó  ˆF�8Ñð &,×%7Ñ%7ØÐ/Ñ0×AÑAÓCØ'ð &8ó &ˆF�>Ñ"ð ˆøô% ò 	Üð?óð ð	ús   ‚A4 Á4B	)rd   r   rA   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r:   Ú__annotations__rH   r   rQ   rS   rT   r#   rW   rZ   r   re   r9   r3   r1   rN   rN   I   s„   … ñ (à€FˆCÓØ€L�#ÓÙ ¨Ô.€Eˆ=Ó.Øà€K�ÓØQà*.€NÐ'Ó.ØVà $€DÐ
Ó$á EÔ*€IˆtÓ*Ø(à!€J�Ó!Ø<àòó ñr3   rN   z0.1.14zlangchain_cohere.Coherec                  ó,  — e Zd ZU dZdZded<   	 dZded<   	 dZded<   	 d	Zd
ed<   	 d	Z	d
ed<   	 dZ
ded<   	 dZded<   	  ed¬«      Zedd„«       Zedd„«       Zedd„«       Zedd„«       Zdd„Zd d„Z	 	 d!	 	 	 	 	 	 	 	 	 d"d„Z	 	 d!	 	 	 	 	 	 	 	 	 d#d„Zy)$r4   a¦  Cohere large language models.

    To use, you should have the ``cohere`` python package installed, and the
    environment variable ``COHERE_API_KEY`` set with your API key, or pass
    it as a named parameter to the constructor.

    Example:
        .. code-block:: python

            from langchain_community.llms import Cohere

            cohere = Cohere(model="gptd-instruct-tft", cohere_api_key="my-api-key")
    é   ÚintÚ
max_tokensr   Úkr   Úpg        rR   Úfrequency_penaltyÚpresence_penaltyNrP   Útruncater   r-   Úforbid)Úextrac                ó¢   — | j                   | j                  | j                  | j                  | j                  | j
                  | j                  dœS )z2Get the default parameters for calling Cohere API.©rn   rS   ro   rp   rq   rr   rs   rw   ©Úselfs    r1   Ú_default_paramszCohere._default_params¦   sE   € ð Ÿ/™/Ø×+Ñ+Ø—‘Ø—‘Ø!%×!7Ñ!7Ø $× 5Ñ 5ØŸ™ñ
ð 	
r3   c                ó
   — ddiS )NrT   r\   r9   rx   s    r1   Ú
lc_secretszCohere.lc_secrets³   s   € à Ð"2Ð3Ð3r3   c                ó:   — i d| j                   i¥| j                  ¥S )zGet the identifying parameters.rQ   )rQ   rz   rx   s    r1   Ú_identifying_paramszCohere._identifying_params·   s$   € ð A�7˜DŸJ™JÐ'Ð@¨4×+?Ñ+?Ð@Ð@r3   c                 ó   — y)zReturn type of llm.r&   r9   rx   s    r1   Ú	_llm_typezCohere._llm_type¼   s   € ð r3   c                óš   — | j                   }| j                  �|�t        d«      ‚| j                  �| j                  |d<   n||d<   i |¥|¥S )Nz2`stop` found in both the input and default params.Ústop_sequences)rz   r#   Ú
ValueError)ry   r#   r=   Úparamss       r1   Ú_invocation_paramszCohere._invocation_paramsÁ   s\   € Ø×%Ñ%ˆØ�9‰9Ð  TÐ%5ÜÐQÓRÐRØ�Y‰YÐ"Ø'+§y¡yˆFÐ#Ò$à'+ˆFÐ#Ñ$Ø#�&Ð#˜FÐ#Ð#r3   c                óT   — |j                   d   j                  }|rt        ||«      }|S )Nr   )ÚgenerationsÚtextr   )ry   Úresponser#   rˆ   s       r1   Ú_process_responsezCohere._process_responseË   s.   € Ø×#Ñ# AÑ&×+Ñ+ˆñ Ü& t¨TÓ2ˆDØˆr3   c                ó    —  | j                   |fi |¤Ž}t        | f| j                  |dœ|¤Ž}|j                  d«      }| j	                  ||«      S )ah  Call out to Cohere's generate endpoint.

        Args:
            prompt: The prompt to pass into the model.
            stop: Optional list of stop words to use when generating.

        Returns:
            The string generated by the model.

        Example:
            .. code-block:: python

                response = cohere("Tell me a joke.")
        ©rQ   Úpromptr‚   )r…   rE   rQ   ÚgetrŠ   ©ry   r�   r#   Úrun_managerr=   r„   r‰   Ú_stops           r1   Ú_callzCohere._callÓ   sb   € ð* )�×(Ñ(¨Ñ8°Ñ8ˆÜ(Øð
ØŸ
™
¨6ñ
Ø5;ñ
ˆð —
‘
Ð+Ó,ˆØ×%Ñ% h°Ó6Ð6r3   c              ‹  ó¼   K  —  | j                   |fi |¤Ž}t        | f| j                  |dœ|¤Žƒ d{  –—† }|j                  d«      }| j	                  ||«      S 7 Œ'­w)at  Async call out to Cohere's generate endpoint.

        Args:
            prompt: The prompt to pass into the model.
            stop: Optional list of stop words to use when generating.

        Returns:
            The string generated by the model.

        Example:
            .. code-block:: python

                response = await cohere("Tell me a joke.")
        rŒ   Nr‚   )r…   rI   rQ   rŽ   rŠ   r�   s           r1   Ú_acallzCohere._acallï   sp   è ø€ ð* )�×(Ñ(¨Ñ8°Ñ8ˆÜ/Øð
ØŸ
™
¨6ñ
Ø5;ñ
÷ 
ˆð —
‘
Ð+Ó,ˆØ×%Ñ% h°Ó6Ð6ð	
ús   ‚0A²A³(A)rA   zDict[str, Any])rA   zDict[str, str])rA   rY   )r#   rU   r=   r   rA   Údict)r‰   r   r#   rU   rA   rY   )NN)
r�   rY   r#   rU   r�   z"Optional[CallbackManagerForLLMRun]r=   r   rA   rY   )
r�   rY   r#   rU   r�   z'Optional[AsyncCallbackManagerForLLMRun]r=   r   rA   rY   )rf   rg   rh   ri   rn   rj   ro   rp   rq   rr   rs   r-   r   Úmodel_configÚpropertyrz   r|   r~   r€   r…   rŠ   r’   r”   r9   r3   r1   r4   r4   |   sK  … ñð €J�ÓØAà€A€sƒJØ@à€A€sƒJØDà"Ð�uÓ"ØLà!Ð�eÓ!Ø5à"€HˆmÓ"ð0ð €K�ÓØ<áØô€Lð ò

ó ð

ð ò4ó ð4ð òAó ðAð òó ðó$óð %)Ø:>ð	7àð7ð "ð7ð 8ð	7ð
 ð7ð 
ó7ð> %)Ø?Cð	7àð7ð "ð7ð =ð	7ð
 ð7ð 
ô7r3   )r-   rm   rA   zCallable[[Any], Any])r>   r4   r=   r   rA   r   )*Ú
__future__r   r+   Útypingr   r   r   r   r   Úlangchain_core._api.deprecationr	   Úlangchain_core.callbacksr
   r   Ú#langchain_core.language_models.llmsr   Ú langchain_core.load.serializabler   Úlangchain_core.utilsr   r   r   Úpydanticr   r   r   Útenacityr   r   r   r   r   Úlangchain_community.llms.utilsr   Ú	getLoggerrf   r*   r2   rE   rI   rN   r4   r9   r3   r1   Ú<module>r£      s±   ðÝ "ã ß 6Õ 6å 6÷õ 4Ý 9ß VÑ Vß 1Ñ 1÷õ õ ?à	ˆ×	Ñ	˜8Ó	$€óó.,ó,ñ Ø
˜EÐ6Sôô-�ó -óð-ñ` �( EÐ>WÔXôL7ˆS�*ó L7ó YñL7r3   