
    h                         d Z ddlZddlmZmZmZmZmZmZ ddl	Z	ddl
mZ ddl ddlmZ ddlmZmZ ddlmZ dd	lmZ  e       Zej/                  d
dg ee      g       ee      fdededefd       Zy)z2
Unified /v1/messages endpoint - (Anthropic Spec)
    N)	APIRouterDependsHTTPExceptionRequestResponsestatus)verbose_proxy_logger)*)user_api_key_auth)ProxyBaseLLMRequestProcessingcreate_streaming_response)_read_request_body)add_litellm_data_to_requestz/v1/messagesz[beta] Anthropic `/v1/messages`)tagsdependenciesfastapi_responserequestuser_api_key_dictc                 r	  K   ddl m}m}m}m}m}m}m}	m}
m	}m
} t        |       d{   }i |}	 |j                  dd      xs |	xs |j                  dd      |d<   |	r|	|d<   t        ||||||       d{   }|r||d<   |
r|
|d	<   |r||d
<   |r||d<   |d   t        j                  v rt        j                  |d      |d<   |j!                  ||d       d{   }||j"                  ng }|.|d   |v r't%        j&                   |j(                  d+i |      }nx|D|j*                  8|d   |j*                  v r't%        j&                   |j(                  d+i |      }n2|;|d   |j,                  v r*t%        j&                   |j(                  d+i |ddi      }n|;|d   |j/                         v r&t%        j&                   |j(                  d+i |      }n|[|d   |vrT|j0                  "t3        |j4                  j6                        dkD  r&t%        j&                   |j(                  d+i |      }n[|	)t%        j&                  t        j8                  d+i |      }n0t;        t<        j>                  dd|j                  dd      z   i      | d{   }tA        |di       xs i }|j                  dd      xs d}|j                  dd      xs d}|j                  dd      xs d}|j                  dd      xs d}t%        j&                  |jC                  |j                  dd      d             tE        jF                  d|       | jH                  jK                  tM        jN                  ||||||||             d|v rI|d   du rBtM        jP                  ||||      }tS        |dtU        | jH                                d{   S tE        jV                  d!jY                  |             |S 7 7 7 +7 l7 6# tZ        $ r}|j]                  |||"       d{  7   tE        j^                  d#jY                  ta        |                   ta        |       }tc        tA        |d$|      tA        |d%d&      tA        |d'd&      tA        |d(d)      *      d}~ww xY ww),z
    Use `{PROXY_BASE_URL}/anthropic/v1/messages` instead - [Docs](https://docs.litellm.ai/docs/anthropic_completion).

    This was a BETA endpoint that calls 100+ LLMs in the anthropic format.
    r   )
general_settings
llm_routerproxy_configproxy_logging_objuser_api_baseuser_max_tokens
user_modeluser_request_timeoutuser_temperatureversion)r   Ncompletion_modelmodel)datar   r   r   r   r   temperaturerequest_timeout
max_tokensapi_basetext_completion)r   r"   	call_typespecific_deploymentTerrorz/completion: Invalid model name passed in model= )status_codedetail_hidden_paramsmodel_id	cache_keyresponse_costlitellm_call_idsuccess)r2   r   zfinal response: %s)r   r/   r0   r&   r   r1   request_datahidden_paramsstream)responser   r4   r   ztext/event-stream)	generator
media_typeheadersz
Response from Litellm:
{})r   original_exceptionr4   zGlitellm.proxy.proxy_server.anthropic_response(): Exception occured - {}messagetypeNoneparamr,   i  )r<   r=   r?   code )2litellm.proxy.proxy_serverr   r   r   r   r   r   r   r   r   r   r   getr   litellmmodel_alias_mappre_call_hookmodel_namesasynciocreate_taskaanthropic_messagesmodel_group_aliasdeployment_namesget_model_idsdefault_deploymentlenpattern_routerpatternsanthropic_messagesr   r   HTTP_400_BAD_REQUESTgetattrupdate_request_statusr	   debugr:   updater   get_custom_headersasync_sse_data_generatorr   dictinfoformat	Exceptionpost_call_failure_hook	exceptionstrProxyException)r   r   r   r   r   r   r   r   r   r   r   r   r   r4   r"   router_model_namesllm_responser7   r5   r/   r0   r&   r1   selected_data_generatore	error_msgs                             g/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/proxy/anthropic_endpoints/endpoints.pyanthropic_responserh      s#       ,G<<L!L!DU
  !3T: ''xx& 	W
 &DM0-/%
 
 "2D&:D"#!0D,D
 =G333#33DMBDM '44/dFW 5 
 

 8B7MZ33SU "tG}8J'J"../Mz/M/M/UPT/UVL",,8W!=!=="../Mz/M/M/UPT/UVL"tG}
8S8S'S"...
..PP4PL "tG}
8P8P8R'R"../Mz/M/M/UPT/UVL"W%77--9z0099:Q> #../Mz/M/M/UPT/UVL#"..w/I/I/QD/QRL"77Nhhw+,  &%*:B?E2 $$Z6<"!%%k48>B	 $$Z6<"%))/4@FB 	33 $):B ?	 4 	
 	""#7B  '')<<"3!#!+!+		
 h4!7 .FF%&7!%&7	 $ 31.-556   	!!"@"G"G"QRO =
4
b &T  
66/ATX 7 
 	
 	
 	&&U\\A	

 1vh	Ay)4FF+!Wf-M3/	
 	

s   (R7PR7AP <P
=A%P "P#GP $P%D7P PP  R7!%P R7
P P P P 	R4R/5P86A9R//R44R7)__doc__rH   fastapir   r   r   r   r   r   rD   litellm._loggingr	   litellm.proxy._types$litellm.proxy.auth.user_api_key_authr   'litellm.proxy.common_request_processingr   r   -litellm.proxy.common_utils.http_parsing_utilsr   $litellm.proxy.litellm_pre_call_utilsr   routerpostUserAPIKeyAuthrh   rA       rg   <module>ru      s     P P  1 " B M L	 
+	,+,-   )00A(Bn
n
n
 &n

n
rt   