Ë
    tPêj…«  ã                   ó"  — U d Z ddlZddlZddlZddlmZmZmZ ddlm	Z	m
Z
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 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%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ e	rddl,m-Z. ne
Z.dZ/ee0d<   dZ1ee0d<   dZ2ee0d<    ejf                  d«      Z4ee0d<    e5h d£«      Z6ee0d<   dZ7ee0d<   dZ8ee0d<   e%ez  Z9de:d e;fd!„Z<de:d e;dz  fd"„Z=d#e>d e;fd$„Z?d%e>d e;fd&„Z@d%e>d e;fd'„ZAd(ZBee0d)<    G d*„ d+e«      ZCy),aˆ  
This hook is used to inject cache control directives into messages.

Users can define
- `cache_control_injection_points` in the completion params and litellm will inject the cache control directives into the messages at the specified injection points.

Supported for both `v1/chat/completions` (via the prompt-management hook) and
`v1/messages` (via `apply_to_anthropic_messages_request`).

é    N)ÚIterableÚMappingÚSequence)ÚTYPE_CHECKINGÚAnyÚFinalÚcast)Úurlparse)Úverbose_logger)ÚCustomLogger)ÚCustomPromptManagement©ÚPromptManagementClient)Úwith_prompt_cache_breakpoint)Ú#GATEWAY_INJECTED_CACHE_METADATA_KEYÚ%GATEWAY_INJECTED_FOR_EVERY_DEPLOYMENTÚCacheControlInjectionPointÚ!CacheControlMessageInjectionPoint)ÚAllAnthropicToolsValuesÚAnthropicSystemMessageContent)ÚAllMessageValuesÚChatCompletionCachedContentÚChatCompletionTextObjectÚChatCompletionToolParamÚPromptCacheBreakpointÚPromptCacheOptions)Ú
PromptSpec)ÚStandardCallbackDynamicParams)ÚLoggingé   ÚMAX_CACHE_CONTROL_BLOCKS)Úcache_controlÚprompt_cache_breakpointÚCACHE_BREAKPOINT_KEYS)é   é   Ú.OPENAI_PROMPT_CACHE_BREAKPOINT_MIN_GPT_VERSIONz^gpt-(\d+)(?:\.(\d+))?Ú_GPT_VERSION_PATTERN>   ÚfileÚtextÚimageÚ	image_urlÚ
input_fileÚ
input_textÚinput_audioÚinput_imageÚ*OPENAI_PROMPT_CACHE_BREAKPOINT_BLOCK_TYPESzapi.openai.comÚOPENAI_API_HOST)ÚOPENAI_BASE_URLÚOPENAI_API_BASEÚOPENAI_API_BASE_ENV_VARSÚmodelÚreturnc                 ó  — t        | «      }|�|S t        j                  | j                  dd«      d   j	                  «       «      }|€yt        |j                  d«      «      t        |j                  d«      xs d«      f}|t        k\  S )Nú/é   éÿÿÿÿFé   r   )Ú'_model_map_prompt_cache_breakpoint_flagr(   ÚmatchÚrsplitÚlowerÚintÚgroupr'   )r6   Úmodel_map_flagÚversion_matchÚversions       úv/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/integrations/anthropic_cache_control_hook.pyÚ'supports_openai_prompt_cache_breakpointrG   E   s†   € ÜCÀEÓJ€NØÐ!ØÐÜ/×5Ñ5°e·l±lÀ3ÈÓ6JÈ2Ñ6N×6TÑ6TÓ6VÓW€MØÐØÜ˜-×-Ñ-¨aÓ0Ó1´3°}×7JÑ7JÈ1Ó7MÒ7RÐQRÓ3SÐT€GØÔDÑDÐDó    c                 ó„   ‡— dd l Šˆfd„| | j                  dd«      d   fD «       }d„ |D «       }t        d„ |D «       d «      S )Nr   c              3   óT   •K  — | ]  }‰j                   j                  |«      –— Œ! y ­w©N)Ú
model_costÚget)Ú.0ÚkeyÚlitellms     €rF   ú	<genexpr>z:_model_map_prompt_cache_breakpoint_flag.<locals>.<genexpr>S   s"   øè ø€ Ò_°c�g×(Ñ(×,Ñ,¨S×1Ñ_ùó   ƒ%(r9   r:   r;   c              3   ó`   K  — | ]&  }t        |t        «      sŒ|j                  d «      –— Œ( y­w)Ú supports_prompt_cache_breakpointN©Ú
isinstanceÚdictrM   )rN   Úentrys     rF   rQ   z:_model_map_prompt_cache_breakpoint_flag.<locals>.<genexpr>T   s&   è ø€ ÒrÀeÔZdÐejÔlpÕZq�E—I‘IÐ@×AÑrùs   ‚.˜.c              3   ó8   K  — | ]  }|€Œt        |«      –— Œ y ­wrK   )Úbool)rN   Úflags     rF   rQ   z:_model_map_prompt_cache_breakpoint_flag.<locals>.<genexpr>U   s   è ø€ ÒB °Ñ1A”�d—ÑBùs   ‚Š)rP   r?   Únext)r6   ÚentriesÚflagsrP   s      @rF   r=   r=   P   sE   ø€ Ûã_¸eÀUÇ\Á\ÐRUÐWXÓEYÐZ\ÑE]Ð=^Ô_€GÙrÈwÔr€EÜÑB¨ÔBÀDÓIÐIrH   Úapi_basec                 ó$  — dd l }t        d„ | |j                  gt        t        j
                  t        «      ¢­D «       d «      }t        |t        «      syt        |«      j                  }|d uxr# |t        k(  xs |j                  dt        › �«      S )Nr   c              3   ó&   K  — | ]	  }|sŒ|–— Œ y ­wrK   © )rN   Úvalues     rF   rQ   z%targets_openai_api.<locals>.<genexpr>\   s   è ø€ Òm�5ÒglŒÑmùs   ‚ŠTú.)rP   r\   r_   ÚmapÚosÚgetenvr5   rV   Ústrr
   Úhostnamer2   Úendswith)r_   rP   ÚresolvedÚhosts       rF   Útargets_openai_apirm   X   s€   € ÛäÙm˜X w×'7Ñ'7Ðc¼#¼b¿i¹iÔIaÓ:bÑcÔmØó€Hô �h¤Ô$ØÜ˜8Ó$×-Ñ-€DØ�tÐÒa ¬Ñ!8Ò!`¸D¿M¹MÈAÌoÐM^ÐJ_Ó<`ÐarH   Úblockc                 óX   ‡ — t        ‰ t        «      xr t        ˆ fd„t        D «       «      S )Nc              3   óD   •K  — | ]  }‰j                  |«      d u–— Œ y ­wrK   ©rM   )rN   rO   rn   s     €rF   rQ   z,_carries_cache_breakpoint.<locals>.<genexpr>f   s   øè ø€ Ò*gÈ#¨5¯9©9°S«>ÀÔ+EÑ*gùs   ƒ )rV   rW   Úanyr$   ©rn   s   `rF   Ú_carries_cache_breakpointrt   e   s!   ø€ Ü�eœTÓ"Òg¤sÓ*gÔQfÔ*gÓ'gÐgrH   c                 óT   — t        | t        «      xr | j                  d«      t        v S )NÚtype)rV   rW   rM   r1   rs   s    rF   Ú _accepts_prompt_cache_breakpointrw   i   s#   € Ü�eœTÓ"Òf u§y¡y°Ó'8Ô<fÐ'fÐfrH   Ú-_litellm_carry_unmatched_cache_control_pointsÚCARRY_UNMATCHED_MESSAGE_POINTSc                    ó˜  — e Zd Z	 	 	 	 	 dBdedee   dededz  dedz  dededz  d	edz  d
e	dz  de
dz  de
dz  deeee   ef   fd„Ze	 	 dCdedz  dedz  dedede
f
d„«       Zedededz  fd„«       ZedDdee   dede	fd„«       Ze	 dEdee   dee   de	de
dee   f
d„«       Zededee   dee	   fd„«       Zedede	fd„«       Zedede
fd„«       Ze	 dEdedede
defd „«       Zededefd!„«       Zed"eeef   dede
deeef   fd#„«       Ze	 dEdee   deez  dz  d$ee   de
deee   eez  dz  ee   f   f
d%„«       Zedefd&„«       Z edee   deeeef      fd'„«       Z!edee   dee   d(ee   dz  dededz  dededeeeef      dz  fd)„«       Z"edee   dededz  dededeeeef      fd*„«       Z#edee   d+ed,edeeeef      fd-„«       Z$edee   dee   deez  dz  d(edz  de
f
d.„«       Z%e	 dDdee   deez  dz  d(edz  de
fd/„«       Z&e	 	 dCdee   deez  dz  dededz  d(edz  d0e
dz  dee   fd1„«       Z'e	 	 dCdee   d2ee   d(ee(   dz  d0e
dz  dee   f
d3„«       Z)e	 	 	 dFdeee*f   dee   dededz  d(edz  d0e
dz  deddfd4„«       Z+ed5eeef   d6e	ddfd7„«       Z,e	 	 	 	 dGdee   deez  dz  d8eee*f   dedz  dedz  d(ee   dz  dedz  deee   eez  dz  f   fd9„«       Z-e.defd:„«       Z/dedz  dedz  dede
fd;„Z0	 	 dCdedz  dedz  dedz  ded	edz  d
e	dz  de1fd<„Z2	 	 	 dFdedz  dedz  dededz  d	edz  d
e	dz  de1fd=„Z3	 	 	 	 	 	 dHdedee   dededz  dedz  ded>e4dedz  d(ee   dz  d	edz  d
e	dz  de
dz  de
dz  deeee   ef   fd?„Z5edede
fd@„«       Z6edede7dz  fdA„«       Z8y)IÚAnthropicCacheControlHookNr6   ÚmessagesÚnon_default_paramsÚ	prompt_idÚprompt_variablesÚdynamic_callback_paramsÚprompt_specÚprompt_labelÚprompt_versionÚignore_prompt_manager_modelÚ%ignore_prompt_manager_optional_paramsr7   c                 óì  — t        |j                  t        d«      «      }|j                  dg «      }|s|||fS t        j                  |«      }g }g }|D ]G  }|j                  d«      dk(  r |j                  t        t        |«      «       Œ7|j                  |«       ŒI |d   j                  d«      }t        |t         «      r|nWt        j                  ||j                  d«      |j                  d«      xs |j                  d	«      |j                  d
«      «      }|rt        d„ |D «       «      nd}|rt        d„ |D «       «      n
t        |«      }|st        d„ |D «       «      rdnd}t        j                  |«      }| j                  ||t         |z
  |¬«      }|r4t        j                  |«      |kD  r|j#                  d
t%        d¬«      «       g |¢|¢­}|rt        j'                  |«      |d<   |||fS )a,  
        Apply cache control directives based on specified injection points.

        Returns:
        - model: str - the model to use
        - messages: List[AllMessageValues] - messages with applied cache controls
        - non_default_params: dict - params with any global cache controls
        FÚcache_control_injection_pointsÚlocationÚmessager   Ú_litellm_openai_dialectÚcustom_llm_providerr_   Úbase_urlÚprompt_cache_optionsc              3   óD   K  — | ]  }|j                  d «      �Œ|–— Œ y­w©ÚindexNrq   ©rN   Úpoints     rF   rQ   zGAnthropicCacheControlHook.get_chat_completion_prompt.<locals>.<genexpr>´   s   è ø€ ÒR˜E°u·y±yÀÓ7IÑ7Q”%ÑRùó   ‚ ™ rb   c              3   óD   K  — | ]  }|j                  d «      €Œ|–— Œ y­wr�   rq   r‘   s     rF   rQ   zGAnthropicCacheControlHook.get_chat_completion_prompt.<locals>.<genexpr>·   s   è ø€ ÒV˜E°u·y±yÀÓ7IÑ7U”%ÑVùr“   c              3   óD   K  — | ]  }|j                  d «      dk(  –— Œ y­w©rˆ   Útool_configNrq   ©rN   Úps     rF   rQ   zGAnthropicCacheControlHook.get_chat_completion_prompt.<locals>.<genexpr>¼   ó   è ø€ Ò+iÐST¨A¯E©E°*Ó,=ÀÕ,NÑ+iùó   ‚ r:   ©Úpointsr|   Ú
max_blocksÚopenai_dialectÚexplicit©Úmode)rZ   Úpopry   ÚcopyÚdeepcopyrM   Úappendr	   r   rV   r{   Ú'_targets_openai_prompt_cache_breakpointÚtuplerr   Úcount_request_cache_breakpointsÚ_apply_message_injectionsr!   Ú
setdefaultr   Ú_stamped_as_judged)Úselfr6   r|   r}   r~   r   r€   r�   r‚   rƒ   r„   r…   Úcarry_unmatchedÚinjection_pointsÚprocessed_messagesÚmessage_pointsÚremaining_pointsr’   Ústamped_dialectrŸ   Úcarried_message_pointsÚapplied_message_pointsÚreserved_blocksÚbreakpoints_beforeÚcarried_pointss                            rF   Úget_chat_completion_promptz4AnthropicCacheControlHook.get_chat_completion_promptu   s4  € ô. "&Ð&8×&<Ñ&<Ô=[Ð]bÓ&cÓ!dˆØDV×DZÑDZØ,¨bóE
Ðñ  Ø˜(Ð$6Ð6Ð6ô "Ÿ]™]¨8Ó4Ðð JLˆØDFÐØ%ò 	/ˆEØ�y‰y˜Ó$¨	Ò1Ø×%Ñ%¤dÔ+LÈeÓ&TÕUà ×'Ñ'¨Õ.ð		/ð "2°!Ñ!4×!8Ñ!8Ð9RÓ!Sˆô ˜/¬4Ô0ñ ä*×RÑRØØ"×&Ñ&Ð'<Ó=Ø"×&Ñ& zÓ2ÒXÐ6H×6LÑ6LÈZÓ6XØ"×&Ñ&Ð'=Ó>ó	ð 	ñ  WfŒEÑR ^ÔRÔRÐkmð 	ñ
 ô ÑV ^ÔVÔVä�~Ó&ð 	ñ $¬Ñ+iÐXhÔ+iÔ(i‰AÐopð 	ô %>×$]Ñ$]Ð^pÓ$qÐØ!×;Ñ;Ø)Ø'Ü/°/ÑAØ)ð	 <ó 
Ðñ Ü)×IÑIÐJ\Ó]Ð`rÒrà×)Ñ)Ð*@ÔBTÐZdÔBeÔfð GsÐHXÐFrÐ[qÑFrˆÙÜC\×CoÑCoØóDÐÐ?Ñ@ð Ð(Ð*<Ð<Ð<rH   r‹   r_   r�   c                 óz   — | �t        | «      sy|xs t        j                  | «      dk7  ry|d uxs t        |«      S )NFÚopenai)rG   r{   Ú_resolve_providerrm   )r6   r‹   r_   r�   s       rF   r§   zAAnthropicCacheControlHook._targets_openai_prompt_cache_breakpointØ   sG   € ð ˆ=Ô GÈÔ NØØÒUÔ#<×#NÑ#NÈuÓ#UÐZbÒbØØ#¨4Ð/ÒOÔ3EÀhÓ3OÐOrH   c                 óR   — ddl m} ddlm} 	  || ¬«      \  }}}}|S # |$ r Y y w xY w)Nr   )ÚBadRequestError©Úget_llm_provider©r6   )Úlitellm.exceptionsr¾   Ú1litellm.litellm_core_utils.get_llm_provider_logicrÀ   )r6   r¾   rÀ   Ú_Úproviders        rF   r¼   z+AnthropicCacheControlHook._resolve_providerå   s;   € å6ÝVð	Ù 0°uÔ =ÑˆAˆx˜˜Að ˆøð ò 	Ùð	ús   Ž ž&¥&Úsystemc                 ót   — t        |t        «      rt        d„ |D «       «      nd}|t        d„ | D «       «      z   S )Nc              3   ó8   K  — | ]  }t        |«      sŒd –— Œ y­w©r:   N©rt   ©rN   rn   s     rF   rQ   zLAnthropicCacheControlHook.count_request_cache_breakpoints.<locals>.<genexpr>ó   s   è ø€ ÒJ�eÔ)BÀ5Õ)I”ÑJùó   ‚“r   c              3   óF   K  — | ]  }t         j                  |«      –— Œ y ­wrK   ©r{   Ú_count_cache_control_blocks)rN   Úmsgs     rF   rQ   zLAnthropicCacheControlHook.count_request_cache_breakpoints.<locals>.<genexpr>õ   s   è ø€ Ò"rÐbeÔ#<×#XÑ#XÐY\×#]Ñ"rùs   ‚!)rV   ÚlistÚsum)r|   rÆ   Úsystem_blockss      rF   r©   z9AnthropicCacheControlHook.count_request_cache_breakpointsð   s@   € ô OYÐY_ÔaeÔNfŒCÑJ˜vÔJÔJÐlmð 	ð œsÑ"rÐiqÔ"rÓrÑrÐrrH   r�   rž   rŸ   c                 óÆ  — t         j                  |«      }d}| D ]¨  }||k\  rd} nŸ|j                  dd«      xs t        d¬«      }t         j	                  ||¬«      D ]_  }||k\  rd} nVt         j                  ||   «      rŒ%t         j                  ||   ||«      ||<   t         j                  ||   «      sŒ[|dz  }Œa |sŒ¨ n |rt        j                  d	t        «       |S )
aü  Apply message-level cache control injection points in order.

        Anthropic allows at most ``MAX_CACHE_CONTROL_BLOCKS`` cache_control
        breakpoints per request. Client-supplied breakpoints count toward that
        limit, so we never inject onto a message that already carries
        cache_control (preserving the client's TTL) and we stop injecting once
        ``max_blocks`` is reached. Injection points are honored in config order,
        so earlier points win when slots are scarce.
        FTÚcontrolNÚ	ephemeral©rv   )r’   r|   r:   zjAnthropicCacheControlHook: Reached the provider limit of %s cache breakpoints. Skipping further injection.)
r{   r©   rM   r   Ú_resolve_target_indicesÚ_message_has_cache_controlÚ%_safe_insert_cache_control_in_messager   Úwarningr!   )	r�   r|   rž   rŸ   Úused_blocksÚlimit_reachedr’   rÕ   Útarget_indexs	            rF   rª   z3AnthropicCacheControlHook._apply_message_injections÷   s  € ô  0×OÑOÐPXÓYˆàˆØò 	ˆEØ˜jÒ(Ø $�Ùà38·9±9¸YÈÓ3Mò 4ÔQlØ ôRˆGô !:× QÑ QÐX]ÐhpÐ QÓ qò %�Ø *Ò,Ø$(�MÙä,×GÑGÈÐQ]ÑH^Ô_àä)B×)hÑ)hØ˜\Ñ*¨G°^ó*�˜Ñ&ô -×GÑGÈÐQ]ÑH^Õ_Ø 1Ñ$‘Kð%ò Ùð3	ñ6 Ü×"Ñ"Ø|Ü(ôð
 ˆrH   r’   c                 óÈ  — | j                  dd«      }d}t        |t        «      r	 t        |«      }n|}|�P|}|dk  r|t        |«      z  }d|cxk  rt        |«      k  r|gS  t        j                  d|t        |«      |«       g S | j                  dd«      }|�3t        |«      D ��cg c]  \  }}|j                  d«      |k(  sŒ|‘Œ c}}S g S # t        $ r Y Œ¦w xY wc c}}w )z9Resolve which message indices an injection point targets.r�   Nr   z¤AnthropicCacheControlHook: Provided index %s is out of bounds for message list of length %s. Targeted index was %s. Skipping cache control injection for this point.Úrole)	rM   rV   rh   rA   Ú
ValueErrorÚlenr   rÛ   Ú	enumerate)r’   r|   Ú_targetted_indexÚtargetted_indexÚoriginal_indexÚtargetted_roleÚidxrÐ   s           rF   rØ   z1AnthropicCacheControlHook._resolve_target_indices-  s  € ð
 5:·I±I¸gÀtÓ4LÐØ&*ˆÜÐ&¬Ô,ðÜ"%Ð&6Ó"7‘ð /ˆOð Ð&Ø$3ˆNØ Ò"Ø¤3 x£=Ñ0�à�OÔ3¤c¨(£mÒ3Ø'Ð(Ð(ð 4ô ×"Ñ"ð wØÜ�H“Øô	ð ˆIð !&§	¡	¨&°$Ó 7ˆØÐ%Ü(1°(Ó(;×a™H˜C ¸s¿w¹wÀv»ÐR`Ó?`’CÓaÐaàˆ	øô7 ò Ùðüó2 bs   ¦C Â(CÃCÃ	CÃCr‰   c                 ó²   — t        | t        «      syt        | «      rdnd}| j                  d«      }t        |t        «      r|t        d„ |D «       «      z  }|S )Nr   r:   Úcontentc              3   ó8   K  — | ]  }t        |«      sŒd –— Œ y­wrÉ   rÊ   rË   s     rF   rQ   zHAnthropicCacheControlHook._count_cache_control_blocks.<locals>.<genexpr>[  s   è ø€ ÒT˜uÔ3LÈUÕ3SœÑTùrÌ   )rV   rW   rt   rM   rÑ   rÒ   )r‰   Úcountrê   s      rF   rÏ   z5AnthropicCacheControlHook._count_cache_control_blocksT  sO   € ä˜'¤4Ô(ØÜ.¨wÔ7‘¸QˆØ Ÿ™ YÓ/ˆÜ�gœtÔ$Ø”SÑT¨ÔTÓTÑTˆEØˆrH   c                 ó2   — t         j                  | «      dkD  S )z=Return True if the message already carries any cache_control.r   rÎ   )r‰   s    rF   rÙ   z4AnthropicCacheControlHook._message_has_cache_control^  s   € ô )×DÑDÀWÓMÐPQÑQÐQrH   rÕ   c                 óø   — |rt         j                  | «      S | j                  dd«      }t        |t        «      r|| d<   | S t        |t
        «      r)t        |«      dkD  rt        |d   t        «      r||d   d<   | S )ap  
        Safe way to insert cache control in a message

        OpenAI Message content can be either:
            - string
            - list of objects

        This method handles inserting cache control in both cases.
        Per Anthropic's API specification, when using multiple content blocks,
        only the last content block can have cache_control.
        rê   Nr"   r   r;   )r{   Ú*_insert_prompt_cache_breakpoint_in_messagerM   rV   rh   rÑ   râ   rW   )r‰   rÕ   rŸ   Úmessage_contents       rF   rÚ   z?AnthropicCacheControlHook._safe_insert_cache_control_in_messagec  s�   € ñ Ü,×WÑWÐX_Ó`Ð`à!(§¡¨Y¸Ó!=ˆô �o¤sÔ+Ø'.ˆG�OÑ$ð
 ˆô ˜¬Ô.Ü�?Ó# aÒ'¬J°ÀrÑ7JÌDÔ,QØ7>� Ñ# OÑ4ØˆrH   c                 ó¤  ‡— | j                  d«      dk(  r| S | j                  dd «      Št        ‰t        «      r<t        j                  | «      }t	        t        d‰¬«      t        d¬«      «      g|d<   |S t        ‰t        «      rJt        ˆfd„t        t        ‰«      d	z
  d
d
«      D «       d «      }|�t	        ‰|   t        d¬«      «      ‰|<   | S )Nrà   Ú	assistantrê   r*   ©rv   r*   r    r¡   c              3   ó>   •K  — | ]  }t        ‰|   «      r|–— Œ y ­wrK   )rw   )rN   r�   rð   s     €rF   rQ   zWAnthropicCacheControlHook._insert_prompt_cache_breakpoint_in_message.<locals>.<genexpr>�  s&   øè ø€ ò àÜ7¸ÈÑ8NÔOô ñùs   ƒr:   r;   )rM   rV   rh   r¤   r   r   r   rÑ   r\   Úrangerâ   )r‰   ÚmarkedrÞ   rð   s      @rF   rï   zDAnthropicCacheControlHook._insert_prompt_cache_breakpoint_in_message€  sÖ   ø€ à�;‰;�vÓ +Ò-ØˆNØ!(§¡¨Y¸Ó!=ˆÜ�o¤sÔ+Ü ŸI™I gÓ.ˆFä,Ü,°&¸ÔOÔQfÐlvÔQwóð!ˆF�9Ñð
 ˆMÜ�o¤tÔ,Ü"&óä!&¤s¨?Ó';¸aÑ'?ÀÀRÓ!Hôð
 ó#ˆLð Ð'Ü0LØ# LÑ1Ô3HÈjÔ3Yó1� Ñ-ð ˆrH   rn   c                 óF   — |rdt        d¬«      fnd|f}i | ¥|d   |d   i¥S )Nr#   r    r¡   r"   r   r:   )r   )rn   rÕ   rŸ   Úmarkers       rF   Ú_system_block_with_breakpointz7AnthropicCacheControlHook._system_block_with_breakpointœ  s@   € ñ ð 'Ô(=À:Ô(NÑOà! 7Ð+ð 	ð
 /�%Ð.˜ ™ F¨1¡IÑ.Ð.rH   r¯   c                 óŒ  — |s| |g fS t        j                  | «      }|�t        j                  |«      nd}g }g }g }|D ]o  }	|	j                  d«      dk(  rHt        t        |	«      }
|
j                  d«      dk(  r|j                  |
«       ŒM|j                  |
«       Œ_|j                  |	«       Œq |st        d„ |D «       «      rdnd}t        |z
  }t        j                  |«      }t        j                  d	|«      }|rÎ|�Ì||z   |k  rÄt        |t        «      xr t        d
„ |D «       «      }|sž|d   j                  d«      xs t        d¬«      }t        |t        «      r)t        j                  t        d|¬«      ||«      g}|dz  }nCt!        |«      dkD  r5t        |d   t"        «      r"t        j                  |d   ||«      |d<   |dz  }t%        |«      D ]6  \  }}|j                  d«      }t        |t        «      sŒ(i |¥dd|dœgi¥||<   Œ8 t        j'                  |t        t        t(           |«      ||z
  |¬«      }|||fS )z˜Apply cache control injection for the Anthropic-native v1/messages endpoint.

        Returns (messages, system, remaining_non_message_points).
        Nrˆ   r‰   rà   rÆ   c              3   óD   K  — | ]  }|j                  d «      dk(  –— Œ y­wr–   rq   r˜   s     rF   rQ   zPAnthropicCacheControlHook.apply_to_anthropic_messages_request.<locals>.<genexpr>Ç  rš   r›   r:   r   rb   c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wrK   rÊ   )rN   Úbs     rF   rQ   zPAnthropicCacheControlHook.apply_to_anthropic_messages_request.<locals>.<genexpr>Ï  s   è ø€ ò VØ12Ô)¨!×,ñVùs   ‚rÕ   rÖ   r×   r*   ró   r;   rê   rœ   )r¤   r¥   rM   r	   r   r¦   rr   r!   r{   r©   rV   rÑ   r   rh   rù   r   râ   rW   rã   rª   r   )r|   rÆ   r¯   rŸ   r°   Úprocessed_systemr±   Úsystem_pointsr²   r’   Ú	msg_pointr¶   rž   Úmessage_blocksrÓ   Úsystem_already_has_ccrÕ   ÚirÐ   rê   s                       rF   Ú#apply_to_anthropic_messages_requestz=AnthropicCacheControlHook.apply_to_anthropic_messages_request§  sŒ  € ñ  Ø˜V RÐ'Ð'ä)-¯©°xÓ)@ÐØ4:Ð4Fœ4Ÿ=™=¨Ô0ÈDÐàIKˆØHJˆØDFÐà%ò 	/ˆEØ�y‰y˜Ó$¨	Ò1Ü Ô!BÀEÓJ�	Ø—=‘= Ó(¨HÒ4Ø!×(Ñ(¨Õ3à"×)Ñ)¨)Õ4à ×'Ñ'¨Õ.ð	/ñ $¬Ñ+iÐXhÔ+iÔ(i‰AÐopð 	ô 5°ÑFˆ
ä 9× YÑ YÐZlÓ mˆÜ1×QÑQÐRTÐVfÓgˆáÐ-Ð9¸nÈ}Ñ>\Ð_iÒ>iÜ+5Ð6FÌÓ+Mò ,ÔRUñ VØ6FôVó SÐ!ñ )Ø!.¨qÑ!1×!5Ñ!5°iÓ!@Ò!qÔD_ÐepÔDq�ÜÐ.´Ô4ä1×OÑOÜ9¸vÐL\Ô]Ð_fÐhvóð(Ð$ð
 " QÑ&‘MÜÐ)Ó*¨QÒ.´:Ð>NÈrÑ>RÔTXÔ3YÜ+D×+bÑ+bØ(¨Ñ,¨g°~ó,Ð$ RÑ(ð " QÑ&�MäÐ 2Ó3ò 	`‰FˆAˆsØ—g‘g˜iÓ(ˆGÜ˜'¤3Õ'Ø(_¨3Ð(_°	ÀVÐU\Ñ<]Ð;^Ñ(_Ð" 1Ò%ð	`ô
 7×PÑPØ!Üœ$Ô/Ñ0Ð2DÓEØ! MÑ1Ø)ð	 Qó 
Ðð "Ð#3Ð5EÐEÐErH   c                  óh   — ddl } | j                  }|dk(  s|dk(  rt        d|¬«      S t        d¬«      S )zÞBuild the cache_control block for auto-injected breakpoints.

        Defaults to Anthropic's 5-minute ephemeral cache; honors the optional
        ``litellm.anthropic_prompt_caching_ttl`` override ("5m" or "1h").
        r   NÚ5mÚ1hrÖ   )rv   Úttlr×   )rP   Úanthropic_prompt_caching_ttlr   )rP   r  s     rF   Ú_default_controlz*AnthropicCacheControlHook._default_controlï  s7   € ó 	à×9Ñ9ˆØ�$Š;˜# š+Ü.°KÀSÔIÐIÜ*°Ô<Ð<rH   c                 ó0   — t         j                  | dd«      S )zêMark written-back points as having passed the client cache_control judgment.

        Builds copies because config-owned point dicts are shared across
        requests; mutating them would leak the stamp into future requests.
        Ú_litellm_judgedT)r{   Ú_stamped)r�   s    rF   r¬   z,AnthropicCacheControlHook._stamped_as_judgedý  s   € ô )×1Ñ1°&Ð:KÈTÓRÐRrH   Útoolsc                 óf   — t         j                  | |d |«      ry t         j                  | ||||«      S rK   )r{   Ú_should_stand_downÚ_stamped_with_dialect)r�   r|   r  r6   r‹   r_   r�   s          rF   Ú_judged_configured_pointsz3AnthropicCacheControlHook._judged_configured_points  s<   € ô %×7Ñ7¸ÀÈ$ÐPUÔVØÜ(×>Ñ>Ø�EÐ.°Ð:Nó
ð 	
rH   c           
      óv   — t        |«      s| S t        j                  | dt        j                  ||||«      «      S )NrŠ   )rG   r{   r  r§   )r�   r6   r‹   r_   r�   s        rF   r  z/AnthropicCacheControlHook._stamped_with_dialect  sC   € ô 7°uÔ=ØˆMÜ(×1Ñ1ØØ%Ü%×MÑMØÐ*¨HÐ6Jóó
ð 	
rH   rO   rc   c                 ó8   — | D �cg c]
  }i |¥||i¥‘Œ c}S c c}w rK   rb   )r�   rO   rc   r’   s       rF   r  z"AnthropicCacheControlHook._stamped(  s%   € ð 4:Ö:¨%Ð%�5Ð%˜#˜uÓ%Ò:Ð:ùÒ:s   …c                 óV   — t        d„ | D «       «      ryt        j                  |||«      S )a  Whether configured injection points must yield to client-set cache_control.

        Points that a prior pass over this request already judged and wrote
        back carry the internal judged stamp; any re-entry (acompletion
        re-entering completion, the async-to-sync /v1/messages dispatch,
        interceptor sub-calls reusing the request kwargs) must not re-judge
        them, because by then the messages carry litellm's own injected marks
        and the judgment would misread those as client breakpoints.
        c              3   ó>   K  — | ]  }|j                  d «      –— Œ y­w)r  Nrq   r‘   s     rF   rQ   z?AnthropicCacheControlHook._should_stand_down.<locals>.<genexpr>>  s   è ø€ Ò@°ˆu�y‰yÐ*×+Ñ@ùs   ‚F)Úallr{   Ú_request_has_cache_control)r�   r|   rÆ   r  s       rF   r  z,AnthropicCacheControlHook._should_stand_down.  s+   € ô  Ñ@¸Ô@Ô@ØÜ(×CÑCÀHÈfÐV[Ó\Ð\rH   c                 ó`   — t         j                  | |«      dkD  ry|�t        d„ |D «       «      S y)a�  Return True if the request already carries any client-supplied cache_control.

        When the client (e.g. Claude Code) already marks its own breakpoints we
        stand down entirely rather than add more, per the auto-caching contract.
        Tools count: they are a breakpoint the client can mark, they count toward
        the provider's four-block limit, and caching only the tool definitions is
        a common pattern, so injecting alongside them can exceed the cap. Tools
        carry the mark either at the top level (Anthropic shape) or nested under
        ``function`` (OpenAI shape); the Anthropic chat transform accepts both.
        r   Tc              3   óØ   K  — | ]b  }t        |t        «      xrL |j                  d «      duxs7 t        |j                  d«      t        «      xr |d   j                  d «      du–— Œd y­w)r"   NÚfunctionrU   )rN   Útools     rF   rQ   zGAnthropicCacheControlHook._request_has_cache_control.<locals>.<genexpr>U  sq   è ø€ ò ð ô ˜4¤Ó&ò à—H‘H˜_Ó-°TÐ9ò vÜ" 4§8¡8¨JÓ#7¼Ó>ÒtÀ4È
ÑCS×CWÑCWÐXgÓChÐptÐCtóñùs   ‚A(A*F)r{   r©   rr   )r|   rÆ   r  s      rF   r  z4AnthropicCacheControlHook._request_has_cache_controlB  sD   € ô  %×DÑDÀXÈvÓVÐYZÒZØØÐÜñ ð "ôó ð ð rH   Úenable_prompt_cachingc                 óP  — ddl }|j                  dur|durg S |}|€ddlm} 	  ||¬«      \  }	}}	}	|dvrg S ddlm}
  |
||¬«      sg S t        j                  | ||«      rg S t        j                  «       }t        d	d
d|¬«      t        d	dd|¬«      g}|S # t        $ r g cY S w xY w)aÚ  Default breakpoints when ``litellm.enable_anthropic_prompt_caching`` is on.

        ``enable_prompt_caching`` is the per-request override (stamped from key
        metadata by the proxy); True turns auto-injection on for this request
        even when the global flag is off. Caches the system prompt and the
        trailing turn, so the stable prefix (system + tools + history) is
        reused while the breakpoint advances with the conversation. Returns []
        (stand down) when neither flag is on, the provider does not consume
        cache_control breakpoints (only anthropic / bedrock do), the model
        lacks prompt-caching support, or the request already carries
        client-supplied cache_control.
        r   NTr¿   rÁ   )Ú	anthropicÚbedrock)Úsupports_prompt_caching)r6   r‹   r‰   rÆ   )rˆ   rà   r�   rÕ   r;   )rP   Úenable_anthropic_prompt_cachingrÃ   rÀ   Ú	ExceptionÚlitellm.utilsr!  r{   r  r
  r   )r|   rÆ   r6   r‹   r  r  rP   rÅ   rÀ   rÄ   r!  rÕ   r�   s                rF   Úget_default_injection_pointsz6AnthropicCacheControlHook.get_default_injection_points_  s×   € ó* 	à×2Ñ2¸$Ñ>ÐCXÐ`dÑCdØˆIà&ˆØÐõðÙ$4¸5Ô$AÑ!��8˜Q ð Ð3Ñ3ØˆIå9á&¨UÈÕQØˆIä$×?Ñ?ÀÈ&ÐRWÔXØˆIä2×CÑCÓEˆä-°yÀxÐW[ÐelÔmÜ-°yÀtÐSUÐ_fÔgð;
ˆð ˆøô' ò Ø’	ðús   ¤B ÂB%Â$B%Úmodelsc                 óÔ   ‡ ‡‡— t        d„ ˆˆ ˆfd„|D «       D «       d«      }|s‰ S t        j                  t        t        t
           |«      t        j                  ‰ «      t        ¬«      S )a€  Return the messages auto prompt caching will send, default breakpoints included.

        Router cache affinity depends on this. Deployment selection runs before the injection in
        `litellm.acompletion`, so it has to reproduce the markers to derive the same cache key the
        success event later writes from the sent messages. `models` is every candidate model of the
        group: the first that would auto-inject decides, since the default breakpoints (system
        prompt and trailing turn) do not depend on which deployment serves the call. Returns the
        input list itself when auto-injection would not apply
        c              3   ó$   K  — | ]  }|r|–— Œ
 y ­wrK   rb   ©rN   Ú	candidates     rF   rQ   zMAnthropicCacheControlHook.messages_with_default_injections.<locals>.<genexpr>§  s   è ø€ ò àñ ô ñùs   ‚c           	   3   óT   •K  — | ]  }t         j                  ‰d |d ‰‰¬«      –— Œ! y ­w)N©r|   rÆ   r6   r‹   r  r  )r{   r%  )rN   r6   r  r|   r  s     €€€rF   rQ   zMAnthropicCacheControlHook.messages_with_default_injections.<locals>.<genexpr>©  s>   øè ø€ ò 
"ð ô .×JÑJØ!)Ø#Ø#Ø,0Ø#Ø.Cð K÷ ñ
"ùrR   N)r�   r|   rž   )	r\   r{   rª   r	   rÑ   r   r¤   r¥   r!   )r|   r&  r  r  r�   s   ` `` rF   Ú messages_with_default_injectionsz:AnthropicCacheControlHook.messages_with_default_injections–  st   ú€ ô  ñõ
"ð "(ô
"ôð ó!
ˆñ$ ØˆOÜ(×BÑBÜÜÔ6Ñ7¸óô —]‘] 8Ó,Ü/ð Có 
ð 	
rH   c                 óú   — | j                  d«      rGt        j                  | d   |||||| j                  d«      «      }|€| j                  d«       y|| d<   yt        j	                  |d||||¬«      }|r|| d<   yy)a½  For /chat/completions: resolve the injection points the request should carry.

        Configured injection points win over the automatic defaults, but stand
        down entirely when the client already marked its own cache_control
        breakpoints (messages or tools): injecting alongside them clashes with
        the client's caching strategy and can exceed the provider's four-block
        limit. The judgment happens once per request; points a prior pass
        wrote back carry the judged stamp and are never re-judged (see
        ``_should_stand_down``). Seeding the param lets the existing
        prompt-management gate and the AnthropicCacheControlHook run
        unchanged.
        r‡   r�   Nr,  )rM   r{   r  r£   r%  )	r}   r|   r6   r‹   r  r  r_   Újudgedr�   s	            rF   Ú#maybe_seed_default_injection_pointsz=AnthropicCacheControlHook.maybe_seed_default_injection_pointsÂ  s¶   € ð, ×!Ñ!Ð"BÔCÜ5×OÑOØ"Ð#CÑDØØØØ#ØØ"×&Ñ&Ð'=Ó>óˆFð ˆ~Ø"×&Ñ&Ð'GÔHð ð HNÐ"Ð#CÑDØÜ1×NÑNØØØØ 3ØØ"7ð Oó 
ˆñ ØCIÐÐ?Ò@ð rH   Úrequest_kwargsÚaddedc                 ó  — |dk  ryt        d„ | j                  d«      | j                  d«      fD «       d«      }|�E| j                  d«      }t        |t        «      r|j                  dt        «      nt        |t
        <   yy)a;	  Name the deployment whose payload the gateway, not the client, put breakpoints on.

        Spend accounting only asks whether litellm acted, so what it needs is which
        deployment, not a count. Recording that is what makes the mark attempt-scoped: the
        metadata bucket is one dict shared by every retry, failover and fallback of a
        request, and ``litellm_call_id`` is shared with it, so anything request-scoped
        written by one attempt is read by all of them and each boundary would have to
        remember to strip it. The deployment is the part that actually changes when the
        request moves, so a leg that injected nothing is never credited for one that did.

        It also makes a zero delta (hook re-entry) and a negative one (a prompt manager
        replacing the messages) harmless, since neither rewrites an earlier mark.

        A pass that runs before a deployment is chosen, which is what the proxy does for
        prompt templates, injects into the payload every leg goes on to send, so it marks
        the request for all of them rather than for one.

        Only what this pass actually placed counts. A ``tool_config`` point is placed by
        the Bedrock converse transform, and only when the request carries tools, so the
        presence of one here says nothing about whether a breakpoint reaches the wire;
        claiming it marked three request shapes out of four that inject nothing. Missing
        that Bedrock credit is the fail-closed direction, and the alternative is a
        provider transform that carries spend-attribution state.

        Reads whichever bucket the request actually carries rather than asking the shared
        name resolver, which answers on key presence: ``litellm_params`` declares
        ``litellm_metadata`` as None on every request, so the resolver names a bucket that
        is not there and the mark is dropped.

        Never CREATES the bucket. The proxy seeds it on every request and is the marker's
        only reader, so a request without one is a bare SDK call nothing would consume it
        from. Creating it would also add a key to a dict call sites splat as ``**kwargs``,
        and on the Responses API ``metadata`` is both this bucket's default name and an
        explicit parameter, so the splat collides with the caller's own value.
        r   Nc              3   ó@   K  — | ]  }t        |t        «      r|–— Œ y ­wrK   )rV   rW   r)  s     rF   rQ   zEAnthropicCacheControlHook.record_gateway_injection.<locals>.<genexpr>  s"   è ø€ ò àÜ˜i¬Ô.ô ñùs   ‚Úlitellm_metadataÚmetadataÚ
model_infoÚid)r\   rM   rV   rW   r   r   )r1  r2  Úbucketr7  s       rF   Úrecord_gateway_injectionz2AnthropicCacheControlHook.record_gateway_injectionò  s�   € ðP �AŠ:ØÜñà"0×"4Ñ"4Ð5GÓ"HÈ.×J\ÑJ\Ð]gÓJhÐ!iôð
 ó
ˆð ÐØ .× 2Ñ 2°<Ó @ˆJô ˜j¬$Ô/ð —‘˜tÔ%JÔKä:ð Ô6Ò7ð rH   Úkwargsc                 óð  — t        t        t           | «      }t        t        dz  |j	                  dd«      «      }t        t        t
           dz  |j	                  dd«      «      }	|	rt        j                  |	|||«      r| |fS |	xs g }
|
s|�t        j                  ||||||¬«      }
|
s| |fS t        j                  ||||j                  d«      «      }t        j                  | |«      }t        j                  | ||
|¬«      \  } }}t        j                  | |«      |z
  }t        j                  ||«       |r!|dkD  r|j                  dt        d¬	«      «       |rt        j!                  |«      |d<   | |fS )
a!  Extract cache_control_injection_points from kwargs and apply if present.

        Configured points stand down entirely when the client already marked
        its own cache_control breakpoints anywhere in the request. The
        judgment happens once per request; points a prior pass wrote back
        carry the judged stamp and are never re-judged (see
        ``_should_stand_down``). When none are configured but
        ``litellm.enable_anthropic_prompt_caching`` or the per-request
        ``enable_prompt_caching`` kwarg (stamped from key metadata) is on,
        synthesize default breakpoints for the native /v1/messages path. Pops
        both keys from kwargs;
        if remaining (non-message) points exist they are written back so
        downstream transforms can handle them.
        Nr  r‡   )r|   rÆ   r  r6   r‹   r  r�   )r|   rÆ   r¯   rŸ   r   r    r¡   )r	   rÑ   r   rZ   r£   r   r{   r  r%  r§   rM   r©   r  r:  r«   r   r¬   )r|   rÆ   r;  r6   r‹   r  r_   Útyped_messagesr  Ú
configuredr¯   rŸ   r·   Ú	remainingÚbreakpoints_addeds                  rF   Úmaybe_inject_cache_controlz4AnthropicCacheControlHook.maybe_inject_cache_control,  s®  € ô0 œdÔ#3Ñ4°hÓ?ˆÜ'+Ü�4‰K˜Ÿ™Ð$;¸TÓBó(
Ðô !ÜÔ+Ñ,¨tÑ3°V·Z±ZÐ@`ÐbfÓ5gó
ˆ
ñ Ô3×FÑFÀzÐSaÐciÐkpÔqØ˜VÐ#Ð#Ø=GÒ=MÈ2ÐÙ EÐ$5Ü8×UÑUØ'ØØØØ$7Ø&;ð  Vó  Ðñ  Ø˜VÐ#Ð#ä 9× aÑ aØÐ&¨°&·*±*Ð=SÓ2Tó!
ˆô %>×$]Ñ$]Ð^fÐhnÓ$oÐÜ&?×&cÑ&cØØØ-Ø)ð	 'dó '
Ñ#ˆ�&˜)ô &×EÑEÀhÐPVÓWÐZlÑlð 	ô 	"×:Ñ:¸6ÐCTÔUÙÐ/°!Ò3Ø×ÑÐ4Ô6HÈjÔ6YÔZÙÜ7P×7cÑ7cÐdmÓ7nˆFÐ3Ñ4Ø˜ÐÐrH   c                  ó   — y)z*Return the integration name for this hook.Úanthropic_cache_control_hookrb   )r­   s    rF   Úintegration_namez*AnthropicCacheControlHook.integration_namen  s   € ð .rH   c                  ó   — y)zFAlways return False since this is not a true prompt management system.Frb   )r­   r~   r�   r€   s       rF   Úshould_run_prompt_managementz6AnthropicCacheControlHook.should_run_prompt_managements  s   € ð rH   c                 ó"   — t        |g ddd¬«      S )úCNot used - this hook only modifies messages, doesn't fetch prompts.N)r~   Úprompt_templateÚprompt_template_modelÚprompt_template_optional_paramsÚcompleted_messagesr   )r­   r~   r�   r   r€   r‚   rƒ   s          rF   Ú_compile_prompt_helperz0AnthropicCacheControlHook._compile_prompt_helper|  s    € ô &ØØØ"&Ø,0Ø#ô
ð 	
rH   c              ƒ   ó8   K  — | j                  ||||||¬«      S ­w)rH  )r~   r�   r   r€   r‚   rƒ   )rM  )r­   r~   r   r€   r�   r‚   rƒ   s          rF   Úasync_compile_prompt_helperz5AnthropicCacheControlHook.async_compile_prompt_helperŽ  s2   è ø€ ð ×*Ñ*ØØ#Ø-Ø$;Ø%Ø)ð +ó 
ð 	
ùs   ‚Úlitellm_logging_objc              ƒ   óB   K  — | j                  ||||||||
|||¬«      S ­w)zCAsync version - delegates to sync since no async operations needed.)r6   r|   r}   r~   r   r€   r�   r‚   rƒ   r„   r…   )r¹   )r­   r6   r|   r}   r~   r   r€   rP  r�   r  r‚   rƒ   r„   r…   s                 rF   Ú async_get_chat_completion_promptz:AnthropicCacheControlHook.async_get_chat_completion_prompt¡  sA   è ø€ ð" ×.Ñ.ØØØ1ØØ-Ø$;Ø#Ø%Ø)Ø(CØ2Wð /ó 
ð 	
ùs   ‚c                 ó*   — | j                  dd «      ryy)Nr‡   TFrq   )r}   s    rF   Ú'should_use_anthropic_cache_control_hookzAAnthropicCacheControlHook.should_use_anthropic_cache_control_hookÀ  s   € à×!Ñ!Ð"BÀDÔIØØrH   c                 óP   — ddl m} t        j                  | «      r |dd d ¬«      S y )Nr   )Ú$_init_custom_logger_compatible_classrC  )Úlogging_integrationÚinternal_usage_cacheÚ
llm_router)Ú*litellm.litellm_core_utils.litellm_loggingrV  r{   rT  )r}   rV  s     rF   Ú2get_custom_logger_for_anthropic_cache_control_hookzLAnthropicCacheControlHook.get_custom_logger_for_anthropic_cache_control_hookÆ  s3   € õ	
ô %×LÑLÐM_Ô`Ù7Ø$BØ%)Øôð ð
 rH   )NNNFF)NNrK   )F)NNN)NNNN)NNNNFF)9Ú__name__Ú
__module__Ú__qualname__rh   rÑ   r   rW   r   r   rA   rZ   r¨   r¹   ÚstaticmethodÚobjectr§   r¼   r   r©   r   r   rª   rØ   rÏ   rÙ   r   rÚ   rï   r   rù   r   r  r
  r¬   r  r  r  r  r  r%  ÚAllToolParamValuesr-  r   r0  r:  rA  ÚpropertyrD  rF  r   rM  rO  ÚLiteLLMLoggingObjrR  rT  r   r[  rb   rH   rF   r{   r{   t   sw
  „ ð *.Ø#'Ø%)Ø38Ø=Bña=àða=ð Ð'Ñ(ða=ð !ð	a=ð
 ˜‘:ða=ð  ™+ða=ð "?ða=ð   $Ñ&ða=ð ˜D‘jða=ð ˜d™
ða=ð &*¨D¡[ða=ð 04°d©{ða=ð 
ˆs�DÐ)Ñ*¨DÐ0Ñ	1óa=ðF ð  Ø'+ñ	
PØ�T‰zð
Pà  4™Zð
Pð ð
Pð %ð	
Pð
 
ò
Pó ð
Pð ð ð ¨¨t©ò ó ðð ñs°(¸6Ñ2Bð sÈFð sÐ^aò só ðsð ð
  %ñ	3ØÐ:Ñ;ð3àÐ'Ñ(ð3ð ð3ð ð	3ð
 
ÐÑ	ò3ó ð3ðj ð$Ø0ð$Ø<@ÐAQÑ<Rð$à	ˆc‰ò$ó ð$ðL ð¨Vð ¸ò ó ðð ðRÐ,<ð RÀò Ró ðRð à`eñØ!ðØ,GðØY]ðà	òó ðð8 ðÐ<Lð ÐQaò ó ðð6 ð/Ø�s˜F�{Ñ#ð/Ø.Ið/Ø[_ð/à	��f�Ñ	ò/ó ð/ð ð
  %ñ	EFØ�t‘*ðEFà�d‘
˜TÑ!ðEFð Ð9Ñ:ðEFð ð	EFð
 
ˆt�D‰z˜3 ™:¨Ñ,¨dÐ3MÑ.NÐNÑ	OòEFó ðEFðN ð=Ð9ò =ó ð=ð ðS 8Ð,FÑ#Gð SÈHÐU\Ð]`ÐbhÐ]hÑUiÑLjò Só ðSð ð
ØÐ3Ñ4ð
àÐ'Ñ(ð
ð �F‰|˜dÑ"ð
ð ð	
ð
 ! 4™Zð
ð ð
ð %ð
ð 
�'˜#˜v˜+Ñ&Ñ	'¨$Ñ	.ò
ó ð
ð ð
ØÐ3Ñ4ð
àð
ð ! 4™Zð
ð ð	
ð
 %ð
ð 
�'˜#˜v˜+Ñ&Ñ	'ò
ó ð
ð" ð;ØÐ3Ñ4ð;Ø;>ð;ØGMð;à	�'˜#˜v˜+Ñ&Ñ	'ò;ó ð;ð
 ð]ØÐ3Ñ4ð]àÐ'Ñ(ð]ð �d‘
˜TÑ!ð]ð �d‰{ð	]ð
 
ò]ó ð]ð& ð "ñØÐ'Ñ(ðà�d‘
˜TÑ!ðð �d‰{ðð 
ò	ó ðð8 ð "Ø-1ñ4ØÐ'Ñ(ð4à�d‘
˜TÑ!ð4ð ð4ð ! 4™Zð	4ð
 �d‰{ð4ð  $ d™{ð4ð 
Ð(Ñ	)ò4ó ð4ðl ð 26Ø-1ñ	)
ØÐ'Ñ(ð)
à˜‘ð)
ð Ð&Ñ'¨$Ñ.ð)
ð  $ d™{ð	)
ð
 
ÐÑ	ò)
ó ð)
ðV ð "Ø-1Øñ-JØ   c ™Nð-JàÐ'Ñ(ð-Jð ð-Jð ! 4™Zð	-Jð
 �d‰{ð-Jð  $ d™{ð-Jð ð-Jð 
ò-Jó ð-Jð^ ð7Ø  V Ñ,ð7àð7ð 
ò7ó ð7ðr ð
 !Ø*.Ø#'Ø#ñ? Ø�t‘*ð? à�d‘
˜TÑ!ð? ð �S˜#�X‘ð? ð �T‰zð	? ð
 ! 4™Zð? ð �D‰z˜DÑ ð? ð ˜‘*ð? ð 
ˆt�D‰z˜3 ™:¨Ñ,Ð,Ñ	-ò? ó ð? ðB ð. #ò .ó ð.ðà˜‘:ðð   $Ñ&ðð "?ð	ð
 
óð $(Ø%)ñ
à˜‘:ð
ð   $Ñ&ð
ð  ™+ð	
ð
 "?ð
ð ˜D‘jð
ð ˜d™
ð
ð 
 ó
ð. *.Ø#'Ø%)ñ
à˜‘:ð
ð  ™+ð
ð "?ð	
ð
   $Ñ&ð
ð ˜D‘jð
ð ˜d™
ð
ð 
 ó
ð8 *.Ø#'Ø#'Ø%)Ø38Ø=Bñ
àð
ð Ð'Ñ(ð
ð !ð	
ð
 ˜‘:ð
ð  ™+ð
ð "?ð
ð /ð
ð   $Ñ&ð
ð �D‰z˜DÑ ð
ð ˜D‘jð
ð ˜d™
ð
ð &*¨D¡[ð
ð 04°d©{ð
ð 
ˆs�DÐ)Ñ*¨DÐ0Ñ	1ó
ð> ðÀDð ÈTò ó ðð
 ðØ ðà	˜Ñ	òó ñrH   r{   )DÚ__doc__r¤   rf   ÚreÚcollections.abcr   r   r   Útypingr   r   r   r	   Úurllib.parser
   Úlitellm._loggingr   Ú"litellm.integrations.custom_loggerr   Ú-litellm.integrations.custom_prompt_managementr   Ú+litellm.integrations.prompt_management_baser   Ú8litellm.litellm_core_utils.prompt_templates.common_utilsr   Ú7litellm.types.integrations.anthropic_cache_control_hookr   r   r   r   Úlitellm.types.llms.anthropicr   r   Úlitellm.types.llms.openair   r   r   r   r   r   Ú"litellm.types.prompts.init_promptsr   Úlitellm.types.utilsr   rZ  r   rc  r!   Ú__annotations__r$   r'   Úcompiler(   Ú	frozensetr1   r2   r5   ra  rh   rZ   rG   r=   r`  rm   rt   rw   ry   r{   rb   rH   rF   ú<module>rv     sc  ðò	ó Û 	Û 	ß 7Ñ 7ß 2Ó 2Ý !å +Ý ;Ý PÝ Nõ÷ó ÷÷÷ õ :Ý =áÞWàÐð
 #$Ð ˜%Ó #àKÐ �uÓ KØ8>Ð .°Ó >Ø(˜bŸj™jÐ)BÓCÐ �eÓ CÙ4=Údó5Ð *¨Eó ð *€�Ó )Ø"HÐ ˜%Ó Hà,Ð/FÑFÐ ðE°3ð E¸4ó EðJ°3ð J¸4À$¹;ó Jð
b ð 
b¨Dó 
bðh Vð h°ó hðg¨Fð g°tó gð )XÐ  Ó Wô`Ð 6õ `rH   