Ë
    µŒjX  ã                   ób   — d dl Zd dlZd dlZd dlmZmZmZmZ d dl	m
Z
 d dlmZ  G d„ de«      Zy)é    N)ÚAnyÚListÚMappingÚOptional)ÚCallbackManagerForLLMRun)ÚLLMc                   ó¤   — e Zd ZU dZee   ed<   	 dZe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e	deeef   fd„«       Zy)ÚNIBittensorLLMaÕ  NIBittensor LLMs

    NIBittensorLLM is created by Neural Internet (https://neuralinternet.ai/),
    powered by Bittensor, a decentralized network full of different AI models.

    To analyze API_KEYS and logs of your usage visit
        https://api.neuralinternet.ai/api-keys
        https://api.neuralinternet.ai/logs

    Example:
        .. code-block:: python

            from langchain_community.llms import NIBittensorLLM
            llm = NIBittensorLLM()
    Úsystem_promptr   Útop_responsesÚreturnc                  ó   — y)Nr
   © ©Úselfs    úl/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/llms/bittensor.pyÚ	_llm_typezNIBittensorLLM._llm_type"   s   € àó    NÚpromptÚstopÚrun_managerÚkwargsc                 ó  — t        j                  «       }d|_        t        j                  j                  d|¬«      }t        | j                  t        «      rt        d| j                  «      }nd}d}| j                  €|dz   }	n|t        | j                  «      z   }	|j                  d	d
«       |j                  «       }
|
j                  «       j                  d«      j!                  dd«      j!                  dd«      }t#        j$                  |«      }|d   d   }dd|› �ddœ}|j                  d	d|¬«       |j                  «       }|j                  «       j                  d«      j!                  dd«      j!                  dd«      }t#        j$                  |«      }t        |t&        «      rË|rÉ|sÇ|D ]Â  }	 t#        j(                  |gd|	dœd|dœgdœ«      }|j                  dd||«       |j                  «       }|j                  «       j                  d«      j!                  dd«      j!                  dd«      }t#        j$                  |«      }d|vrŒ¢|d   d   d   d   }|j+                  «        |c S  	 t#        j(                  |d|	dœd|dœgdœ«      }|j                  dd||«       |j                  «       }|j                  «       j                  d«      j!                  dd«      j!                  dd«      }|r|j+                  «        |S t#        j$                  |«      }|d   d   d   d   }|j+                  «        |S # t,        $ r Y �Œžw xY w# t,        $ r$}|j                  d	d |› d!|› �|¬«       Y d}~y"d}~ww xY w)#a¾  
        Wrapper around the bittensor top miner models. Its built by Neural Internet.

        Call the Neural Internet's BTVEP Server and return the output.

        Parameters (optional):
            system_prompt(str): A system prompt defining how your model should respond.
            top_responses(int): Total top miner responses to retrieve from Bittensor
                protocol.

        Return:
            The generated response(s).

        Example:
            .. code-block:: python

                from langchain_community.llms import NIBittensorLLM
                llm = NIBittensorLLM(system_prompt="Act like you are programmer with                 5+ years of experience.")
        Tztest.neuralinternet.ai)Úcontextéd   r   zwYou are an assistant which is created by Neural Internet(NI)             in decentralized network named as a Bittensor.Nz? Your task is to provide accurate response based on user promptÚGETz/admin/api-keys/zutf-8Ú
Ú Ú	Úapi_keyzapplication/jsonzBearer z
2023-05-19)zContent-TypeÚAuthorizationzEndpoint-Versionz/top_miner_uids)ÚheadersÚsystem)ÚroleÚcontentÚuser)ÚuidsÚmessagesÚPOSTz/chatÚchoicesÚmessager%   )Útop_nr(   z/error_msg?e=z&p=zBSorry I am unable to provide response now, Please try again later.)ÚsslÚcreate_default_contextÚcheck_hostnameÚhttpÚclientÚHTTPSConnectionÚ
isinstancer   ÚintÚminr   ÚstrÚrequestÚgetresponseÚreadÚdecodeÚreplaceÚjsonÚloadsÚlistÚdumpsÚcloseÚ	Exception)r   r   r   r   r   r   Úconnr,   Údefault_promptr   Úapi_key_responseÚapi_keys_dataÚapi_keys_jsonr    r"   Úminer_responseÚ
miner_datar'   ÚuidÚpayloadÚinit_responseÚ	init_dataÚ	init_jsonÚreplyÚresponseÚ
utf_stringÚ	json_respÚes                               r   Ú_callzNIBittensorLLM._call&   sŒ  € ô: ×,Ñ,Ó.ˆØ!%ˆÔÜ�{‰{×*Ñ*Ð+CÈWÐ*ÓUˆô �d×(Ñ(¬#Ô.Ü˜˜T×/Ñ/Ó0‰EàˆEð<ˆà×ÑÐ%àØSñTñ ð
 +¬S°×1CÑ1CÓ-DÑDˆMð 	�‰�UÐ.Ô/Ø×+Ñ+Ó-Ðà×!Ñ!Ó#×*Ñ*¨7Ó3×;Ñ;¸DÀ"ÓE×MÑMÈdÐTVÓWð 	ô Ÿ
™
 =Ó1ˆØ Ñ" 9Ñ-ˆð /Ø& w iÐ0Ø ,ñ
ˆð
 	�‰�UÐ-°wˆÔ?Ø×)Ñ)Ó+ˆà×ÑÓ!×(Ñ(¨Ó1×9Ñ9¸$ÀÓC×KÑKÈDÐRTÓUð 	ô �z‰z˜*Ó%ˆô �dœDÔ!¡d±5Û�ðÜ"Ÿj™jà%( Eà)1¸mÑ LØ)/¸FÑ Cð)ñó�Gð —L‘L ¨°'¸7ÔCØ$(×$4Ñ$4Ó$6�Mà%×*Ñ*Ó,ß™ ›ß ™  rÓ*ß ™  rÓ*ð	 ô !%§
¡
¨9Ó 5�IØ ¨	Ñ1Ø Ø% iÑ0°Ñ3°IÑ>¸yÑI�EØ—J‘J”LØ ’Lð3 ð<	XÜ—j‘jà"à!)°mÑDØ!'°FÑ;ð!ñóˆGð �L‰L˜ ¨'°7Ô;Ø×'Ñ'Ó)ˆHà—‘“×&Ñ& wÓ/×7Ñ7¸¸bÓA×IÑIÈ$ÐPRÓSð ñ Ø—
‘
”Ø!Ð!ÜŸ
™
 :Ó.ˆIØ˜iÑ(¨Ñ+¨IÑ6°yÑAˆEØ�J‰JŒLØˆLøô5 !ò Úðûô6 ò 	XØ�L‰L˜ -°¨s°#°f°XÐ >ÈˆLÔPÜWûð	Xús8   Æ5BMÉMÉ7BM Ì4M Í	MÍMÍ	N ÍM;Í;N c                 ó4   — | j                   | j                  dœS )zGet the identifying parameters.©r   r   rU   r   s    r   Ú_identifying_paramsz"NIBittensorLLM._identifying_params¨   s    € ð "×/Ñ/Ø!×/Ñ/ñ
ð 	
r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r6   Ú__annotations__r   r4   Úpropertyr   r   r   r   rS   r   rV   r   r   r   r
   r
   
   sÁ   … ñð  ˜C‘=Ó ØWà#$€M�8˜C‘=Ó$ð#ð ð ˜3ò  ó ð ð %)Ø:>ñ	@Xàð@Xð �t˜C‘yÑ!ð@Xð Ð6Ñ7ð	@Xð
 ð@Xð 
ó@XðD ð
 W¨S°#¨XÑ%6ò 
ó ñ
r   r
   )Úhttp.clientr0   r<   r-   Útypingr   r   r   r   Úlangchain_core.callbacksr   Ú#langchain_core.language_models.llmsr   r
   r   r   r   Ú<module>ra      s(   ðÛ Û Û 
ß /Ó /å =Ý 3ôd
�Sõ d
r   