
    ia                          d Z ddlZddlZddlmZmZmZ ddlZddlm	Z	 ddl
mZmZ ddlmZ ddlmZ dd	lmZ er	  G d
 de	      Zy)zZ
Azure Anthropic handler - reuses AnthropicChatCompletion logic with Azure authentication
    N)TYPE_CHECKINGCallableUnion)AnthropicChatCompletion)AsyncHTTPHandlerHTTPHandler)ModelResponse)CustomStreamWrapper   )AzureAnthropicConfigc                   |     e Zd ZdZd fdZddi dfdededededed	ed
e	dede
eej                  f   defdZ xZS )AzureAnthropicChatCompletionzp
    Azure Anthropic chat completion handler.
    Reuses all Anthropic logic but with Azure authentication.
    Nc                 "    t         |           y )N)super__init__)self	__class__s    x/Users/manta/Documents/Projects/TheRoad-I1/.venv/lib/python3.12/site-packages/litellm/llms/azure_ai/anthropic/handler.pyr   z%AzureAnthropicChatCompletion.__init__   s        modelmessagesapi_basecustom_llm_providercustom_prompt_dictmodel_responseprint_verboseoptional_paramstimeoutlitellm_paramsc                    t        j                  |      }|j                  dd      }|j                  dd      }|j                  dd      }d}t        j                  |      }t               }|j	                  |	|||i |d|i|      }|j                  |||||      }|
j                  ||	|||d	        |d
|        |du rs|du rJ |d       ||d<   | j                  |||||||||	|
|||||||||t        |t              r|      S d      S | j                  |||||||||	||
|||||||||      S |du rN||d<   ddlm}  ||||t        j                  |      |||
||	      \  }}ddlm} t#        ||d|
 ||            S |t        |t$              sddlm}  |d|i      }n|}	 |j+                  ||t        j                  |      |      }|j7                  ||||
|	||||||       S # t,        $ r}ddlm} t1        |dd      } t1        |dd      }!t1        |dt3        |            }"t1        |dd      }#|!|#rt1        |#dd      }!|#rt5        |#d      rt1        |#d|"      }" ||"| |!      d}~ww xY w)!z
        Completion method that uses Azure authentication instead of Anthropic's x-api-key.
        All other logic is the same as AnthropicChatCompletion.
        streamN	json_modeFis_vertex_request)api_keyheadersr   r   r   r   )r   r   r   r   r%   )complete_input_dictr   r%   )inputr$   additional_argsz_is_function_call: Tz2makes async azure anthropic streaming POST request)r   r   datar   r   r   r   encodingr$   logging_objr   r!   _is_function_callr"   r   	logger_fnr%   r   client)r   r   r)   r   r   r   r   r*   r$   provider_configr+   r   r!   r,   r   r-   r%   r.   r"   r   r   )make_sync_call)	r.   r   r%   r)   r   r   r+   r   r"   )process_anthropic_headersazure_ai)completion_streamr   r   r+   _response_headers)_get_httpx_clientr   )params)r%   r)   r   )AnthropicErrorstatus_codei  r%   textresponse)messager8   r%   )r   raw_responser   r+   r$   request_datar   r   r   r*   r"   )copydeepcopypopr   validate_environmenttransform_requestpre_callacompletion_stream_function
isinstancer   acompletion_function#litellm.llms.anthropic.chat.handlerr0   jsondumps#litellm.llms.anthropic.common_utilsr1   r
   r   &litellm.llms.custom_httpx.http_handlerr5   post	Exceptionr7   getattrstrhasattrtransform_response)$r   r   r   r   r   r   r   r   r*   r$   r+   r   r   r   acompletionr-   r%   r.   r!   r"   r#   r,   configr)   r0   r3   response_headersr1   r5   r:   er7   r8   error_headers
error_texterror_responses$                                       r   
completionz'AzureAnthropicChatCompletion.completion!   s   2 --8 $$Xt4)--k5A	"1"5"56I5"Q!==* &'--WW0CEVW) . 
 ''+) ( 
 	'+$" 	 	
 	+,=+>?@$$RS!'X77%%'9#1"/%# +$3!&7'#1'## "-*VEU2V ) 8  , "- 8  4 00%%'9#1"/%#$* +$3!&7#1'#!'#) 1  2 $!'XN6D!%#D)% +#'
73!#3 +&7(2 +&?@P&Q  >FK)HX.y'6JKF#F%{{  '!ZZ- '	  +  H. ((!)#+) ) 
 	
# ! R")!]C"@K$+Ay$$?M!(FCF!;J%,Q
D%AN$,(/	4(P%'.&*I%,^VZ%P
( *$/ - s   3(G7 7	I? A:I::I?)returnN)__name__
__module____qualname____doc__r   rO   listdictr	   r   r   floathttpxTimeoutrY   __classcell__)r   s   @r   r   r      s    
$ %A
A
 A
 	A

 !A
 !A
 &A
  A
 A
 uemm+,A
 A
r   r   )r^   r>   rH   typingr   r   r   rb   rG   r   rK   r   r   litellm.types.utilsr	   litellm.utilsr
   transformationr   r    r   r   <module>rj      sC      1 1  G . - 0J
#: J
r   