Ë
    µŒjX  ã                   ó  — 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	 d dl
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Ze j.                   G d	„ d
«      «       Zdee   fd„Z	 	 ddededededeeeeeef   f   f
d„Z G d„ de«      Zy)é    N)ÚAnyÚDictÚListÚMappingÚOptionalÚUnionÚcast)ÚCallbackManagerForLLMRun)ÚLLM)Úget_from_dict_or_env)Ú
ConfigDictÚmodel_validator)Úenforce_stop_tokensé<   c                   ó@   — e Zd ZU dZeed<   eed<   dd„Zedd„«       Zy)	ÚAviaryBackendz“Aviary backend.

    Attributes:
        backend_url: The URL for the Aviary backend.
        bearer: The bearer token for the Aviary backend.
    Úbackend_urlÚbearerNc                 ó*   — d| j                   i| _        y )NÚAuthorization)r   Úheader©Úselfs    úi/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/llms/aviary.pyÚ__post_init__zAviaryBackend.__post_init__   s   € Ø&¨¯©Ð4ˆ�ó    c                 ó¾   — t        j                  d«      }|sJ d«       ‚t        j                  dd«      }|rd|› �nd}||j                  d«      sdndz  } | ||«      S )NÚ
AVIARY_URLzAVIARY_URL must be setÚAVIARY_TOKENÚ zBearer Ú/)ÚosÚgetenvÚendswith)ÚclsÚ
aviary_urlÚaviary_tokenr   s       r   Úfrom_envzAviaryBackend.from_env   sd   € ä—Y‘Y˜|Ó,ˆ
ÙÐ3Ð3Ó3ˆzä—y‘y °Ó4ˆá-9�7˜<˜.Ñ)¸rˆØ ×!4Ñ!4°SÔ!9‘c¸rÑAˆ
á�:˜vÓ&Ð&r   )ÚreturnN)r)   r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__r   Úclassmethodr(   © r   r   r   r      s-   … ñð ÓØƒKó5ð ò	'ó ñ	'r   r   r)   c            	      óÈ  — t         j                  «       } | j                  dz   }t        j                  || j
                  t        ¬«      }	 |j                  «       }t        |j                  «       D �cg c](  }d|v sŒ|j                  d«      j                  dd«      ‘Œ* c}«      }|S # t        j                  $ r!}t        d|› d|j                  › �«      |‚d}~ww xY wc c}w )zList available modelsz-/routes)ÚheadersÚtimeoutúError decoding JSON from ú. Text response: Nú--r!   )r   r(   r   ÚrequestsÚgetr   ÚTIMEOUTÚjsonÚJSONDecodeErrorÚRuntimeErrorÚtextÚsortedÚkeysÚlstripÚreplace)ÚbackendÚrequest_urlÚresponseÚresultÚeÚks         r   Ú
get_modelsrI   ,   sÎ   € ä×$Ñ$Ó&€GØ×%Ñ%¨
Ñ2€KÜ�|‰|˜K°·±ÌÔQ€HðØ—‘“ˆô
 Ø39·;±;´=ÓN±=¨aÀDÈAÂIˆ�‰�#‹×	Ñ	˜t SÕ	)°=ÑNó€Fð €Møô ×#Ñ#ò ÜØ'¨ }Ð4EÀhÇmÁmÀ_ÐUó
àð	ûðüò
 	Os$   ÁB( Á2	CÁ<#CÂ(CÂ;CÃCÚmodelÚpromptÚuse_prompt_formatÚversionc                 ó^  — t         j                  «       }|j                  | j                  dd«      z   dz   |z   dz   }t	        j
                  ||j                  ||dœt        ¬«      }	 |j                  «       S # t        j                  $ r!}t        d|› d|j                  › �«      |‚d}~ww xY w)	z#Get completions from Aviary models.r!   r7   Úquery)rK   rL   )r3   r;   r4   r5   r6   N)r   r(   r   rB   r8   Úpostr   r:   r;   r<   r=   r>   )rJ   rK   rL   rM   rC   ÚurlrE   rG   s           r   Úget_completionsrR   =   s¬   € ô ×$Ñ$Ó&€GØ
×
Ñ
 §¡¨c°4Ó 8Ñ
8¸3Ñ
>ÀÑ
HÈ7Ñ
R€CÜ�}‰}ØØ—‘ØÐ5FÑGÜô	€HðØ�}‰}‹ÐøÜ×#Ñ#ò ÜØ'¨ uÐ,=¸h¿m¹m¸_ÐMó
àð	ûðús   Á(A8 Á8B,ÂB'Â'B,c                   ó  — e Zd ZU dZdZ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	<    ed
¬«      Z ed¬«      ededefd„«       «       Zedeeef   fd„«       Zedefd„«       Z	 	 ddedeee      dee   dedef
d„Zy)ÚAviaryab  Aviary hosted models.

    Aviary is a backend for hosted models. You can
    find out more about aviary at
    http://github.com/ray-project/aviary

    To get a list of the models supported on an
    aviary, follow the instructions on the website to
    install the aviary CLI and then use:
    `aviary models`

    AVIARY_URL and AVIARY_TOKEN environment variables must be set.

    Attributes:
        model: The name of the model to use. Defaults to "amazon/LightGPT".
        aviary_url: The URL for the Aviary backend. Defaults to None.
        aviary_token: The bearer token for the Aviary backend. Defaults to None.
        use_prompt_format: If True, the prompt template for the model will be ignored.
            Defaults to True.
        version: API version to use for Aviary. Defaults to None.

    Example:
        .. code-block:: python

            from langchain_community.llms import Aviary
            os.environ["AVIARY_URL"] = "<URL>"
            os.environ["AVIARY_TOKEN"] = "<TOKEN>"
            light = Aviary(model='amazon/LightGPT')
            output = light('How do you make fried rice?')
    zamazon/LightGPTrJ   Nr&   r'   TrL   rM   Úforbid)ÚextraÚbefore)ÚmodeÚvaluesr)   c                 óR  — t        |dd«      }t        |dd«      }|t        j                  d<   |t        j                  d<   	 t        «       }|j                  d«      }|r||vrt        |› d|d   › d�«      ‚|S # t        j
                  j                  $ r}t        |«      ‚d}~ww xY w)	z?Validate that api key and python package exists in environment.r&   r   r'   r   NrJ   z does not support model Ú.)	r   r"   ÚenvironrI   r8   Ú
exceptionsÚRequestExceptionÚ
ValueErrorr9   )r%   rY   r&   r'   Úaviary_modelsrG   rJ   s          r   Úvalidate_environmentzAviary.validate_environment�   s°   € ô *¨&°,ÀÓMˆ
Ü+¨F°NÀNÓSˆð $.Œ�
‰
�<Ñ Ø%1Œ�
‰
�>Ñ"ð	 Ü&›LˆMð —
‘
˜7Ó#ˆÙ�U -Ñ/Ü 
˜|Ð+CÀFÈ7ÁOÐCTÐTUÐVÓWÐWàˆøô ×"Ñ"×3Ñ3ò 	 Ü˜Q“-Ðûð	 ús   Á
A9 Á9B&ÂB!Â!B&c                 ó4   — | j                   | j                  dœS )zGet the identifying parameters.)Ú
model_namer&   )rJ   r&   r   s    r   Ú_identifying_paramszAviary._identifying_params—   s   € ð Ÿ*™*ØŸ/™/ñ
ð 	
r   c                 ó@   — d| j                   j                  dd«      › �S )zReturn type of llm.zaviary-r!   Ú-)rJ   rB   r   s    r   Ú	_llm_typezAviary._llm_typeŸ   s#   € ð ˜Ÿ™×+Ñ+¨C°Ó5Ð6Ð7Ð7r   rK   ÚstopÚrun_managerÚkwargsc                 óÊ   — d| j                   i}| j                  r| j                  |d<   t        d| j                  |dœ|¤Ž}t	        t
        |d   «      }|rt        ||«      }|S )a  Call out to Aviary
        Args:
            prompt: The prompt to pass into the model.

        Returns:
            The string generated by the model.

        Example:
            .. code-block:: python

                response = aviary("Tell me a joke.")
        rL   rM   )rJ   rK   Úgenerated_textr1   )rL   rM   rR   rJ   r	   r.   r   )r   rK   rh   ri   rj   Úoutputr>   s          r   Ú_callzAviary._call¤   st   € ð& & t×'=Ñ'=Ð>ˆØ�<Š<Ø $§¡ˆF�9Ñä ð 
Ø—*‘*Øñ
ð ñ
ˆô ”C˜Ð 0Ñ1Ó2ˆÙÜ& t¨TÓ2ˆDàˆr   )NN)r*   r+   r,   r-   rJ   r.   r/   r&   r   r'   rL   ÚboolrM   r   Úmodel_configr   r0   r   r   ra   Úpropertyr   rd   rg   r   r
   rn   r1   r   r   rT   rT   U   s  … ñð> #€Eˆ3Ó"Ø $€J�˜‘Ó$Ø"&€L�(˜3‘-Ó&à"Ð�tÓ"à!€GˆX�c‰]Ó!áØô€Lñ ˜(Ô#Øð¨$ð °3ò ó ó $ðð( ð
 W¨S°#¨XÑ%6ò 
ó ð
ð ð8˜3ò 8ó ð8ð %)Ø:>ñ	!àð!ð �t˜C‘yÑ!ð!ð Ð6Ñ7ð	!ð
 ð!ð 
ô!r   rT   )Tr    ) Údataclassesr"   Útypingr   r   r   r   r   r   r	   r8   Úlangchain_core.callbacksr
   Ú#langchain_core.language_models.llmsr   Úlangchain_core.utilsr   Úpydanticr   r   Úlangchain_community.llms.utilsr   r:   Ú	dataclassr   r.   rI   ro   ÚfloatÚintrR   rT   r1   r   r   Ú<module>r|      s¸   ðÛ Û 	ß B× BÑ Bã Ý =Ý 3Ý 5ß 0å >à
€ð ×Ñ÷'ð 'ó ð'ð6�D˜‘Ió ð( #Øñ	Øðàðð ðð ð	ð
 
ˆ#ˆu�S˜% �_Ñ%Ð
%Ñ&óô0pˆSõ pr   