Ë
    uPêj  ã                   ó²   — U d dl Z d dlmZ d dlmZmZ d dlZd dlmZ dZ	ee
d<    G d„ de«      Zed	   Zg d	¢Zee
d
<   defd„Z ed¬«      dedefd„«       Zy)é    N)Ú	lru_cache)ÚFinalÚLiteral)ÚBaseLLMExceptionzhttps://huggingface.coÚ
HF_HUB_URLc                   óˆ   ‡ — e Zd Z	 	 	 ddej                  dz  dej
                  dz  dej                  ez  dz  fˆ fd„Zˆ xZ	S )ÚHuggingFaceErrorNÚrequestÚresponseÚheadersc                 ó.   •— t         ‰| �  |||||¬«       y )N)Ústatus_codeÚmessager
   r   r   )ÚsuperÚ__init__)Úselfr   r   r
   r   r   Ú	__class__s         €új/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/huggingface/common_utils.pyr   zHuggingFaceError.__init__   s&   ø€ ô 	‰ÑØ#ØØØØð 	õ 	
ó    )NNN)
Ú__name__Ú
__module__Ú__qualname__ÚhttpxÚRequestÚResponseÚHeadersÚdictr   Ú__classcell__)r   s   @r   r	   r	      sV   ø„ ð
 )-Ø*.Ø/3ñ
ð —‘ Ñ%ð	
ð
 —.‘. 4Ñ'ð
ð —‘ Ñ%¨Ñ,÷
ñ 
r   r	   )ztext-generation-inferenceÚconversationalztext-classificationztext-generationÚhf_task_listÚgenerated_textc                 óî   — g d¢}|D ]k  }| j                  «       j                  |«      r| j                  |dd«      } | j                  |«      sŒG| ddd…   j                  |ddd…   dd«      ddd…   } Œm | S )zÐ
    Parse the output text to remove any special characters. In our current approach we just check for ChatML tokens.

    Initial issue that prompted this - https://github.com/BerriAI/litellm/issues/763
    )z<|assistant|>z
<|system|>z<|user|>z<s>z</s>Ú é   Néÿÿÿÿ)ÚstripÚ
startswithÚreplaceÚendswith)r!   Úchat_template_tokensÚtokens      r   Úoutput_parserr,   -   sŒ   € ò #]ÐØ%ò TˆØ×ÑÓ!×,Ñ,¨UÔ3Ø+×3Ñ3°E¸2¸qÓAˆNØ×"Ñ" 5Õ)Ø+©D¨b¨DÑ1×9Ñ9¸%ÁÀ"À¹+ÀrÈ1ÓMÉdÐPRÈdÑS‰Nð	Tð
 Ðr   é€   )ÚmaxsizeÚmodelÚreturnc                 ó  — ddi}t        j                  d«      rdt        j                  d«      › �|d<   t        › d| › �}ddgi}	 t        j                  |||¬	«      }|j                  «        |j                  «       j	                  d«      }|€t        d| › �«      ‚|S # t        j                  $ rU}t        |d«      r/t        |j                  dd«      }t        |j                  di «      }nd}i }t        d|› �||¬«      ‚d
}~ww xY w)aT  
    Fetch provider mappings for a model from the Hugging Face Hub.

    Args:
        model: The model identifier (e.g., 'meta-llama/Llama-2-7b')

    Returns:
        dict: The inference provider mapping for the model

    Raises:
        ValueError: If no provider mapping is found
        HuggingFaceError: If the API request fails
    ÚAcceptzapplication/jsonÚHUGGINGFACE_API_KEYzBearer ÚAuthorizationz/api/models/ÚexpandÚinferenceProviderMapping)r   ÚparamsNz$No provider mapping found for model r   r   iô  r   z"Failed to fetch provider mapping: )r   r   r   )ÚosÚgetenvr   r   ÚgetÚraise_for_statusÚjsonÚ
ValueErrorÚ	HTTPErrorÚhasattrÚgetattrr   r	   )r/   r   Úpathr7   r   Úprovider_mappingÚer   s           r   Ú!_fetch_inference_provider_mappingrD   <   s  € ð Ð+Ð,€GÜ	‡y�yÐ&Ô'Ø%,¬R¯Y©YÐ7LÓ-MÐ,NÐ#Oˆ�Ñ ä�L ¨U¨GÐ4€DØÐ :Ð;Ð<€Fð
ÜŸ)™) D°'À&ÔIˆØ×!Ñ!Ô#Ø"*§-¡-£/×"5Ñ"5Ð6PÓ"QÐàÐ#ÜÐCÀEÀ7ÐKÓLÐLàÐøÜ�?‰?ò 
Ü�1�jÔ!Ü! !§*¡*¨m¸SÓAˆKÜ˜aŸj™j¨)°RÓ8‰GàˆKØˆGÜØ8¸¸Ð<Ø#Øô
ð 	
ûð
ús   ÁAB ÂDÂ2ADÄD)r8   Ú	functoolsr   Útypingr   r   r   Ú)litellm.llms.base_llm.chat.transformationr   r   Ú__annotations__r	   Úhf_tasksr    Ústrr,   r   rD   © r   r   ú<module>rL      s}   ðÜ 	Ý ß !ã å Fà,€
ˆEÓ ,ô
Ð'ô 
ð$ ðñ€ò€ˆeó ð #ó ñ �3Ôð)
¨Sð )
°Tò )
ó ñ)
r   