
    g"w                     L   d Z ddlZddlZddlZddlmZ ddl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 ddlmZ ddlmZ ddlmZ  G d	 d
e      Z G d d      Z G d d      Z G d dee      Z G d d      Z G d d      Z G d dee      Z G d dee      Z G d de      Z G d dee      Z  G d dee      Z!d Z"	 	 	 	 	 	 	 	 	 	 	 d0d e	e#   d!e	e#   d"e	e#   d#e	e#   d$e	e#   d%e	e#   d&e	e#   d'e	e#   d(e	e$   d)e	e
e%ejL                  f      fd*Z' G d+ d,      Z(d-e#d.e#fd/Z)y)1zF
Common utilities used across bedrock chat/embedding/image generation
    N)Enum)AnyListOptionalUnion)
BaseConfigBaseLLMExceptionLiteLLMLoggingObj)
get_secret)AllMessageValues)ModelResponsec                       e Zd Zy)BedrockErrorN)__name__
__module____qualname__     V/var/www/openai/venv/lib/python3.12/site-packages/litellm/llms/bedrock/common_utils.pyr   r      s    r   r   c                   R    e Zd Zd ZdefdZdedefdZdee   fdZ	dee   fdZ
y	)
AmazonBedrockGlobalConfigc                      y Nr   selfs    r   __init__z"AmazonBedrockGlobalConfig.__init__   s    r   returnc                 
    ddiS )zS
        Mapping of common auth params across bedrock/vertex/azure/watsonx
        region_nameaws_region_namer   r   s    r   get_mapped_special_auth_paramsz8AmazonBedrockGlobalConfig.get_mapped_special_auth_params    s     011r   non_default_paramsoptional_paramsc                 p    | j                         }|j                         D ]  \  }}||v s||||   <    |S r   )r!   items)r   r"   r#   mapped_paramsparamvalues         r   map_special_auth_paramsz1AmazonBedrockGlobalConfig.map_special_auth_params&   sF    ;;=.446LE5%8=e 45 7 r   c                 
    g dS )D
        Source: https://www.aws-services.info/bedrock.html
        )z	eu-west-1z	eu-west-3zeu-central-1r   r   s    r   get_eu_regionsz(AmazonBedrockGlobalConfig.get_eu_regions-   s    
 	
r   c                 
    g dS )r+   )z	us-east-2z	us-east-1z	us-west-2zus-gov-west-1r   r   s    r   get_us_regionsz(AmazonBedrockGlobalConfig.get_us_regions7   s    
 	
r   N)r   r   r   r   dictr!   r)   r   strr,   r.   r   r   r   r   r      sG    2 2$ QU 
S	 
	
S	 	
r   r   c                      e Zd ZdZdededeeej                  f   de
fdZdedee   d	ed
ededefdZ	 	 ddedej                  dedededee   d	ed
ededee   dee   defdZ	 	 ddededee   d	edee   dee   defdZy)AmazonInvokeMixinzG
    Base class for bedrock models going through invoke_handler.py
    error_messagestatus_codeheadersr   c                     t        |||      S )N)messager4   r5   )r   )r   r3   r4   r5   s       r   get_error_classz!AmazonInvokeMixin.get_error_classH   s     !#
 	
r   modelmessagesr#   litellm_paramsc                     t        d      )NzGtransform_request not implemented for config. Done in invoke_handler.pyNotImplementedError)r   r9   r:   r#   r;   r5   s         r   transform_requestz#AmazonInvokeMixin.transform_requestQ   s     "U
 	
r   Nraw_responsemodel_responselogging_objrequest_dataencodingapi_key	json_modec                     t        d      )NzHtransform_response not implemented for config. Done in invoke_handler.pyr=   )r   r9   r@   rA   rB   rC   r:   r#   r;   rD   rE   rF   s               r   transform_responsez$AmazonInvokeMixin.transform_response]   s     "V
 	
r   api_basec                     t        d      )NzJvalidate_environment not implemented for config. Done in invoke_handler.pyr=   )r   r5   r9   r:   r#   rE   rI   s          r   validate_environmentz&AmazonInvokeMixin.validate_environmento   s     "X
 	
r   NN)r   r   r   __doc__r0   intr   r/   httpxHeadersr	   r8   r   r   r?   Responser   r
   r   r   boolrH   rK   r   r   r   r2   r2   C   ss   
 
/2
=B4CV=W
	




 '(

 	


 

 

 


. "&$(

 nn
 &	

 '
 
 '(
 
 
 
 #
 D>
 

0 "&"&

 
 '(	

 
 #
 3-
 

r   r2   c                   
   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dee   dee	   dee   dee   ddf
dZed	        Zd
edededeee   ef   fdZdedee   fdZdededededef
dZy)AmazonTitanConfigaw  
    Reference: https://us-west-2.console.aws.amazon.com/bedrock/home?region=us-west-2#/providers?model=titan-text-express-v1

    Supported Params for the Amazon Titan models:

    - `maxTokenCount` (integer) max tokens,
    - `stopSequences` (string[]) list of stop sequence strings
    - `temperature` (float) temperature for model,
    - `topP` (int) top p for model
    NmaxTokenCountstopSequencestemperaturetopPr   c                     t               }|j                         D ]%  \  }}|dk7  s|t        | j                  ||       ' y Nr   localsr%   setattr	__class__)r   rU   rV   rW   rX   locals_keyr(   s           r   r   zAmazonTitanConfig.__init__   s;     (!--/JCf}!2U3 *r   c                    | j                   j                         D ci c]`  \  }}|j                  d      sJ|j                  d      s9t        |t        j
                  t        j                  t        t        f      s|||b c}}S c c}}w N___abc	__dict__r%   
startswith
isinstancetypesFunctionTypeBuiltinFunctionTypeclassmethodstaticmethodclskvs      r   
get_configzAmazonTitanConfig.get_config        **,
,1<<%LL(&&-- 	  qD,
 	
 
   A%Bsupported_paramsproviderr9   stopc                     d}d|v rZt         j                  rJ|dk(  rEd|v rAg }t        |t              r/|D ]*  }t	        j
                  d|      s|j                  |       , |||d<   |S )z
        filter params to fit the required provider format, drop those that don't fit if user sets `litellm.drop_params = True`.
        Nrw   bedrockamazonz^(\|+|User:)$)litellmdrop_paramsrh   listrematchappend)r   ru   rv   r9   rw   filtered_stopss          r   _map_and_modify_argz%AmazonTitanConfig._map_and_modify_arg   sx     %%'*=*=9$U): "dD)!88$4a8)003 " $'4V$r   c                 
    g dS )N)
max_tokensmax_completion_tokensrw   rW   top_pstreamr   r   r9   s     r   get_supported_openai_paramsz-AmazonTitanConfig.get_supported_openai_params   s    
 	
r   r"   r#   r|   c                     |j                         D ]W  \  }}|dk(  s|dk(  r||d<   |dk(  r||d<   |dk(  r| j                  d|id||      }|d   |d<   |d	k(  r||d
<   |dk(  sS||d<   Y |S )Nr   r   rU   rW   rw   ry   )rv   r9   rw   rV   r   rX   r   )r%   r   )r   r"   r#   r9   r|   rp   rq   r   s           r   map_openai_paramsz#AmazonTitanConfig.map_openai_params   s     ',,.DAqL A)@$@340M!12.F{ $ 8 8QK)5q !9 ! 4A3H0G|*+'H},-) / r   )NNNN)r   r   r   rM   rU   r   rN   __annotations__rV   r}   rW   floatrX   r   rl   rr   r/   r0   r   r   r   r   rR   r   r   r   r   rT   rT   }   s,   	 $(M8C='$(M8D>(#'K%'D(3- (,(,'+"
4}
4  ~
4 e_	
4
 sm
4 

4 
 
$     	 
 DIsN# .
 
c 
   	
  
r   rT   c                       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	      ed<   	 	 ddee   dee	   ddfdZed        Zd ZdedefdZy)AmazonAnthropicClaude3Configa~  
    Reference:
        https://us-west-2.console.aws.amazon.com/bedrock/home?region=us-west-2#/providers?model=claude
        https://docs.anthropic.com/claude/docs/models-overview#model-comparison

    Supported Params for the Amazon / Anthropic Claude 3 models:

    - `max_tokens` Required (integer) max tokens. Default is 4096
    - `anthropic_version` Required (string) version of anthropic for bedrock - e.g. "bedrock-2023-05-31"
    - `system` Optional (string) the system prompt, conversion from openai format to this is handled in factory.py
    - `temperature` Optional (float) The amount of randomness injected into the response
    - `top_p` Optional (float) Use nucleus sampling.
    - `top_k` Optional (int) Only sample from the top K options for each subsequent token
    - `stop_sequences` Optional (List[str]) Custom text sequences that cause the model to stop generating
    i   r   zbedrock-2023-05-31anthropic_versionNsystemrW   r   top_kstop_sequencesr   c                     t               }|j                         D ]%  \  }}|dk7  s|t        | j                  ||       ' y rZ   r[   )r   r   r   r_   r`   r(   s         r   r   z%AmazonAnthropicClaude3Config.__init__   s;    
 (!--/JCf}!2U3 *r   c                     | j                   j                         D ci c]O  \  }}|j                  d      s9t        |t        j
                  t        j                  t        t        f      s|||Q c}}S c c}}w Nrc   re   rn   s      r   rr   z'AmazonAnthropicClaude3Config.get_config	  y     **,
,1<<%&&-- 	  qD,
 	
 
   AA6c                 
    g dS )N)	r   r   toolstool_choicer   rw   rW   r   extra_headersr   r   s    r   r   z8AmazonAnthropicClaude3Config.get_supported_openai_params  s    

 
	
r   r"   r#   c                     |j                         D ]G  \  }}|dk(  s|dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  sC||d<   I |S )	Nr   r   r   r   rw   r   rW   r   r%   r   r"   r#   r'   r(   s        r   r   z.AmazonAnthropicClaude3Config.map_openai_params(  s    .446LE5$1H(H05-+0( ,1)49 01%16.+0( 7 r   rL   )r   r   r   rM   r   r   rN   r   r   r0   r   rW   r   r   r   r   r   r   rl   rr   r   r/   r   r   r   r   r   r      s      !%J$';x}; FHSM #'K%'!E8E?!E8C=*.NHT#Y'. %)+/4SM4 $C=4 
	4 
 
"
D 4 r   r   c                      e Zd ZU dZej
                  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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        Zd ZdedefdZy)AmazonAnthropicConfiga  
    Reference: https://us-west-2.console.aws.amazon.com/bedrock/home?region=us-west-2#/providers?model=claude

    Supported Params for the Amazon / Anthropic models:

    - `max_tokens_to_sample` (integer) max tokens,
    - `temperature` (float) model temperature,
    - `top_k` (integer) top k,
    - `top_p` (integer) top p,
    - `stop_sequences` (string[]) list of stop sequences - e.g. ["\n\nHuman:"],
    - `anthropic_version` (string) version of anthropic for bedrock - e.g. "bedrock-2023-05-31"
    max_tokens_to_sampleNr   rW   r   r   r   r   c                     t               }|j                         D ]%  \  }}	|dk7  s|	t        | j                  ||	       ' y rZ   r[   )
r   r   r   rW   r   r   r   r_   r`   r(   s
             r   r   zAmazonAnthropicConfig.__init__N  s;     (!--/JCf}!2U3 *r   c                     | j                   j                         D ci c]O  \  }}|j                  d      s9t        |t        j
                  t        j                  t        t        f      s|||Q c}}S c c}}w r   re   rn   s      r   rr   z AmazonAnthropicConfig.get_config\  r   r   c                 
    g dS )N)r   r   rW   rw   r   r   r   r   s    r   r   z1AmazonAnthropicConfig.get_supported_openai_paramsn  s    
 	
r   r"   r#   c                     |j                         D ]B  \  }}|dk(  s|dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  s9|d	u s>||d<   D |S )
Nr   r   r   rW   r   rw   r   r   Tr   r   s        r   r   z'AmazonAnthropicConfig.map_openai_paramsz  s    .446LE5$1H(H:? 67%16.+0(49 01 Ud],1) 7 r   )NNNNNN)r   r   r   rM   r{   r   r   r   rN   r   r   r}   rW   r   r   r   r   r0   r   rl   rr   r   r/   r   r   r   r   r   r   9  s    +2*<*<(3-<%)NHTN)#'K%'E8C=E8C='+x}+ /3)-'+##+/4&sm4 !4 e_	4
 }4 }4 $C=4 
4 
 
"

D 4 r   r   c            
           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dee   dee	   dee   ddfdZed        Zd	edee   fd
Zdeded	ededef
dZy)AmazonCohereConfiga*  
    Reference: https://us-west-2.console.aws.amazon.com/bedrock/home?region=us-west-2#/providers?model=command

    Supported Params for the Amazon / Cohere models:

    - `max_tokens` (integer) max tokens,
    - `temperature` (float) model temperature,
    - `return_likelihood` (string) n/a
    Nr   rW   return_likelihoodr   c                     t               }|j                         D ]%  \  }}|dk7  s|t        | j                  ||       ' y rZ   r[   )r   r   rW   r   r_   r`   r(   s          r   r   zAmazonCohereConfig.__init__  ;     (!--/JCf}!2U3 *r   c                    | j                   j                         D ci c]`  \  }}|j                  d      sJ|j                  d      s9t        |t        j
                  t        j                  t        t        f      s|||b c}}S c c}}w rb   re   rn   s      r   rr   zAmazonCohereConfig.get_config  rs   rt   r9   c                 
    g dS )N)r   rW   r   r   r   s     r   r   z.AmazonCohereConfig.get_supported_openai_params  s    
 	
r   r"   r#   r|   c                 t    |j                         D ]$  \  }}|dk(  r||d<   |dk(  r||d<   |dk(  s ||d<   & |S )Nr   rW   r   r   r   r"   r#   r9   r|   rp   rq   s          r   r   z$AmazonCohereConfig.map_openai_params  sX     ',,.DAqH},-)M!12.L 01- / r   NNN)r   r   r   rM   r   r   rN   r   rW   r   r   r0   r   rl   rr   r   r   r/   rR   r   r   r   r   r   r     s     !%J$#'K%''+x}+ %)'++/		4SM	4 e_	4 $C=		4
 
	4 
 
$
 
c 
   	
  
r   r   c                   <   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	<   	 	 	 	 	 	 	 dd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        Zded
efdZdedededed
ef
dZy)AmazonAI21ConfigaK  
    Reference: https://us-west-2.console.aws.amazon.com/bedrock/home?region=us-west-2#/providers?model=j2-ultra

    Supported Params for the Amazon / AI21 models:

    - `maxTokens` (int32): The maximum number of tokens to generate per result. Optional, default is 16. If no `stopSequences` are given, generation stops after producing `maxTokens`.

    - `temperature` (float): Modifies the distribution from which tokens are sampled. Optional, default is 0.7. A value of 0 essentially disables sampling and results in greedy decoding.

    - `topP` (float): Used for sampling tokens from the corresponding top percentile of probability mass. Optional, default is 1. For instance, a value of 0.9 considers only tokens comprising the top 90% probability mass.

    - `stopSequences` (array of strings): Stops decoding if any of the input strings is generated. Optional.

    - `frequencyPenalty` (object): Placeholder for frequency penalty object.

    - `presencePenalty` (object): Placeholder for presence penalty object.

    - `countPenalty` (object): Placeholder for count penalty object.
    N	maxTokensrW   rX   rV   frequencePenaltypresencePenaltycountPenaltyr   c                     t               }|j                         D ]%  \  }	}
|	dk7  s|
t        | j                  |	|
       ' y rZ   r[   )r   r   rW   rX   rV   r   r   r   r_   r`   r(   s              r   r   zAmazonAI21Config.__init__  s;     (!--/JCf}!2U3 *r   c                    | j                   j                         D ci c]`  \  }}|j                  d      sJ|j                  d      s9t        |t        j
                  t        j                  t        t        f      s|||b c}}S c c}}w rb   re   rn   s      r   rr   zAmazonAI21Config.get_config  rs   rt   r9   c                 
    g dS N)r   rW   r   r   r   r   s     r   r   z,AmazonAI21Config.get_supported_openai_params      
 	
r   r"   r#   r|   c                     |j                         D ].  \  }}|dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  s*||d<   0 |S )Nr   r   rW   r   rX   r   r   r   s          r   r   z"AmazonAI21Config.map_openai_params  si     ',,.DAqL /0,M!12.G|*+'H},-) / r   )NNNNNNN)r   r   r   rM   r   r   rN   r   rW   r   rX   rV   r}   r   r/   r   r   r   rl   rr   r0   r   r   rR   r   r   r   r   r   r     sN   (  $Ix}##'K%' D(5/ $(M8D>('+htn+&*OXd^*#'L(4.' $('+ $(,+/*.'+4C=4 e_4 uo	4
  ~4 #4.4 "$4 tn4 
4 
 
$
 
 
   	
  
r   r   c                       e Zd ZdZdZy)AnthropicConstantsz	

Human: z

Assistant: N)r   r   r   HUMAN_PROMPT	AI_PROMPTr   r   r   r   r   (  s     L!Ir   r   c            
           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dee   dee	   dee   ddfdZed	        Zd
edefdZdeded
ededef
dZy)AmazonLlamaConfigaB  
    Reference: https://us-west-2.console.aws.amazon.com/bedrock/home?region=us-west-2#/providers?model=meta.llama2-13b-chat-v1

    Supported Params for the Amazon / Meta Llama models:

    - `max_gen_len` (integer) max tokens,
    - `temperature` (float) temperature for model,
    - `top_p` (float) top p for model
    Nmax_gen_lenrW   rX   rU   r   c                     t               }|j                         D ]%  \  }}|dk7  s|t        | j                  ||       ' y rZ   r[   )r   rU   rW   rX   r_   r`   r(   s          r   r   zAmazonLlamaConfig.__init__<  r   r   c                    | j                   j                         D ci c]`  \  }}|j                  d      sJ|j                  d      s9t        |t        j
                  t        j                  t        t        f      s|||b c}}S c c}}w rb   re   rn   s      r   rr   zAmazonLlamaConfig.get_configG  rs   rt   r9   c                 
    g dS r   r   r   s     r   r   z-AmazonLlamaConfig.get_supported_openai_paramsZ  r   r   r"   r#   r|   c                     |j                         D ].  \  }}|dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  s*||d<   0 |S )Nr   r   rW   r   r   r   r   s          r   r   z#AmazonLlamaConfig.map_openai_paramsb  si     ',,.DAqL 12.M!12.G|+,(H},-) / r   r   )r   r   r   rM   r   r   rN   r   rW   r   rX   r   rl   rr   r0   r   r   r/   rR   r   r   r   r   r   r   -  s     "&K#%#'K%' D(5/  (,'+"		4}	4 e_	4 sm		4
 
	4 
 
$
 
 
   	
  
r   r   c                      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      ed<   	 	 	 	 	 ddee   dee	   dee   dee	   deee      ddfd	Zed
        Zdedee   fdZdededededef
dZy)AmazonMistralConfiga  
    Reference: https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-mistral.html
    Supported Params for the Amazon / Mistral models:

    - `max_tokens` (integer) max tokens,
    - `temperature` (float) temperature for model,
    - `top_p` (float) top p for model
    - `stop` [string] A list of stop sequences that if generated by the model, stops the model from generating further output.
    - `top_k` (float) top k for model
    Nr   rW   r   r   rw   r   c                     t               }|j                         D ]%  \  }}|dk7  s|t        | j                  ||       ' y rZ   r[   )	r   r   rW   r   r   rw   r_   r`   r(   s	            r   r   zAmazonMistralConfig.__init__  s;     (!--/JCf}!2U3 *r   c                    | j                   j                         D ci c]`  \  }}|j                  d      sJ|j                  d      s9t        |t        j
                  t        j                  t        t        f      s|||b c}}S c c}}w rb   re   rn   s      r   rr   zAmazonMistralConfig.get_config  rs   rt   r9   c                 
    g dS )N)r   rW   r   rw   r   r   r   s     r   r   z/AmazonMistralConfig.get_supported_openai_params  s    GGr   r"   r#   r|   c                     |j                         D ]8  \  }}|dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  s4||d<   : |S )Nr   rW   r   rw   r   r   r   s          r   r   z%AmazonMistralConfig.map_openai_params  sz     ',,.DAqL 01-M!12.G|+,(F{*+'H},-) / r   )NNNNN)r   r   r   rM   r   r   rN   r   rW   r   r   r   rw   r   r0   r   rl   rr   r   r/   rR   r   r   r   r   r   r   u  s    	 !%J$#'K%'!E8E?!!E8E?! $D(49
$ %)'+#!%$(4SM4 e_4 }	4
 4 tCy!4 
4 
 
$H Hc H   	
  
r   r   c                       fd}|S )z,Closure to capture the headers and add them.c                 n    j                         D ]!  \  }}| j                  j                  ||       # y)z.Actual callback function that Boto3 will call.N)r%   r5   
add_header)requestkwargsheader_nameheader_valuer5   s       r   callbackz#add_custom_header.<locals>.callback  s,    )0%KOO&&{LA *9r   r   )r5   r   s   ` r   add_custom_headerr     s    B
 Or   aws_access_key_idaws_secret_access_keyr    aws_bedrock_runtime_endpointaws_session_nameaws_profile_nameaws_role_nameaws_web_identity_tokenr   timeoutc           
      `   t        dd       }t        dd       }||||||||g}t        |      D ](  \  }}|s	|j                  d      st        |      ||<   * |\  }}}}}}}}t        j                  dt
        j                        }| rn|r|} n|r|} n|r|} nt        dd      t        d      }|r|}n|r|}nd	|  d
}dd l}t        |
t              r|j                  j                  |
|
      }nft        |
t        j                        r2|j                  j                  |
j                  |
j                         }n|j                  j                         }|p|n|lt        |      }|t        dd      |j#                  d      }|j%                  |||d      }|j#                  d|d   d   |d   d   |d   d   | |||      }n|U|S|j#                  d||      }|j'                  ||      }|j#                  d|d   d   |d   d   |d   d   | |||      }nZ||j#                  d||| |||      }n?|'|j)                  |      j#                  d| |||      }n|j#                  d| |||      }|	r/|j*                  j,                  j/                  dt1        |	             |S )NAWS_REGION_NAME
AWS_REGIONzos.environ/
SSL_VERIFYzRAWS region not set: set AWS_REGION_NAME or AWS_REGION env variable or in .env filei  )r7   r4   AWS_BEDROCK_RUNTIME_ENDPOINTzhttps://bedrock-runtime.z.amazonaws.comr   )connect_timeoutread_timeoutz6OIDC token could not be retrieved from secret manager.stsi  )RoleArnRoleSessionNameWebIdentityTokenDurationSecondszbedrock-runtimeCredentialsAccessKeyIdSecretAccessKeySessionToken)service_namer   r   aws_session_tokenr   endpoint_urlconfigverify)r   r   )r   r   )r   r   r   r   r   r   r   )profile_name)r   r   r   r   r   zbefore-sign.bedrock-runtime.*)r   	enumeraterg   osgetenvr{   
ssl_verifyr   boto3rh   r   sessionConfigrO   Timeoutconnectreadclientassume_role_with_web_identityassume_roleSessionmetaeventsregisterr   )r   r   r   r    r   r   r   r   r   r   r   litellm_aws_region_namestandard_aws_region_nameparams_to_checkir'   r    env_aws_bedrock_runtime_endpointr   r   r   
oidc_token
sts_clientsts_responser   s                            r   init_bedrock_clientr    s    )):DA),= 	$	O o.5U%%m4!+E!2OA / 		$ <););<J 	%	 -	!.h
 	
 (22P'Q$#3	)71+nM'5!%%gG%T	GU]]	+%%#OO',, & 
 %%' 	*%( 67
P 
 \\%(
 "??!,' 	 @ 
 **=9-H".}"=>O"P*=9.I#%  	
 
	"'7'C\\/"7 " 

 "--!3C . 
 **=9-H".}"=>O"P*=9.I#%  	
 
	& */"7#%  
 
	% ,<=DD*#% E 
 *#%  
 ##+->}-M	
 Mr   c                   *    e Zd Zd Zd Zd Zd Zd Zy)ModelResponseIteratorc                      || _         d| _        y )NF)rA   is_done)r   rA   s     r   r   zModelResponseIterator.__init__  s    ,r   c                     | S r   r   r   s    r   __iter__zModelResponseIterator.__iter__      r   c                 L    | j                   rt        d| _         | j                  S NT)r  StopIterationrA   r   s    r   __next__zModelResponseIterator.__next__  s"    <<"""r   c                     | S r   r   r   s    r   	__aiter__zModelResponseIterator.__aiter__  r  r   c                 T   K   | j                   rt        d| _         | j                  S wr  )r  StopAsyncIterationrA   r   s    r   	__anext__zModelResponseIterator.__anext__  s&     <<$$"""s   &(N)r   r   r   r   r  r  r  r  r   r   r   r  r    s    
##r   r  response_tool_namer   c                 x    | t         j                  j                  v rt         j                  j                  |    } | S )z
    If litellm formatted the input tool name, we need to convert it back to the original name.

    Args:
        response_tool_name (str): The name of the tool as received from the response.

    Returns:
        str: The original name of the tool.
    )r{   bedrock_tool_name_mappings
cache_dict)r   s    r   get_bedrock_tool_namer$    s:     W??JJJ$??JJ
 r   )NNNNNNNNNNN)*rM   r   r~   ri   enumr   typingr   r   r   r   rO   r{   )litellm.llms.base_llm.chat.transformationr   r	   r
   litellm.secret_managers.mainr   litellm.types.llms.openair   litellm.types.utilsr   r   r   r2   rT   r   r   r   r   r   r   r   r   r0   r/   r   r   r  r  r$  r   r   r   <module>r+     s   
 	   - -   
 4 6 -	# 	$
 $
N7
 7
tf): fRP PfM M`B*J BJW(* Wt" "
E): EPG+Z GT '++/%)26&*&*#',0$(59s}s $C=s c]	s
 #+3-s sms sms C=s %SMs D>s eE5==012sl# #4c c r   