
    i>                       d dl Z 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
mZ 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mZ d dlmZ d dlmZmZ d dlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: d d	l;m<Z<m=Z= d d
l>m?Z?m@Z@ d dl>mAZB d dl>mCZCmDZD d dlEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZN ddlOmPZPmQZQmRZR er	d dlSmTZU eUZVneZV G d deQe      ZWdeXdeYfdZZy)    N)TYPE_CHECKINGAnyDictListOptionalTupleUnioncast)"ANTHROPIC_WEB_SEARCH_TOOL_MAX_USES!DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS-DEFAULT_REASONING_EFFORT_HIGH_THINKING_BUDGET,DEFAULT_REASONING_EFFORT_LOW_THINKING_BUDGET/DEFAULT_REASONING_EFFORT_MEDIUM_THINKING_BUDGET0DEFAULT_REASONING_EFFORT_MINIMAL_THINKING_BUDGETRESPONSE_FORMAT_TOOL_NAME)map_finish_reasontype_to_response_format_param)
BaseConfigBaseLLMException)ANTHROPIC_BETA_HEADER_VALUESANTHROPIC_HOSTED_TOOLSAllAnthropicMessageValuesAllAnthropicToolsValuesAnthropicCodeExecutionToolAnthropicComputerToolAnthropicHostedToolsAnthropicInputSchemaAnthropicMcpServerToolAnthropicMessagesToolAnthropicMessagesToolChoiceAnthropicOutputSchemaAnthropicSystemMessageContentAnthropicThinkingParamAnthropicWebSearchToolAnthropicWebSearchUserLocation)REASONING_EFFORTAllMessageValuesChatCompletionCachedContent#ChatCompletionRedactedThinkingBlockChatCompletionSystemMessageChatCompletionThinkingBlockChatCompletionToolCallChunk#ChatCompletionToolCallFunctionChunkChatCompletionToolParam OpenAIChatCompletionFinishReasonOpenAIMcpServerToolOpenAIWebSearchOptions)OutputCodeInterpreterCall"build_code_interpreter_log_outputs)CacheCreationTokenDetailsCompletionTokensDetailsWrapper)Message)PromptTokensDetailsWrapperServerToolUse)	ModelResponseUsageadd_dummy_tool)any_assistant_message_has_thinking_blocksget_max_tokenshas_tool_call_blocks5last_assistant_with_tool_calls_has_no_thinking_blockssupports_reasoningtoken_counter   )AnthropicErrorAnthropicModelInfoprocess_anthropic_headers)Loggingc                       e Zd ZU dZdZee   ed<   dZee	   ed<   dZ
ee   ed<   dZee   ed<   dZee   ed<   dZee   ed<   dZee   ed	<   	 	 	 	 	 	 	 dedee   dee	   dee   dee   dee   dee   d	ee   d
dfdZed
ee   fd       Zedddee   f fd       Zedfdee   d
efd       Zedeeef   ded
efd       Zeded
efd       ZdefdZedeeef   d
eeef   fd       Zde eedf   d
ee   fdZ!d
efdZ"dee   dee   d
ee#   fdZ$de%d
e&ee'   ee(   f   fdZ)de*d
e(fd Z+d!e,d
e&e,e'   e,e(   f   fd"Z-d!ee,   d
efd#Z.d!e,d
e&e,e,f   fd$Z/d%e,d&e,d
e,fd'Z0d(ee ee,e   f      d
ee,e      fd)Z1ed*ee e2ef      ded
ee3   fd+       Z4d,ee   d
ee   fd-Z5d,ee   d
ee6   fd.Z7d,ee   d/ed0ed
ee8   fd1Z9d,e:d
e;fd2Z<ed3e e,eeef      eeef   f   d
eeeef      fd4       Z=d5ed/eded6ed
ef
d7Z>	 dfd8ee   d
e8fd9Z?d:e,e@   d
e,eA   fd;ZBd:e,eC   d!e,e e'ef      d
e,e e'ef      fd<ZDd=ed>ed
dfd?ZEd=ed3eFd
dfd@ZGd=ed/ed
efdAZHded:e,e@   d/edBed=ed
efdCZIdDee   dEe,e   d
eeJ   fdFZKdGed
e&eee,e      ee,e eLeMf         ee   e,e   ee,e      ee,e      ee,e      f   fdHZN	 	 dgdIedJee   dGee   dKee   d
eOf
dLZPdEe,e   d
eeef   fdMZQdNe,e   dOeeef   dPee   d
e,eR   fdQZSdGedRee,e      dSee,e eLeMf         dTee,e      dNee,e      dUee,e      dEe,e   d
eeef   fdVZT	 	 	 dhdGedWeUj                  dXeWdDee   dYee   dKee   fdZZXd:e,e@   d
ee   fd[ZY	 	 dgdedWeUj                  dXeWd\eZd]ed:e,e@   d/edBed^ed_ee   dDee   d
eWfd`Z[edEe,e   d
eeJ   fda       Z\dbedced=e eeUj                  f   d
e^fddZ_ xZ`S )iAnthropicConfigz
    Reference: https://docs.anthropic.com/claude/reference/messages_post

    to pass metadata to anthropic, it's {"user_id": "any-relevant-information"}
    N
max_tokensstop_sequencestemperaturetop_ptop_kmetadatasystemreturnc                     t               j                         }|j                         D ]%  \  }	}
|	dk7  s|
t        | j                  |	|
       ' y )Nself)localscopyitemssetattr	__class__)rS   rJ   rK   rL   rM   rN   rO   rP   locals_keyvalues              {/Users/manta/Documents/Projects/TheRoad-I1/.venv/lib/python3.12/site-packages/litellm/llms/anthropic/chat/transformation.py__init__zAnthropicConfig.__init__g   sA     (--/!--/JCf}!2U3 *    c                      y)N	anthropic rS   s    r\   custom_llm_providerz#AnthropicConfig.custom_llm_providerv   s    r^   modelre   c                n    t         |          }|j                  d      | j                  |      |d<   |S )NrJ   )super
get_configgetget_max_tokens_for_model)clsre   configrX   s      r\   rh   zAnthropicConfig.get_configz   s;    #% ::l#+#&#?#?#FF< r^   c                 h    | t         S 	 t        |       }|t         S |S # t        $ r	 t         cY S w xY w)z
        Get the max output tokens for a given model.
        Falls back to DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS (configurable via env var) if model is not found.
        )r   r>   	Exception)re   rJ   s     r\   rj   z(AnthropicConfig.get_max_tokens_for_model   sE     =44	5'.J!88 	544	5s     11anthropic_tool_contentindexc                     t        | d   dt        | d   t        j                  | d               |      }d| v r#t	        t
        t        t        f   | d         |d<   |S )a  
        Convert Anthropic tool_use format to OpenAI ChatCompletionToolCallChunk format.

        Args:
            anthropic_tool_content: Anthropic tool_use content block with format:
                {"type": "tool_use", "id": "...", "name": "...", "input": {...}}
            index: The index of this tool call

        Returns:
            ChatCompletionToolCallChunk in OpenAI format
        idfunctionnameinput)rt   	arguments)rr   typers   rp   caller)r-   r.   jsondumpsr
   r   strr   )ro   rp   	tool_calls      r\   !convert_tool_use_to_openai_formatz1AnthropicConfig.convert_tool_use_to_openai_format   sp      0%d+8+F3**%;G%DE 
	 --"&tCH~7Mh7W"XIhr^   c                 L    | j                         t        fddD              S )z3Check if the model is specifically Claude Opus 4.6.c              3   &   K   | ]  }|v  
 y wNra   ).0vmodel_lowers     r\   	<genexpr>z5AnthropicConfig._is_opus_4_6_model.<locals>.<genexpr>   s      
&VA&V   )opus-4-6opus_4_6opus-4.6zopus_4.6)lowerany)re   r   s    @r\   _is_opus_4_6_modelz"AnthropicConfig._is_opus_4_6_model   s*     kkm 
&V
 
 	
r^   c                     g d}d|v s,t         j                  |      st        || j                        r"|j	                  d       |j	                  d       |S )N)streamstoprL   rM   rJ   max_completion_tokenstoolstool_choiceextra_headersparallel_tool_callsresponse_formatuserweb_search_optionsspeedcontext_managementcache_controlzclaude-3-7-sonnet)re   rc   thinkingreasoning_effort)rI   _is_claude_4_6_modelrA   rc   append)rS   re   paramss      r\   get_supported_openai_paramsz+AnthropicConfig.get_supported_openai_params   sU    
(  5(33E:!$($<$<
 MM*%MM,-r^   schemac           	         t        | t              s| S h d}g }dddddddd	d
}|D ]-  }|| v s|j                  ||   j                  | |                / i }|r<| j	                  dd      }ddj                  |      z   dz   }|r|dz   |z   |d<   n||d<   | j                         D ]  \  }}	||v r|dk(  rd|v r|dk(  rKt        |	t              r;|	j                         D 
ci c]  \  }
}|
t        j                  |       c}}
||<   f|dk(  r)t        |	t              rt        j                  |	      ||<   |dk(  rKt        |	t              r;|	j                         D 
ci c]  \  }
}|
t        j                  |       c}}
||<   |dk(  r8t        |	t              r(|	D cg c]  }t        j                  |       c}||<   !|dk(  r8t        |	t              r(|	D cg c]  }t        j                  |       c}||<   ^|dk(  r8t        |	t              r(|	D cg c]  }t        j                  |       c}||<   |	||<    |j	                  d      dk(  r	d|vrd|d<   |S c c}}
w c c}}
w c c}w c c}w c c}w )a  
        Filter out unsupported fields from JSON schema for Anthropic's output_format API.

        Anthropic's output_format doesn't support certain JSON schema properties:
        - maxItems/minItems: Not supported for array types
        - minimum/maximum: Not supported for numeric types
        - minLength/maxLength: Not supported for string types

        This mirrors the transformation done by the Anthropic Python SDK.
        See: https://platform.claude.com/docs/en/build-with-claude/structured-outputs#how-sdk-transformation-works

        The SDK approach:
        1. Remove unsupported constraints from schema
        2. Add constraint info to description (e.g., "Must be at least 100")
        3. Validate responses against original schema
        Args:
            schema: The JSON schema dictionary to filter

        Returns:
            A new dictionary with unsupported fields removed and descriptions updated

        Related issues:
        - https://github.com/BerriAI/litellm/issues/19444
        >   maximumminimummaxItemsminItems	maxLength	minLengthexclusiveMaximumexclusiveMinimumzminimum number of items: {}zmaximum number of items: {}zminimum value: {}zmaximum value: {}zexclusive minimum value: {}zexclusive maximum value: {}zminimum length: {}zmaximum length: {})r   r   r   r   r   r   r   r   description zNote: , . 
propertiesrV   $defsanyOfallOfoneOfrw   objectadditionalPropertiesF)

isinstancedictr   formatri   joinrV   rI   filter_anthropic_output_schemalist)r   unsupported_fieldsconstraint_descriptionsconstraint_labelsfieldresultexisting_descconstraint_noterZ   r[   kr   items                r\   r   z.AnthropicConfig.filter_anthropic_output_schema   s   4 &$'M	
 )+55** = =--	
 (E'..%e,33F5MB ( "$ #"JJ}b9M&3J)KKcQO(5(;o(M}%(7}% ,,.JC((m#(?l"z%'> !& -1 EEaHH -s Jud$;-LLUSsJud$; !& -1 EEaHH -s Jud$; !& % $BB4H %s Jud$; !& % $BB4H %s Jud$; !& % $BB4H %s
 $sG )N ::f).DF.R-2F)*E


s   $ I(" I.#I4 I9I>r   c                     t        |d      S )Nz/$defs/{model})ref_templater   )rS   r   s     r\   $get_json_schema_from_pydantic_objectz4AnthropicConfig.get_json_schema_from_pydantic_objectM  s     -*:
 	
r^   c                 
    ddiS )Nzanthropic-versionz
2023-06-01ra   rb   s    r\   get_cache_control_headersz)AnthropicConfig.get_cache_control_headersT  s    
  
 	
r^   r   parallel_tool_usec                    d }|dk(  rt        d      }n|dk(  rt        d      }n|dk(  rt        d      }nt        |t              rd|v rPd|vrL|j                  d      }|dk(  rt        d      }n]|dk(  s|dk(  rt        d      }nF|dk(  rAt        d      }n4|j                  di       j                  d      }|t        d	      }||d<   | |dk(  r	 |S || |d
<   |S t        d|       }|S )Nautorw   requiredr   nonerw   rs   rt   tooldisable_parallel_tool_use)rw   r   )r!   r   r   ri   )rS   r   r   _tool_choice	tool_type
_tool_names         r\   _map_tool_choicez AnthropicConfig._map_tool_choice\  s4    ?C& 6L J&6EBLF"6FCLT*$;)F'OOF3	&#>F#KL*,	U0B#>E#JL&(#>F#KL(__Z<@@H
)#>F#KL+5L(( f$  )@Q<Q89 	  ;2C.C  r^   r   c                 L   d }d }d   dk(  s	d   dk(  rd   j                  ddi d      }|j                  d      dk7  r[t        j                  j                  d|j                  d      d   j                  d             t	        |      }d|d<   d	|vri |d	<   t        t        j                  j                               }|j                         D ci c]  \  }}||v s|| }}}t        d-i |}	t        d   d   |	d
      }
d   j                  d      }|||
d<   |
}nd   j                  d      rdd   vrt        d      d   d   j                  d      }d   d   j                  d      }||t        d      t        d   d   j                  dd      ||      }d   d   j                  d      }|||d<   |}npt        fdt        D              rj                  dj                  di       j                  d            }|t!        |t"              st        d      |}i }j                         D ]  \  }}|dk7  s|dk7  s|||<    t%        d-d   |d|}nˉd   dk(  rt'        d-i }nd   dk(  r | j)                  t+        t,                    }nd   dk(  r@ddlm} j                  dd      }t!        |t"              st        d      |} |d|      }nGd   dk(  r?ddlm} j                  dd       }t!        |t"              st        d      |} |d|      }||t        d!d          j                  d"d       }j                  di       j                  d"d       }|>|j                  dd#      }|d$vr(|||d"<   n |t!        |t              rt5        d-i ||d"<   j                  d%d       }j                  di       j                  d%d       }|[|j                  dd#      }|d&vrE|!t!        |t6              st        d'      ||d%<   n"| t!        |t6              st        d'      ||d%<   j                  d(d       }j                  di       j                  d(d       }||j                  dd#      }|d&vri|3t!        |t8              rt;        d) |D              st        d*      ||d(<   n4|2t!        |t8              rt;        d+ |D              st        d*      ||d(<   j                  d,d       }j                  di       j                  d,d       }|R|j                  dd#      }|dk(  s	|d#k(  r6d|v r2|t!        |t8              r	||d,<   ||fS |t!        |t8              r||d,<   ||fS c c}}w ).Nrw   rs   custom
parametersr   )rw   r   zg_map_tool_helper: coercing input_schema type from %r to 'object' for Anthropic compatibility (tool: %s)rt   r   )rt   input_schemarw   r   	computer_z&Missing required parameter: parametersdisplay_width_pxdisplay_height_pxzAMissing required parameter: display_width_px or display_height_pxcomputer)rw   rt   r   r   display_numberc              3   F   K   | ]  }d    j                  |        yw)rw   N)
startswith)r   tr   s     r\   r   z3AnthropicConfig._map_tool_helper.<locals>.<genexpr>  s#     L5Kf((+5Ks   !z Missing required parameter: namerw   rt   urlmcptool_search_tool_regex_20251119r   )AnthropicToolSearchToolRegextool_search_tool_regexz'Tool search tool must have a valid nametool_search_tool_bm25_20251119)AnthropicToolSearchToolBM25tool_search_tool_bm25zUnsupported tool type: r   r   r   r   defer_loading)r   r   computer_20241022computer_20250124zdefer_loading must be a booleanallowed_callersc              3   <   K   | ]  }t        |t                y wr   r   r{   r   r   s     r\   r   z3AnthropicConfig._map_tool_helper.<locals>.<genexpr>9  s      I:J$
4-:J   z)allowed_callers must be a list of stringsc              3   <   K   | ]  }t        |t                y wr   r   r   s     r\   r   z3AnthropicConfig._map_tool_helper.<locals>.<genexpr>?  s      R:S$
4-:Sr   input_examplesra   )ri   litellmverbose_loggerdebugr   setr   __annotations__keysrV   r    r   
ValueErrorr   r   r   r   r{   r   r   _map_openai_mcp_server_toolr
   r1   litellm.types.llms.anthropicr   r   r)   boolr   all) rS   r   returned_tool
mcp_server_input_schema_allowed_propertiesr   r   input_schema_filteredinput_anthropic_schema_tool_description_display_width_px_display_height_px_computer_tool_display_numberfunction_name_objfunction_nameadditional_tool_paramsr   tool_name_obj	tool_namer   _cache_control_cache_control_functionr   _defer_loading_defer_loading_function_allowed_callers_allowed_callers_function_input_examples_input_examples_functions     `                              r\   _map_tool_helperz AnthropicConfig._map_tool_helper  s    <@7;
<:%f)A"&z"2"6"6$"$#M   (H4&&,,F!%%f-$((0	 !%] 3(0f%}424M,/"%&:&J&J&O&O&Q"R!.!4!4!6%!6A!?R:R1!6 " % <P <'<" **%f-3E  
+//>L''3m$!M&\$$[14
#33 !IJJ/3J/?/M/Q/Q"0 15Z0@0N0R0R#1 !(,>,F W  3&\*%))&*=!2"4	N #:.|<@@AQRO*3B/0*ML5KLL $*b1I1M1Mf1U V (
;Lc0R !CDD-M%'"

1;1;01*1- % 1 &\9OM &\U"/7$7J&\U"99($/J &\>>Q HHV-EFMmS1 !JKK%I86M &\==P HHV-DEMmS1 !JKK%I75M  Z%76tF|nEFF /48"&((:r":">">PT"U$%))&"5I !  "-5CM/2,8Z+T> 6Q 616M/2
 /48"&((:r":">">PT"U$%))&"5I !  "-%nd;()JKK5CM/2,8%&=tD()JKK5LM/2  88$5t<$(HHZ$<$@$@t%
! $%))&"5I !  $/%&6=S I:JI F ))TUU7GM"34.:%&?Fc R:SR O ))TUU7PM"34 ((#3T:#'88J#;#?#?@PRV#W $%))&"5IH$bV}=T".:ot3T6EM"23 j(( .9j,d? 7OM"23j((_%s   V %V c                 ,   ddl m} |j                  dd       }d }| ||j                  dd             }|j                  di       }d }|&|j                  dd       }||j                  dd      }t	        d	|d
   |d         }|||d<   |||d<   |S )Nr   )#AnthropicMcpServerToolConfigurationallowed_tools)r  headersAuthorizationzBearer r   r   
server_urlserver_label)rw   r   rt   tool_configurationauthorization_token)r   r  ri   replacer   )	rS   r   r  r  r"  r  r#  bearer_tokeninitial_tools	            r\   r   z+AnthropicConfig._map_openai_mcp_server_toolU  s     	U$7LP$!D"hh=" ((9b)-1";;=L'&2&:&:9b&I#-\"n%
 )1CL-.*2EL./r^   r   c                     g }g }|D ]S  }d|v r|j                  |       | j                  |      \  }}||j                  |       |C|j                  |       U ||fS )Nr   )r   r  )rS   r   anthropic_toolsmcp_serversr   new_toolmcp_server_tools          r\   
_map_toolszAnthropicConfig._map_toolst  sx     D%&&t,,0,A,A$,G)/'#**84".&&7  ++r^   c                 H    |sy|D ]  }|j                  dd      }|dv s y y)z9Check if tool search tools are present in the tools list.Frw   r   r   T)ri   )rS   r   r   r   s       r\   _detect_tool_search_toolsz)AnthropicConfig._detect_tool_search_tools  s9    D,I     r^   c                     g }g }|D ]7  }|j                  dd      r|j                  |       '|j                  |       9 ||fS )z
        Separate tools into deferred and non-deferred lists.

        Returns:
            Tuple of (non_deferred_tools, deferred_tools)
        r   F)ri   r   )rS   r   non_deferreddeferredr   s        r\   _separate_deferred_toolsz(AnthropicConfig._separate_deferred_tools  sM     Dxx/%##D)	  X%%r^   contentdeferred_toolsc                    |s|S i }|D ]>  }|j                  d      xs! |j                  di       j                  d      }|s:|||<   @ g }|D ]u  }t        |t              rR|j                  d      dk(  r>|j                  d      }|r||v r|j                  ||          S|j                  |       e|j                  |       w |S )a7  
        Expand tool_reference blocks to full tool definitions.

        When Anthropic's tool search returns results, it includes tool_reference blocks
        that reference tools by name. This method expands those references to full
        tool definitions from the deferred_tools catalog.

        Args:
            content: Response content that may contain tool_reference blocks
            deferred_tools: List of deferred tools that can be referenced

        Returns:
            Content with tool_reference blocks expanded to full tool definitions
        rt   rs   rw   tool_referencer  )ri   r   r   r   )rS   r3  r4  tool_mapr   r  expanded_contentr   s           r\   _expand_tool_referencesz'AnthropicConfig._expand_tool_references  s    & N "D(PDHHZ,D,H,H,PI&*# # D$%$((6*:>N*N HH[1	h!6$++HY,?@ %++D1 ''-   r^   r   c                 6   d }t        |t              r)|j                         rt        j                  du r|S |g}|S t        |t
              rMg }|D ]6  }|j                         rt        j                  du r&|j                  |       8 t        |      dkD  r|}|S )NTr   )r   r{   isspacer   drop_paramsr   r   len)rS   r   new_stopnew_vr   s        r\   _map_stop_sequencesz#AnthropicConfig._map_stop_sequences  s     )-dC 7#6#6$#>vH  d#EIIKG$7$74$?Q  5zA~ r^   r   c                     | | dk(  ry t         j                  |      rt        d      S | dk(  rt        dt              S | dk(  rt        dt              S | dk(  rt        dt
              S | d	k(  rt        dt              S t        d
|        )Nr   adaptiver   lowenabled)rw   budget_tokensmediumhighminimalzUnmapped reasoning effort: )rI   r   r$   r   r   r   r   r   r   re   s     r\   _map_reasoning_effortz%AnthropicConfig._map_reasoning_effort  s    
 #'76'A//6)  &)J  ))M  ')K  *)N 
 :;K:LMNNr^   r[   c                 >    |y d }d|v r|d   }|S d|v r|d   d   }|S )Nresponse_schemajson_schemar   ra   )rS   r[   rM  s      r\   )_extract_json_schema_from_response_formatz9AnthropicConfig._extract_json_schema_from_response_format
  sK     =&*% 12K  e#.x8Kr^   c                     | j                  |      }|y dd l}ddlm} |j	                  |      }|j                  d|j                  di             }|r	 |||       | j                  |      }t        d|      S )Nr   )unpack_defsr   definitionsrM  )rw   r   )rN  rU   8litellm.litellm_core_utils.prompt_templates.common_utilsrP  deepcopypopr   r"   )rS   r[   rM  rU   rP  defsfiltered_schemas          r\   .map_response_format_to_anthropic_output_formatz>AnthropicConfig.map_response_format_to_anthropic_output_format  s     '+&T&T'
  		
 mmK0wr(JKT* ==kJ$"
 	
r^   optional_paramsis_thinking_enabledc                 n    dg}||d   |v ry | j                  |      }|y 	 | j                  |      }|S )Ntextrw   )rM  )rN  *_create_json_tool_call_for_response_format)rS   r[   rX  rY  ignore_response_format_typesrM  r  s          r\   %map_response_format_to_anthropic_toolz5AnthropicConfig.map_response_format_to_anthropic_tool5  se     )/x$MU6].JJ&*&T&T'
 	 ??# @ 
 r^   c                 x   t        t        |      }t        dd      }|j                  d      }|jt	        d      }t        j
                  j                         }|j                  d      }|-|j                         D ]  \  }}	||v s|dk7  s|	||<    ||d<   |j                  d      }
|
t        |
   |d	<   |S )
Nweb_search_20250305
web_searchr   user_locationapproximater   rw   search_context_sizemax_uses)	r
   r2   r%   ri   r&   r   r   rV   r   )rS   r[   value_typedhosted_web_search_toolrb  anthropic_user_locationanthropic_user_location_keysuser_location_approximaterZ   user_location_valuerd  s              r\   map_web_search_toolz#AnthropicConfig.map_web_search_toolP  s     159!7&"
 $8$&D-&X#.>>CCE ) )6(9(9-(H%(40I0O0O0Q,C,::sf}7J/4 1R ;R&7 *oo.CD*1S#2":. &%r^   r   c                    t        | t              rd| v r| S t        | t              rg }| D ]  }t        |t              s|j                  d      }|dk(  s+ddi}|j                  d      }|'t        |t        t
        f      rdt	        |      d|d	<   |D ]  }|d
vs||   ||<    |j                  |        |rd|iS y)a  
        OpenAI format: [{"type": "compaction", "compact_threshold": 200000}]
        Anthropic format: {
            "edits": [
                {
                    "type": "compact_20260112",
                    "trigger": {"type": "input_tokens", "value": 150000}
                }
            ]
        }

        Args:
            context_management: OpenAI or Anthropic context_management parameter

        Returns:
            Anthropic-formatted context_management dict, or None if invalid
        editsrw   
compactioncompact_20260112compact_thresholdNinput_tokens)rw   r[   trigger>   rw   rq  )r   r   r   ri   intfloatr   )r   anthropic_editsentry
entry_typeanthropic_editrq  r   s          r\   *map_openai_context_management_to_anthropicz:AnthropicConfig.map_openai_context_management_to_anthropico  s    , ($/G?Q4Q%% ($/ O+!%."YYv.
-6<>P5QN(-		2E(F%(4)C<: %3%():%;5y1
 # %  16aN1- # $**>:1 ,4 11r^   non_default_paramsr<  c           	         | j                  |      }|j                         D ]G  \  }}|dk(  r4t        |t              r|nt	        dt        t        |                  |d<   @|dk(  r4t        |t              r|nt	        dt        t        |                  |d<   y|dk(  r0| j                  |      \  }}	| j                  ||      }|	s|	|d<   |dk(  s|d	k(  r:| j                  |j                  d      |j                  d	      
      }
|
|
|d<   |dk(  r|du r||d<   |dk(  r<t        |t              st        |t              r| j                  |      }|<||d<   C|dk(  r||d<   O|dk(  r||d<   [|dk(  rt        |t              rot        fddD              r| j                  |      }|A||d<   n;| j!                  |||      }||st"        dd}
|
|d<   | j                  ||g      }d|d<   |dk(  r&|$t        |t              rt%        |      r	d|i|d<   
|dk(  r||d<   |dk(  rdt        |t              rTt&        j)                  |      |d<   t&        j+                        s\dddd d!d"}|j                  ||      }d#|i|d$<   |d%k(  rEt        |t              r5| j-                  t/        t0        |            }| j                  ||g       |d&k(  r||d&<   |d'k(  r4t        |t        t        f      s| j3                  |      }|||d'<   |d(k(  rt        |t              r||d(<   *|d)k(  s1t        |t              sC||d)<   J | j5                  ||*       |S )+N)r{  rJ      r   r   )rX  r   r)  r   r   )r   r   r   Tr   rK   rL   rM   r   c              3   &   K   | ]  }|v  
 y wr   ra   )r   	substringre   s     r\   r   z4AnthropicConfig.map_openai_params.<locals>.<genexpr>  s"      &	 &&r   >   opus-4-1opus-4-5opus-4.1opus-4.5
sonnet-4-5
sonnet-4-6
sonnet-4.5
sonnet-4.6
sonnet_4.6
sonnet_4_6r   r   output_formatr   rt   rw   	json_moder   user_idrO   r   r   rI  rC  rF  rG  max)rC  rH  rF  rG  r  effortoutput_configr   r   r   r   r   )r{  rX  )rY  rV   r   rt  r  roundr,  _add_tools_to_optional_paramsr   ri   r{   r   r@  r   r   rW  r^  r   _valid_user_idrI   rJ  r   rl  r
   r2   rz  +update_optional_params_with_thinking_tokens)rS   r{  rX  re   r<  rY  paramr[   r(  r)  r   _value_output_formatr  
effort_mapmapped_effortrg  anthropic_context_managements      `              r\   map_openai_paramsz!AnthropicConfig.map_openai_params  s"    #661 7 
 /446LE5$'s3EQE%L@Q9R  - 11's3EQE%L@Q9R  - '!/3u/E,"&"D"D$3? #E # 5@OM2-'54I+I )) 2 6 6} E&8&<&<=R&S *    +5AOM2("u},1)&5#&*UD*A11%8%8>O$45-'16.'!+0(++
5$0G & $ KKER # &1;I8 FF0CE } .$=$*( :F6&*&H&H(7w 'I 'O 04,%uc*"5)/8%.@
+*$.3
+,,E31G.=.S.S%*% /T /
+
 #77>$#("* &$"J %/NN5%$@M8@-7POO4..:eT3J)-)A)A/7*& 22$3<R;S 3  /)380..edD\2GGN 1 4? 9 (0 '!j&<+0(/)j.E380A 7F 	881? 	9 	
 r^   rM  c                     t        d      }|d|d<   i |d<   n|j                  t        t         |             t        t        |      }|S )a3  
        Handles creating a tool call for getting responses in JSON format.

        Args:
            json_schema (Optional[dict]): The JSON schema the response should be in

        Returns:
            AnthropicMessagesTool: The tool call to send to Anthropic API to get responses in JSON format
        r   r   Tr   r   )rt   r   )r   updater
   r    r   )rS   rM  r  r  s       r\   r\  z:AnthropicConfig._create_json_tool_call_for_response_format>  s]     /C/
  59M01*,M,'  &:K!HI%*
 r^   messagesc                    g }g }t        |      D ].  \  }}|d   dk(  s|j                  |       t        d
i |}t        |d   t              rI|d   sE|d   j                  d      rZt        d|d         }d|v r|d   |d<   |j                  |       t        |d   t              s|d   D ]  }|j                  d      }	|j                  d      dk(  r|	s+|j                  d      dk(  r|	r|	j                  d      rSt        |j                  d      |	      }d|v r|d   |d<   |j                  |        1 t        |      d	kD  r!t        |      D ]  }|j                  |        |S )a  
        Translate system message to anthropic format.

        Removes system message from the original list and returns a new list of anthropic system message content.
        Filters out system messages containing x-anthropic-billing-header metadata.
        rolerP   r3  zx-anthropic-billing-header:r[  )rw   r[  r   rw   r   ra   )	enumerater   r+   r   r{   r   r#   r   ri   r=  reversedrT  )
rS   r  system_prompt_indicesanthropic_system_message_listidxmessagesystem_message_block anthropic_system_message_content_content
text_values
             r\   translate_system_messagez(AnthropicConfig.translate_system_message\  s    !#MO%%h/LCv(*%,,S1'B'MW'M$29=sC/	: +I6AA5 !7T#1)<84 '*>> 1A 9+ 2888  	 2D9$+I$6%-\\&%9
#<</69*$ %LL0F: * * 5 56S T$9%-\\&%9%/ 9 +h6 !) 9 = / 6<<</ %73 0h $%) 56S! 7 -,r^   c                 h   d}|D ]J  }|j                  dd      }|st        |t              s)|D ]  }|j                  dd      }|dk(  sd} J L |r^|D ]=  }|j                  dd      }	|	st        |	t              s)|	j	                  d      s;|c S  |j                  t        dd	             |S )
z:if 'container_upload' in messages, add code_execution toolFr3  Nrw   container_uploadTcode_executioncode_execution_20250522r  )ri   r   r   r{   r   r   r   )
rS   r  r   add_code_execution_toolr  message_contentr3  content_typer   r   s
             r\   r  z'AnthropicConfig.add_code_execution_tool  s     #(G%kk)T:O:ot#D.G#*;;vt#<L#'9926/	  /   # HHVT2	"9c2!,,-=> L  LL*)2 r^   r  
beta_valuec                     |j                  d      }|||d<   y|j                  d      D cg c]  }|j                          }}||vr| d| |d<   yyc c}w )a  
        Ensure a beta header value is present in the anthropic-beta header.
        Merges with existing values instead of overriding them.

        Args:
            headers: Dictionary of headers to update
            beta_value: The beta header value to add
        zanthropic-betaN,r   )ri   splitstrip)rS   r  r  existing_betabetaexisting_valuess         r\   _ensure_beta_headerz#AnthropicConfig._ensure_beta_header  sw      $45 (2G$%4A4G4G4LM4LD4::<4LM_,+8/J<(HG$% - Ns   Ac                    g }t        |t              rd|v r|j                  dg       }nt        |t              r|}nyd}d}|D ]#  }|j                  dd      }|dk(  s|dk(  rd}"d}% |r*| j	                  |t
        j                  j                         |r+| j	                  |t
        j                  j                         yy)	zQ
        Add appropriate beta headers based on context_management edits.
        rn  NFrw   r   rp  ro  T)	r   r   ri   r   r  r   COMPACT_2026_01_12r[   CONTEXT_MANAGEMENT_2025_06_27)rS   r  r   rn  has_compact	has_otheredit	edit_types           r\   &_ensure_context_management_beta_headerz6AnthropicConfig._ensure_context_management_beta_header  s     ($/G?Q4Q&**7B7E*D1&E 	D,I..)|2K" 	  $$5HHNN
 $$,JJPP r^   c                 x   |j                  dd      }|r|S |j                  dg       }|D ]  }|j                  dd      rc|j                  d      j                  t        j                  j                        r+| j                  |t        j                  j                         x|j                  dd      s|j                  d      j                  t        j                  j                        s| j                  |t        j                  j                          |j                  d      | j                  ||d          |j                  d      *| j                  |t        j                  j                         |j                  d      d	k(  r*| j                  |t        j                  j                         |S )
z,Update headers with optional anthropic beta.is_vertex_requestFr   rw   Nr   r  r   fast)ri   r   r   	WEB_FETCHr[   r  r   WEB_FETCH_2025_09_10MEMORYr  r  STRUCTURED_OUTPUT_2025_09_25FAST_MODE_2026_02_01)rS   r  rX  r  _toolsr   s         r\   +update_headers_with_optional_anthropic_betaz;AnthropicConfig.update_headers_with_optional_anthropic_beta  s    ,//0CUKN $$Wb1Dxx%$((6*:*E*E&0066+ ((9NNTT &$'DHHV,<,G,G&--33- ((0NNTT  34@77)=> /;$$5RRXX w'61$$5JJPP r^   litellm_paramsc           	         	 ddl m} d|vrW|Ut        |      rJt        j                  r"| j                  t        d            \  |d<   }nt        j                  ddd	      |j                  d
      Y|Wt        |      rLt        |      sAt        j                  r1|j                  d
d       t        j                  j                  d       | j                  ||      }| j                  |      }t!        |      dkD  r||d<   	  |||| j"                  xs d      }	t-        t.        t0        t2        t4        t6        f         |j                  d            xs g }| j9                  |	|      }t!        |      dkD  r||d<   t        j:                  j=                  |      }|j?                         D ]  \  }}||vs|||<    |j                  dd      }|r1tA        |tB              r!d|v r|d   tE        |d         r
d|d   i|d<   |j                  dd       ||	d|}d|v rr|j                  d      }|r_tA        |tB              rO|j                  d      }|r|dvrtG        d| d      |dk(  r| jI                  |      stG        d |       ||d<   |S # t$        $ r+}
t'        ddj)                  t+        |
      |            d}
~
ww xY w)!z9
        Translate messages to anthropic format.
        r   )anthropic_messages_ptr   Nr`   )rc   zAnthropic doesn't support tool calling without `tools=` param specified. Pass `tools=` param OR set `litellm.modify_params = True` // `litellm_settings::modify_params: True` to add dummy tool to the request.r   )r  re   llm_providerr   zDropping 'thinking' param because the last assistant message with tool_calls has no thinking_blocks. The model won't use extended thinking for this turn.)r  rX  r  rP   )re   r  r  i  z{}
Received Messages={})status_coder  )r  r   r}  rd   rO   r  r  )re   r  r  r  )rG  rF  rC  r  zInvalid effort value: z0. Must be one of: 'high', 'medium', 'low', 'max'r  z>effort='max' is only supported by Claude Opus 4.6. Got model: )%3litellm.litellm_core_utils.prompt_templates.factoryr  r?   r   modify_paramsr,  r<   UnsupportedParamsErrorri   r@   r=   rT  r   warningr  r  r=  rc   rn   rD   r   r{   r
   r   r   r	   r   r   r  rI   rh   rV   r   r   r  r   r   )rS   re   r  rX  r  r  r  _r  anthropic_messageser  r   rl   r   r   _litellm_metadatadatar  r  s                       r\   transform_requestz!AnthropicConfig.transform_request$  s?   		

 ?*$$X.$$.2oo"{C/+(! 44 n!,  
+7$EhO=hG$$##J5&&..c
 BB_ C 

 )-(E(Ex(E(X%,-1(EOH%
	!6!!55D" e$;T$ABCD##G,   	 ,,6HPV,Wu:>',OG$ ((33%3@LLNDAq(%&"	 # +..z4@,d3..!),80;<+46G	6R*SOJ' 	/6 *
 
 o-+//@MM4!@&**84f,LL$08hi  U?4+B+B5+I$XY^X_`  )6_%{  	 299#a&(K 	s   J 	K$&K

Kr  
tool_callsc                     d }|du r[t        |      dk(  rMd }d|d   d   v r)|d   d   d   t        k(  r|d   d   j                  d      }|t        j	                  |      }|S )NTr}  rt   r   rs   rv   )r  )r=  r   ri   rI   !_convert_tool_response_to_message)rS   r  r  _messagejson_mode_content_strs        r\   !_transform_response_for_json_modez1AnthropicConfig._transform_response_for_json_mode  s    
 .2ZA!537!*Q-
33qM*-f59RR(21j(A(E(Ek(R%$0*LL) M  r^   completion_responsec                    d}d }d }d }g }d }d }d }	t        |d         D ]  \  }
}|d   dk(  r
||d   z  }n)|d   dk(  s|d   dk(  r)t        j                  ||
      }|j                  |       n|d   j	                  d      r[|d   d	k(  ro|d   d
k(  r|g }|j                  |       n|d   dk(  r|g }|j                  |       n|g }|j                  |       n|j                  d      dk(  r$|g }|j                  t        t        |             nI|d   dk(  r$|g }|j                  t        t        |             n|d   dk(  r|	g }	|	j                  |       |j                  d      U|g }|j                  |d   D cg c]  }i |d|j                  dd      i c}        |7d}|D ]0  }t        t        t           |j                  d            }|,||z  }2 ||||||||	fS c c}w )Nr   r3  rw   r[  tool_useserver_tool_use)ro   rp   _tool_resulttool_search_tool_resultweb_search_tool_resultweb_fetch_tool_resultr   redacted_thinkingro  	citationssupported_text)r  rI   r}   r   endswithri   r
   r,   r*   r   r{   )rS   r  text_contentr  thinking_blocksreasoning_contentr  web_search_resultstool_resultscompaction_blocksr  r3  r|   citationblockthinking_contents                   r\   extract_response_contentz(AnthropicConfig.extract_response_content  s     )-	
 	 	
 ,08:
26,015%&9)&DELCv&(/J.'&/EV2V+MM+2 N 	 !!), )).96?&??6?&>>)1-/*&--g6V_(??)1-/*&--g6 $+') ''0V$
2"*&(O&&t,G'QR$77"*&(O&&<gF
 L0$,(*%!((1 {{;'3$ "I   )0(<
 )=H	&,gkk&".E )=i Fz & "(#'uyy7L#M #/%)99% ) 	
 		
s   
G6
usage_objectr  r   c                 v   |j                  dd      xs d}|j                  dd      xs d}|}d}d}	d }
d }d }d }d|v r
|d   |d   }d|v r|d   
|d   }||z  }d|v r|d   
|d   }	||	z  }d|v rO|d   Jd|d   v r|d   d   t        t        |d   d         }d	|d   v r|d   d	   t        t        |d   d	         }|S|Qd}|j                  d
g       D ]3  }|j                  d      dk(  s|j                  dd      }d|v s/|dz  }5 |dkD  r|}d|v r6|d   1t        |d   j                  d      |d   j                  d            }
t	        |	||
      }|rt        |d      nd}t        |dkD  r|nd|dkD  r||z
  n|      }||z   }t        ||||||	|||t        ||      nd ||
      }|S )Nrr  r   output_tokensinference_geocache_creation_input_tokenscache_read_input_tokensr  web_search_requeststool_search_requestsr3  rw   rt   r   tool_searchr}  cache_creationephemeral_5m_input_tokensephemeral_1h_input_tokens)r  r  )cached_tokenscache_creation_tokenscache_creation_token_detailsT)r[  count_response_tokens)reasoning_tokenstext_tokens)r   r  )
prompt_tokenscompletion_tokenstotal_tokensprompt_tokens_detailsr  r  completion_tokens_detailsr  r  r   )	ri   r
   rt  r5   r8   rB   r6   r;   r9   )rS   r  r  r  r   r  r  _usager  r  r  r   r  r  tool_search_countr3  r  r  r
  completion_token_detailsr  usages                         r\   calculate_usagezAnthropicConfig.calculate_usage)  s    %((;@q(,,_a@EA+,#'(LP$-1.2'+f$)@)L"?3M *V345A*01N*O'88M%/01=&,-F&G#44M&62C+D+P%0A)BB,-.CDP&* 123HI'# '&1B*CC,-.DEQ'+ 123IJ($  ',?,K !.229bA;;v&*;; 'FB 7I$	1)Q.)	 B
 !1$'8$v%&1A*B*N+D*01A*B*F*F/+ +11A*B*F*F/+	,( !;1"=)E!
 ! 0M 	
 $B1AA1E-1 $a' "$44&$
  %'88'/%"7(C$;&> (37K7W	 (;)=
 '#
& r^   c                 6   i }|D ]  }	 t        j                  |j                  di       j                  dd            }|j                  d      }|j                  dd      }t        |t              rt        |t              r|nd||<    |S # t
        $ r Y w xY w)Nrs   rv   z{}rr   commandr   )ry   loadsri   r   r{   rn   )rS   r  
code_by_idtcargscall_idr  s          r\   _build_code_by_id_mapz%AnthropicConfig._build_code_by_id_map  s     &(
Bzz"&&R"8"<"<[$"OP&&,((9b1gs+5?5M'SUJw'    s   A?B	BBr  r  container_idc                     g }|D ]v  }|j                  d      dk7  r|j                  dd      }|j                  di       }t        |      }|j                  t        d||j                  |d      |d|             x |S )	Nrw   bash_code_execution_tool_resulttool_use_idr   r3  code_interpreter_call	completed)rw   rr   coder  statusoutputs)ri   r4   r   r3   )	rS   r  r  r  code_interpreter_resultstrr  r3  log_outputss	            r\   _build_code_interpreter_resultsz/AnthropicConfig._build_code_interpreter_results  s     $& Bvvf~!BBff]B/GffY+G<WEK$++)0#4!-&'	   ('r^   r  r  r  r  c                 p   ||d}|j                  d      }	|	|	|d<   |||d<   |p||d<   t        |j                  d      t              r!|j                  di       j                  d      nd }
| j                  |      }| j	                  |||
      }||d<   |j                  d      }|||d<   |||d<   |S )	N)r  r  r   r  r  	containerrr   r'  r  )ri   r   r   r  r*  )rS   r  r  r  r  r  r  r  provider_specific_fieldsr   r  r  r'  r,  s                 r\   _build_provider_specific_fieldsz/AnthropicConfig._build_provider_specific_fields  s    #.4
 
 1445IJ)=O$%9:)=O$%9:#7C$^4 155kBDI $''R8<<TB 
 33J?J'+'K'Kj,($
 ) %* (++K8	 4=$[1(<M$%89''r^   raw_responsemodel_responseprefix_promptc           	      N   i }t        t        |j                              |d<   d|v r1t        |dd       }t	        t        |d         |j                  |      | j                  |      \  }	}
}}}}}}|&|	j                  |      st        j                  s||	z   }	| j                  ||
|||||      }t        j                  ||	xs d |||      }||_        | j                  ||      }|d|d	<   |}||j                  d
   _        |d   |j"                  d<   t%        t&        t)        |d	               |j                  d
   _        | j-                  |d   |||      }t/        |d|       t1        t3        j2                               |_        |d   |_        ||d<   ||_        |S )Nadditional_headerserrorr  r  r  r  )r  )r  r3  r-  r  r  )r  r  r   stop_reasonr   r3  original_responser  )r  r  r  r   re   r-  )rF   r   r  getattrrD   r{   r  r  r   r   disable_add_prefix_to_promptr.  r7   r-  r  choicesr  _hidden_paramsr
   r0   r   finish_reasonr  rW   rt  timecreatedre   )rS   r  r/  r0  r  r1  r   r;  response_headersr  r  r  r  r  r  r  r  r-  r  json_mode_messager  s                        r\   transform_parsed_responsez)AnthropicConfig.transform_parsed_response  s     "/H%%&0
+, ))&|YE /89(44(  ))>Q)R		
 % ++M:88(<7L#'#G#G$
  ??! (D%=+/
 -E) BB! C 
 (17.(H,4q!)=P>
%%&9: 37,1-@A3
q!/
 $$,W5/ 3	 % 
 	/!$TYY[!127;5M12(6%r^   c                     t        |      dk(  ry|d   }|j                  d      }|d   dk(  r$|j                  dd      rt        |t              r|S y)	z
        Get the prefix prompt from the messages.

        Check last message
        - if it's assistant message, with 'prefix': true, return the content

        E.g. :    {"role": "assistant", "content": "Argentina", "prefix": True}
        r   Nr3  r  	assistantprefixF)r=  ri   r   r{   )rS   r  r  r  s       r\   get_prefix_promptz!AnthropicConfig.get_prefix_promptM  sW     x=A2,!++i0FO{*He,?C0""r^   logging_objrequest_dataencodingapi_keyc                    |j                  ||
|j                  d|i       	 |j                         }| j                  |      }|j                  d      }| j                  ||||||      }|S # t        $ rM}t	        |dd       }t        dj                  t        |      |j                        |j                  |      d }~ww xY w)	Ncomplete_input_dict)ru   rJ  r7  additional_argsr  z7Unable to get json response - {}, Original Response: {}r5  r  r   )r  r/  r0  r  r1  r   )	post_callr[  ry   rn   r8  rD   r   r{   r  rF  ri   rA  )rS   re   r/  r0  rG  rH  r  rX  r  rI  rJ  r  r  r  r?  r1  r   s                    r\   transform_responsez"AnthropicConfig.transform_responsed  s     	*//2LA	 	 	

	"."3"3"5 ...A##G,77 3%)' 8 
 +  	&|YE QXXFL-- )44( 	s   A/ /	C8AC  Cc                    | d   d   j                  d      }	 |t        j                  |      }t        |t              r>|j                  d      x}+t        j                  t        j                  |            }|S t        j                  t        j                  |            }|S 	 y# t        j                  $ r t        j                  |      cY S w xY w)z
        In JSON mode, Anthropic API returns JSON schema as a tool call, we need to convert it to a message to follow the OpenAI format

        r   rs   rv   Nvalues)r3  )	ri   ry   r  r   r   r   r7   rz   JSONDecodeError)r  r  r  rQ  r  s        r\   r  z1AnthropicConfig._convert_tool_response_to_message  s     0:!}Z/H/L/L0
	B$0zz"78tT*#'88H#55B&tzz&7IJH#O  'tzz$7GHH#O 1   ## 	B??+@AA	Bs   A$B+ >*B+ +)CCerror_messager  c                 N    t        ||t        t        j                  |            S )N)r  r  r  )rD   r
   httpxHeaders)rS   rS  r  r  s       r\   get_error_classzAnthropicConfig.get_error_class  s%     #!0
 	
r^   )NNNNNNNr   )NN)NNN)a__name__
__module____qualname____doc__rJ   r   rt  r   rK   r   rL   rM   rN   rO   r   rP   r{   r]   propertyrc   classmethodrh   staticmethodrj   r   r   r-   r}   r   r   r   r   r	   r   r   r!   r   r/   r   r   r   r  r1   r   r   r,  r.  r2  r9  r@  r'   r$   rJ  rN  r"   rW  r    r^  r2   r%   rl  rz  r  r\  r(   r#   r  r   r  r  r   r  r  r  LitellmMessager  r,   r*   r  r;   r  r  r3   r*  r.  rU  Responser:   rA  rF  LoggingClassrO  r  rV  r   rW  __classcell__)rX   s   @r\   rI   rI   X   sW	    !%J$%)NHTN)!%K#%E8C=E8C=#Hhtn# FHSM  %))-%)###' $4SM4 !4 c]	4
 }4 }4 4.4 4 
4 Xc]   26 (3-   5 5 5 5  $S#X 
% : 
# 
$ 
 
 B otCH~ o$sCx. o ob
$S$_5
	$

4 
'#C='=Ed^'	-	.'RN)+N)	x/0(;Q2RR	SN)`'	>,,	t+,d3I.JJ	K,"x~ $ &d &uT4Z7H &$+ +  +  
	+ ZU3S	>23	$s)	, O"5)93)>#?@OO 
(	)O OBd^	$
d^
	'	(
<d^6:QU	'	(6&%& 
 &> 8!$tCH~"6S#X"FG8	$sCx.	!8 8tR R R 	R
 R 
Rl '+d^ 
<C--.C-	+	,C-J 01  E14789  
e+T12	3	 DI4 IS IT I"&&17&	&P&&.2&	&PDD '(D 	D
 D D 
DLD> 45 
.	!	(i
#'i
	c13VVW	

 	()ccc	
i
^ /3#nn $C=n &d^	n
 }n 
n`:;	c3h(3i( cN( sm	(
 
'	((20(!0( DI&0( "13VVW
	0( %T#Y/0( tCy)0( $DI.0( 450( 
c3h0(n %)'+#X!X nnX &	X
 D>X  }X }Xt$/?*@ Xc] D "&$(.. nn. &	.
 ". . '(. . . . #. D>. 
.` 45	.	! <
 
/2
=B4CV=W
	
r^   rI   r  rQ   c                 h    d}d}t        j                  ||       ryt        j                  ||       ryy)z
    Validate that user_id is not an email or phone number.
    Returns: bool: True if valid (not email or phone), False otherwise
    z0^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$z^\+?[\d\s\(\)-]{7,}$FT)rematch)r  email_patternphone_patterns      r\   r  r    s4    
 HM+M	xxw'	xxw'r^   )[ry   rd  r=  typingr   r   r   r   r   r   r	   r
   rU  r   litellm.constantsr   r   r   r   r   r   r   'litellm.litellm_core_utils.core_helpersr    litellm.llms.base_llm.base_utilsr   )litellm.llms.base_llm.chat.transformationr   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   litellm.types.llms.openair'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   litellm.types.responses.mainr3   r4   litellm.types.utilsr5   r6   r7   r_  r8   r9   litellm.utilsr:   r;   r<   r=   r>   r?   r@   rA   rB   common_utilsrD   rE   rF   *litellm.litellm_core_utils.litellm_loggingrG   LiteLLMLoggingObjra  rI   r{   r   r  ra   r^   r\   <module>rt     s     	  O O O     F J R    $    :
 
 
 Y XW$LLb
(* b
J;C D r^   