Ë
    µŒjY1  ã                   ó  — d dl Z d dlZd dlmZ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 d dlmZ d d	lmZmZmZmZ d d
lmZmZ d dl m!Z!m"Z"m#Z#m$Z$  G d„ de«      Z% eddd¬«       G d„ dee%«      «       Z&y)é    N)ÚAnyÚAsyncIteratorÚCallableÚDictÚIteratorÚListÚMappingÚOptional)Ú
deprecated)ÚAsyncCallbackManagerForLLMRunÚCallbackManagerForLLMRun)ÚBaseLanguageModel)ÚLLM)ÚGenerationChunk)ÚPromptValue)Úcheck_package_versionÚget_from_dict_or_envÚget_pydantic_field_namesÚpre_init)Ú_build_model_kwargsÚconvert_to_secret_str)Ú
ConfigDictÚFieldÚ	SecretStrÚmodel_validatorc                   ó(  — e Zd ZU dZeed<   dZeed<    edd¬«      Ze	ed<   	  edd	¬«      Z
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d<   	 dZee   ed<   	 dZ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	gef      ed<    ee¬«      Zee	ef   ed<    ed¬«      e dedefd„«       «       Z!e"dedefd„«       Z#e$de%e	ef   fd „«       Z&e$de%e	ef   fd!„«       Z'd$d"ee(e	      de(e	   fd#„Z)y)%Ú_AnthropicCommonNÚclientÚasync_clientzclaude-2Ú
model_name)ÚdefaultÚaliasÚmodelé   Ú
max_tokensÚmax_tokens_to_sampleÚtemperatureÚtop_kÚtop_pFÚ	streamingÚdefault_request_timeouté   Úmax_retriesÚanthropic_api_urlÚanthropic_api_keyÚHUMAN_PROMPTÚ	AI_PROMPTÚcount_tokens)Údefault_factoryÚmodel_kwargsÚbefore)ÚmodeÚvaluesÚreturnc                 ó4   — t        | «      }t        ||«      }|S ©N)r   r   )Úclsr7   Úall_required_field_namess      úl/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/llms/anthropic.pyÚbuild_extraz_AnthropicCommon.build_extraE   s!   € ô $<¸CÓ#@Ð Ü$ VÐ-EÓFˆØˆó    c                 óØ  — t        t        |dd«      «      |d<   t        |ddd¬«      |d<   	 ddl}t        d	d
¬«       |j	                  |d   |d   j                  «       |d   |d   ¬«      |d<   |j                  |d   |d   j                  «       |d   |d   ¬«      |d<   |j                  |d<   |j                  |d<   |d   j                  |d<   |S # t        $ r t        d«      ‚w xY w)z?Validate that api key and python package exists in environment.r/   ÚANTHROPIC_API_KEYr.   ÚANTHROPIC_API_URLzhttps://api.anthropic.com)r!   r   NÚ	anthropicz0.3)Úgte_versionr+   r-   )Úbase_urlÚapi_keyÚtimeoutr-   r   r   r0   r1   r2   z]Could not import anthropic python package. Please it install it with `pip install anthropic`.)r   r   rC   r   Ú	AnthropicÚget_secret_valueÚAsyncAnthropicr0   r1   r2   ÚImportError)r;   r7   rC   s      r=   Úvalidate_environmentz%_AnthropicCommon.validate_environmentL   sB  € ô '<Ü  Ð)<Ð>QÓRó'
ˆÐ"Ñ#ô ';ØØØØ/ô	'
ˆÐ"Ñ#ð	Ûä! +¸5ÕAØ(×2Ñ2ØÐ 3Ñ4ØÐ2Ñ3×DÑDÓFØÐ8Ñ9Ø" =Ñ1ð	  3ó  ˆF�8Ñð &/×%=Ñ%=ØÐ 3Ñ4ØÐ2Ñ3×DÑDÓFØÐ8Ñ9Ø" =Ñ1ð	 &>ó &ˆF�>Ñ"ð &/×%;Ñ%;ˆF�>Ñ"Ø"+×"5Ñ"5ˆF�;ÑØ%+¨HÑ%5×%BÑ%BˆF�>Ñ"ð ˆøô ò 	ÜðEóð ð	ús   ­B%C ÃC)c                 óö   — | j                   | j                  dœ}| j                  �| j                  |d<   | j                  �| j                  |d<   | j                  �| j                  |d<   i |¥| j
                  ¥S )z5Get the default parameters for calling Anthropic API.)r&   r#   r'   r(   r)   )r&   r#   r'   r(   r)   r4   )ÚselfÚds     r=   Ú_default_paramsz _AnthropicCommon._default_paramsu   s}   € ð %)×$=Ñ$=Ø—Z‘Zñ
ˆð ×ÑÐ'Ø#×/Ñ/ˆAˆmÑØ�:‰:Ð!ØŸ™ˆAˆg‰JØ�:‰:Ð!ØŸ™ˆAˆg‰JØ)�!Ð)�t×(Ñ(Ð)Ð)r?   c                 ó"   — i i ¥| j                   ¥S )zGet the identifying parameters.)rP   ©rN   s    r=   Ú_identifying_paramsz$_AnthropicCommon._identifying_params„   s   € ð .�"Ð-˜×,Ñ,Ð-Ð-r?   Ústopc                 óŒ   — | j                   r| j                  st        d«      ‚|€g }|j                  | j                   g«       |S )Nú-Please ensure the anthropic package is loaded)r0   r1   Ú	NameErrorÚextend)rN   rT   s     r=   Ú_get_anthropic_stopz$_AnthropicCommon._get_anthropic_stop‰   sC   € Ø× Ò ¨¯ªÜÐKÓLÐLàˆ<ØˆDð 	�‰�T×&Ñ&Ð'Ô(àˆr?   r:   )*Ú__name__Ú
__module__Ú__qualname__r   r   Ú__annotations__r   r   r#   Ústrr&   Úintr'   r
   Úfloatr(   r)   r*   Úboolr+   r-   r.   r/   r   r0   r1   r2   r   Údictr4   r   r   Úclassmethodr>   r   rL   Úpropertyr	   rP   rS   r   rY   © r?   r=   r   r   !   sÂ  … Ø€FˆCÓØ€L�#ÓÙ˜z°Ô>€Eˆ3Ó>Øá %¨c¸Ô FÐ˜#ÓFØAà#'€K�˜%‘Ó'ØQà€Eˆ8�C‰=ÓØ@à!€Eˆ8�E‰?Ó!ØDà€IˆtÓØ(à/3Ð˜X e™_Ó3ØSà€K�ÓØVà'+Ð�x ‘}Ó+à-1Ð�x 	Ñ*Ó1à"&€L�(˜3‘-Ó&Ø#€Iˆx˜‰}Ó#Ø37€L�(˜8 S E¨3 JÑ/Ñ0Ó7Ù#(¸Ô#>€L�$�s˜C�x‘.Ó>á˜(Ô#Øð ð ¨#ò ó ó $ðð
 ð&¨$ð &°4ò &ó ð&ðP ð* ¨¨c¨Ñ!2ò *ó ð*ð ð. W¨S°#¨XÑ%6ò .ó ð.ñ
¨°°c±Ñ(;ð 
ÀtÈCÁyô 
r?   r   z0.0.28z1.0z langchain_anthropic.AnthropicLLM)ÚsinceÚremovalÚalternative_importc                   ó`  — e Zd ZdZ edd¬«      Zededefd„«       Ze	de
fd„«       Z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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e
defd„Zy
)rH   aï  Anthropic large language models.

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

    Example:
        .. code-block:: python

            import anthropic
            from langchain_community.llms import Anthropic

            model = Anthropic(model="<model_name>", anthropic_api_key="my-api-key")

            # Simplest invocation, automatically wrapped with HUMAN_PROMPT
            # and AI_PROMPT.
            response = model.invoke("What are the biggest risks facing humanity?")

            # Or if you want to use the chat mode, build a few-shot-prompt, or
            # put words in the Assistant's mouth, use HUMAN_PROMPT and AI_PROMPT:
            raw_prompt = "What are the biggest risks facing humanity?"
            prompt = f"{anthropic.HUMAN_PROMPT} {prompt}{anthropic.AI_PROMPT}"
            response = model.invoke(prompt)
    T)Úpopulate_by_nameÚarbitrary_types_allowedr7   r8   c                 ó0   — t        j                  d«       |S )z,Raise warning that this class is deprecated.zpThis Anthropic LLM is deprecated. Please use `from langchain_community.chat_models import ChatAnthropic` instead)ÚwarningsÚwarn)r;   r7   s     r=   Úraise_warningzAnthropic.raise_warningº   s   € ô 	�‰ðô	
ð
 ˆr?   c                  ó   — y)zReturn type of llm.zanthropic-llmre   rR   s    r=   Ú	_llm_typezAnthropic._llm_typeÄ   s   € ð r?   Úpromptc                 ó  — | j                   r| j                  st        d«      ‚|j                  | j                   «      r|S t	        j
                  d| j                   |«      \  }}|dk(  r|S | j                   › d|› | j                  › d�S )NrV   z
^\n*Human:é   Ú z Sure, here you go:
)r0   r1   rW   Ú
startswithÚreÚsubn)rN   rr   Úcorrected_promptÚn_subss       r=   Ú_wrap_promptzAnthropic._wrap_promptÉ   s‰   € Ø× Ò ¨¯ªÜÐKÓLÐLà×Ñ˜T×.Ñ.Ô/ØˆMô $&§7¡7¨=¸$×:KÑ:KÈVÓ#TÑ Ð˜&Ø�QŠ;Ø#Ð#ð ×#Ñ#Ð$ A f X¨d¯n©nÐ-=Ð=RÐSÐSr?   NrT   Úrun_managerÚkwargsc                 ó@  — | j                   r.d} | j                  d|||dœ|¤ŽD ]  }||j                  z  }Œ |S | j                  |«      }i | j                  ¥|¥} | j
                  j                  j                  d| j                  |«      |dœ|¤Ž}|j                  S )aî  Call out to Anthropic's completion 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

                prompt = "What are the biggest risks facing humanity?"
                prompt = f"\n\nHuman: {prompt}\n\nAssistant:"
                response = model.invoke(prompt)

        Ú ©rr   rT   r|   ©rr   Ústop_sequencesre   )
r*   Ú_streamÚtextrY   rP   r   ÚcompletionsÚcreater{   Ú
completion©	rN   rr   rT   r|   r}   r‡   ÚchunkÚparamsÚresponses	            r=   Ú_callzAnthropic._callØ   sÀ   € ð0 �>Š>ØˆJØ%˜Ÿ™ð Ø D°kñØEKô�ð ˜eŸj™jÑ(‘
ðð Ðà×'Ñ'¨Ó-ˆØ3�D×(Ñ(Ð3¨FÐ3ˆØ1�4—;‘;×*Ñ*×1Ñ1ð 
Ø×$Ñ$ VÓ,Øñ
ð ñ
ˆð
 ×"Ñ"Ð"r?   c                 ó@   — | j                  |j                  «       «      S r:   )r{   Ú	to_string)rN   rr   s     r=   Úconvert_promptzAnthropic.convert_prompt  s   € Ø× Ñ  ×!1Ñ!1Ó!3Ó4Ð4r?   c              ‹   ól  K  — | j                   r1d} | j                  d|||dœ|¤Ž2 3 d{  –—† }||j                  z  }Œ| j                  |«      }i | j                  ¥|¥} | j
                  j                  j                  d| j                  |«      |dœ|¤Žƒ d{  –—† }|j                  S 7 Œ�6 |S 7 Œ­w)z;Call out to Anthropic's completion endpoint asynchronously.r   r€   Nr�   re   )
r*   Ú_astreamr„   rY   rP   r   r…   r†   r{   r‡   rˆ   s	            r=   Ú_acallzAnthropic._acall  sÝ   è ø€ ð �>Š>ØˆJØ,˜tŸ}™}ð  Ø D°kñ ØEKò ÷ )�eð ˜eŸj™jÑ(‘
ð ×'Ñ'¨Ó-ˆØ3�D×(Ñ(Ð3¨FÐ3ˆà=˜×*Ñ*×6Ñ6×=Ñ=ð 
Ø×$Ñ$ VÓ,Øñ
ð ñ
÷ 
ˆð
 ×"Ñ"Ð"ð)øð  ð Ðð

ús2   ‚%B4§B/«B-¬B/¯A-B4ÂB2ÂB4Â-B/Â/B4c              +   ó<  K  — | j                  |«      }i | j                  ¥|¥} | j                  j                  j                  d| j                  |«      |ddœ|¤ŽD ];  }t        |j                  ¬«      }|r|j                  |j                  |¬«       |–— Œ= y­w)a\  Call Anthropic completion_stream and return the resulting generator.

        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 from Anthropic.
        Example:
            .. code-block:: python

                prompt = "Write a poem about a stream."
                prompt = f"\n\nHuman: {prompt}\n\nAssistant:"
                generator = anthropic.stream(prompt)
                for token in generator:
                    yield token
        T©rr   r‚   Ústream©r„   ©r‰   Nre   )
rY   rP   r   r…   r†   r{   r   r‡   Úon_llm_new_tokenr„   ©rN   rr   rT   r|   r}   rŠ   Útokenr‰   s           r=   rƒ   zAnthropic._stream  sž   è ø€ ð. ×'Ñ'¨Ó-ˆØ3�D×(Ñ(Ð3¨FÐ3ˆà3�T—[‘[×,Ñ,×3Ñ3ð 
Ø×$Ñ$ VÓ,¸TÈ$ñ
ØRXô
ˆEô $¨×)9Ñ)9Ô:ˆEÙØ×,Ñ,¨U¯Z©Z¸uÐ,ÔEØ‹Kñ
ùs   ‚BBc                óv  K  — | j                  |«      }i | j                  ¥|¥} | j                  j                  j                  d| j                  |«      |ddœ|¤Žƒ d{  –—† 2 3 d{  –—† }t        |j                  ¬«      }|r%|j                  |j                  |¬«      ƒ d{  –—†  |­–— ŒL7 ŒP7 ŒI7 Œ6 y­w)a[  Call Anthropic completion_stream and return the resulting generator.

        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 from Anthropic.
        Example:
            .. code-block:: python
                prompt = "Write a poem about a stream."
                prompt = f"\n\nHuman: {prompt}\n\nAssistant:"
                generator = anthropic.stream(prompt)
                for token in generator:
                    yield token
        Tr”   Nr–   r—   re   )
rY   rP   r   r…   r†   r{   r   r‡   r˜   r„   r™   s           r=   r‘   zAnthropic._astream@  sÌ   è ø€ ð, ×'Ñ'¨Ó-ˆØ3�D×(Ñ(Ð3¨FÐ3ˆà!E ×!2Ñ!2×!>Ñ!>×!EÑ!Eð "
Ø×$Ñ$ VÓ,ØØñ"
ð ñ	"
÷ 
ð 
÷ 		�%ô $¨×)9Ñ)9Ô:ˆEÙØ!×2Ñ2°5·:±:ÀUÐ2ÓK×KÐKØŒKð
øð 		øð Løñ
ùsH   ‚AB9Á B1Á!B9Á%B7Á)B3Á*B7Á-9B9Â&B5Â'B9Â3B7Â5B9Â7B9r„   c                 óR   — | j                   st        d«      ‚| j                  |«      S )zCalculate number of tokens.rV   )r2   rW   )rN   r„   s     r=   Úget_num_tokenszAnthropic.get_num_tokensd  s(   € à× Ò ÜÐKÓLÐLØ× Ñ  Ó&Ð&r?   )NN)rZ   r[   r\   Ú__doc__r   Úmodel_configr   r   ro   rd   r^   rq   r{   r
   r   r   r   rŒ   r   r�   r   r’   r   r   rƒ   r   r‘   r_   r�   re   r?   r=   rH   rH   –   sÏ  „ ññ2 ØØ $ô€Lð
 ð 4ð ¨Dò ó ðð ð˜3ò ó ððT 3ð T¨3ó Tð$ %)Ø:>ñ	'#àð'#ð �t˜C‘yÑ!ð'#ð Ð6Ñ7ð	'#ð
 ð'#ð 
ó'#ðR5 [ð 5°Só 5ð %)Ø?Cñ	#àð#ð �t˜C‘yÑ!ð#ð Ð;Ñ<ð	#ð
 ð#ð 
ó#ð: %)Ø:>ñ	 àð ð �t˜C‘yÑ!ð ð Ð6Ñ7ð	 ð
 ð ð 
�/Ñ	"ó ðJ %)Ø?Cñ	"àð"ð �t˜C‘yÑ!ð"ð Ð;Ñ<ð	"ð
 ð"ð 
�Ñ	'ó"ðH' 3ð '¨3ô 'r?   rH   )'rw   rm   Útypingr   r   r   r   r   r   r	   r
   Úlangchain_core._api.deprecationr   Úlangchain_core.callbacksr   r   Úlangchain_core.language_modelsr   Ú#langchain_core.language_models.llmsr   Úlangchain_core.outputsr   Úlangchain_core.prompt_valuesr   Úlangchain_core.utilsr   r   r   r   Úlangchain_core.utils.utilsr   r   Úpydanticr   r   r   r   r   rH   re   r?   r=   Ú<module>rª      s‡   ðÛ 	Û ÷	÷ 	ó 	õ 7÷õ =Ý 3Ý 2Ý 4÷ó ÷ Rß BÓ BôrÐ(ô rñj Ø
ØØ9ôô
M'�Ð%ó M'óñ
M'r?   