Ë
    uPêj„   ã                   óš   — d Z ddlZddlZddlmZ ddlmZ ddlZddlm	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  G d„ de«      Zy)zZ
Azure Anthropic handler - reuses AnthropicChatCompletion logic with Azure authentication
é    N)ÚCallable)ÚFinal)ÚLogging)Ú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deej                  z  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    €úl/home/oem/CyberBrain26-unified/.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Úlogging_objÚ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%   r   r   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ˆØ'×+Ñ+¨H°dÓ;ˆØ!0×!4Ñ!4°[À%Ó!Hˆ	Ø)8×)<Ñ)<Ð=PÐRWÓ)XÐØ#(ÐÜ—=‘= Ó*ˆô -Ó.ˆà×-Ñ-ØØØØØW˜ÐWÐ0CÐEVÑWØ)ð .ó 
ˆð ×.Ñ.ØØØ+Ø)Øð /ó 
ˆð 	×ÑØØà'+Ø$Ø"ñð 	ô 	
ñ 	Ð+Ð,=Ð+>Ð?Ô@Ø˜$Ñà˜$‘áÐRÔSØ!'��X‘Ø×7Ñ7ØØ%ØØ%Ø'9Ø#1Ø"/Ø%Ø#Ø +Ø$3Ø!Ø&7Ø'Ø#1Ø'Ø#Ø#Ø&,Ð&8¼ZÈÔP`Ô=a˜Fð' 8ó ð ð& hlð' 8ó ð ð, ×0Ñ0ØØ%ØØ%Ø'9Ø#1Ø"/Ø%Ø#Ø$*Ø +Ø$3Ø!Ø&7Ø#1Ø'Ø#Ø!Ø'Ø#ð) 1ó ð ð2 ˜$‘à!'��X‘åNá6DØ!Ø%Ø#ÜŸ™ DÓ)ØØ%Ø +Ø#Ø'ô
7Ñ3Ð!Ð#3õô +Ø&7ØØ(2Ø +Ù&?Ð@PÓ&Qôð ð �>¬°F¼KÔ)HÝXá.°yÀ'Ð6JÔK‘Fà#�FðØ&,§k¡kØ Ø 'Ü!ŸZ™Z¨Ó-Ø 'ð	 '2ó '�Hð. ×(Ñ(ØØ!Ø)Ø#ØØØØ+Ø)ØØð )ó 
ð 	
øô# !ò ÝRä)0°°MÀ3Ó)G�KÜ$+¨A¨y¸$Ó$?�MÜ!(¨¨F´C¸³FÓ!;�JÜ,3°A°zÀ4Ó,H�NØ$Ð,±Ü(/°À	È4Ó(P˜Ù%¬'°.À&Ô*IÜ%,¨^¸VÀZÓ%P˜
Ù(Ø *Ø$/Ø -ôð ûðús   Æ3(G7 Ç7	I?È A:I:É:I?)ÚreturnN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rO   ÚlistÚdictr	   r   ÚLiteLLMLoggingObjÚfloatÚhttpxÚTimeoutrY   Ú__classcell__)r   s   @r   r   r      s¡   ø„ ñõ
ð$ ØØØñ%}
àð}
ð ð}
ð ð	}
ð
 !ð}
ð !ð}
ð &ð}
ð  ð}
ð 'ð}
ð ð}
ð ˜Ÿ™Ñ&ð}
ð ÷}
r   r   )r^   r>   rH   Úcollections.abcr   Útypingr   rc   Ú*litellm.litellm_core_utils.litellm_loggingr   ra   rG   r   rK   r   r   Úlitellm.types.utilsr	   Úlitellm.utilsr
   Útransformationr   r   © r   r   ú<module>rm      s@   ðñó Û Ý $Ý ã å SÝ G÷õ .Ý -å 0ôF
Ð#:õ F
r   