Ë
    uPêjÙ  ã                   ó8   — d Z ddlmZmZ ddlmZ  G d„ d«      Zy)zŒ
Anthropic CountTokens API transformation logic.

This module handles the transformation of requests to Anthropic's CountTokens API format.
é    )ÚAnyÚFinal)Ú%ANTHROPIC_TOKEN_COUNTING_BETA_VERSIONc                   ó²   — e Zd ZdZdefd„Z	 	 ddedeeeef      deeeef      dz  dedz  deeef   f
d	„Z	d
edeeef   fd„Z
dedeeeef      ddfd„Zy)ÚAnthropicCountTokensConfiga6  
    Configuration and transformation logic for Anthropic CountTokens API.

    Anthropic CountTokens API Specification:
    - Endpoint: POST https://api.anthropic.com/v1/messages/count_tokens
    - Beta header required: anthropic-beta: token-counting-2024-11-01
    - Response: {"input_tokens": <number>}
    Úreturnc                  ó   — y)z„
        Get the Anthropic CountTokens API endpoint.

        Returns:
            The endpoint URL for the CountTokens API
        z2https://api.anthropic.com/v1/messages/count_tokens© )Úselfs    úw/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/anthropic/count_tokens/transformation.pyÚ#get_anthropic_count_tokens_endpointz>AnthropicCountTokensConfig.get_anthropic_count_tokens_endpoint   s   € ð Dó    NÚmodelÚmessagesÚtoolsÚsystemc                 ó,   — ||dœ}|�||d<   |�||d<   |S )z”
        Transform request to Anthropic CountTokens format.

        Includes optional system and tools fields for accurate token counting.
        )r   r   r   r   r
   )r   r   r   r   r   Úrequests         r   Ú!transform_request_to_count_tokensz<AnthropicCountTokensConfig.transform_request_to_count_tokens   s8   € ð Ø ñ*
ˆð
 ÐØ &ˆG�HÑàÐØ$ˆG�GÑàˆr   Úapi_keyc                 óB   — ddl m} d|dt        dœ} |||¬«      \  }}|S )zº
        Get the required headers for the CountTokens API.

        Args:
            api_key: The Anthropic API key

        Returns:
            Dictionary of required headers
        r   )Ú!optionally_handle_anthropic_oauthzapplication/jsonz
2023-06-01)zContent-Typez	x-api-keyzanthropic-versionzanthropic-beta)Úheadersr   )Ú#litellm.llms.anthropic.common_utilsr   r   )r   r   r   r   Ú_s        r   Úget_required_headersz/AnthropicCountTokensConfig.get_required_headers8   s4   € õ	
ð
 /Ø Ø!-ÜCñ	#
ˆñ 7¸wÐPWÔX‰
ˆ�Øˆr   c                 ó  — |st        d«      ‚|st        d«      ‚t        |t        «      st        d«      ‚t        |«      D ]J  \  }}t        |t        «      st        d|› d�«      ‚d|vrt        d|› d�«      ‚d|vsŒ=t        d|› d	�«      ‚ y
)zè
        Validate the incoming count tokens request.

        Args:
            model: The model name
            messages: The messages to count tokens for

        Raises:
            ValueError: If the request is invalid
        zmodel parameter is requiredzmessages parameter is requiredzmessages must be a listzMessage z must be a dictionaryÚrolez must have a 'role' fieldÚcontentz must have a 'content' fieldN)Ú
ValueErrorÚ
isinstanceÚlistÚ	enumerateÚdict)r   r   r   ÚiÚmessages        r   Úvalidate_requestz+AnthropicCountTokensConfig.validate_requestO   s«   € ñ ÜÐ:Ó;Ð;áÜÐ=Ó>Ð>ä˜(¤DÔ)ÜÐ6Ó7Ð7ä# HÓ-ò 	M‰JˆAˆwÜ˜g¤tÔ,Ü  8¨A¨3Ð.CÐ!DÓEÐEà˜WÑ$Ü  8¨A¨3Ð.GÐ!HÓIÐIà Ò'Ü  8¨A¨3Ð.JÐ!KÓLÐLñ	Mr   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r"   r$   r   r   r   r'   r
   r   r   r   r      sÃ   „ ñðD°Só Dð .2Ø!ñàðð �t˜C ˜H‘~Ñ&ðð �D˜˜c˜‘NÑ# dÑ*ð	ð
 �d‘
ðð 
ˆc�3ˆh‰óð2¨Cð °D¸¸c¸±Nó ð.M cð M°T¸$¸sÀC¸x¹.Ñ5Ið MÈdô Mr   r   N)r+   Útypingr   r   Úlitellm.constantsr   r   r
   r   r   ú<module>r/      s    ðñ÷ å C÷_Mò _Mr   