
    Mi7              .           S r SSKrSSKrSSKJr  SSKJrJrJrJ	r	J
r
JrJrJrJr  SSKrSSKJrJrJr  SSKrSSKJr  SSKJrJr  SSKJr  SS	KJr  SS
KJr  \" 5       r SSK!J"r"  \(       a  SSK#J$r%  SSK&J'r'  \SSSSSSSSSSSSS.S\(S\(S\(S\\(   S\\(   S\\(   S\\)   S\\)   S\\   S\\)   S\\   S\\   S\\   S\\   S\\\\4      S\\RT                  \\\4   4   4 S  jj5       r+\SSSSSS!SSSSSSSS".S\(S\(S\(S\\(   S\\(   S\\(   S\\)   S\\)   S#\,S\\   S\\)   S\\   S\\   S\\   S\\   S\\\\4      S\\RT                  \	\\\RT                  4   \	\\\\RT                  \\\4   4   4   \
\\\4   \\\4   4   4"S$ jj5       r-S\\\4   S%\R\                  S&\,S'S(S)S*S\\RT                  \\\4   4   4S+ jr/S,\RT                  S'S(S)S*4S- jr0S,\	\\\RT                  4   S'S(S)S*4S. jr1g)/z?
This module is used to pass through requests to the LLM APIs.
    N)partial)	TYPE_CHECKINGAnyAsyncGenerator	Coroutine	GeneratorListOptionalUnioncast)CookieTypesQueryParamTypesRequestFiles)get_llm_provider)AsyncHTTPHandlerHTTPHandler)BaseLLMHTTPHandler)CommonUtils)client   )BasePassthroughUtils)Logging)BasePassthroughConfig)custom_llm_providerapi_baseapi_keyrequest_query_paramsrequest_headerscontentdatafilesjsonparamscookiesr   methodendpointmodelr   r   r   r   r   r   r    r!   r"   r#   r$   r   returnc                 "  #     [         R                  " 5       nSUS'   [        UUUUS9u  p#pTSSKJn  SSKJn  [        [        S   UR                  S5      5      =(       d    UR                  U" U5      US	9nUc  [        SU S35      e[        [        4U UUUUUUUUU	U
UUUUS.UD6n[        R                  " 5       n[        UR                   U5      nUR#                  S
U5      I S
h  vN n[         R$                  " U5      (       a;  UI S
h  vN n['        U[(        R*                  5      (       a  UR-                  5         U$ [        S5      e Ne NB! [(        R.                   a  nUeS
nAf[         a  nSSKJn  SSKJn  [        UUUUS9u  nn  nS
nU(       aQ   [        [        S   UR                  S5      5      =(       d    UR                  U" U5      US	9nO! [         a     Of = fUc  Ue[0        R3                  UUS9eS
nAff = f7f)zJ
Async: Reranks a list of documents based on their relevance to the query
Tallm_passthrough_router'   r   r   r   r   LlmProvidersProviderConfigManagerr   provider_configproviderr'   N	Provider 
 not found)r%   r&   r'   r   r   r   r   r   r   r    r!   r"   r#   r$   r   z/Expected coroutine from async passthrough routeer0   )asyncioget_event_loopr   litellm.types.utilsr-   litellm.utilsr/   r   r
   getget_provider_passthrough_config	Exceptionr   llm_passthrough_routecontextvarscopy_contextrunrun_in_executoriscoroutine
isinstancehttpxResponseraise_for_statusHTTPStatusErrorbase_llm_http_handler_handle_error)r%   r&   r'   r   r   r   r   r   r   r    r!   r"   r#   r$   r   kwargsloopr-   r/   r0   funcctxfunc_with_contextinit_responseresponser6   _resolved_custom_llm_providers                               r/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/litellm/passthrough/main.pyr*   r*   &   si    .c
%%'+/'(8H 3	9
5G 	57,-vzz:K/L
 
"BB!"56 C 
 	 "i(;'<JGHH!
 3!5+!
" #
( &&(#CGGT2"2249JKK }--**H (ENN33))+O MNN L +      "
47 1A 3	1
-'A '	"&45vzzBS7T# #*JJ)*FG K      "G#11+ 2 
 	
?"
s}   HC&E *E+$E E4E HE E H(E**H7&H?GH
G+(H*G++HHHF)r   r   r   r   r   r*   r   r    r!   r"   r#   r$   r   r*   c                    SSK Jn  SSKJn  SSKJn  UnUc(  U(       a  [        R                  nO[        R                  n[        SUR                  S5      5      n[        UUUUS9u  p#pTU" S0 UD6nUR                  UU0 UUU
(       a  U
OUS	9  [        [        S
   UR                  S5      5      =(       d    UR                  U" U5      US9nUc  [        SU S35      eUR!                  UUUUUUS9u  nnUS:X  a;  SU;   a5  ["        R$                  " ['        U5      5      n[(        R*                  " U5      nUR-                  U5      nUR/                  0 U/ 0 0 UUS9n[0        R2                  " U=(       d    0 USS9nUR5                  UUU
(       a  U
OU['        U5      US9u  nnU(       a  [7        U[8        5      (       a
  SU;   a  X,S'   UR:                  R=                  U UUUc  U
OSUUc  UOSUUUS9	nUR?                  UU
=(       d    U=(       d    0 S9n U Ul         U
(       a  U
OUn!URC                  U!UU!['        U5      US.S9   U(       a  [E        UUU UUS9$ UR:                  RG                  UU S9n"U"RI                  5         [K        U"S5      (       a  U (       a  [M        U"UU5      $ U"$ ! [         a  n#Uc  U#e[N        RQ                  U#US9eSn#A#ff = f) zx
Pass through requests to the LLM APIs.

Step 1. Build the request
Step 2. Send the request
Step 3. Return the response
r   )get_litellm_paramsr,   r.   NLiteLLMLoggingObjlitellm_logging_objr+   )r'   litellm_paramsoptional_paramsr&   r   request_datar   r0   r1   r3   r4   )r   r   r'   r&   r   rY   bedrockzapplication-inference-profile)headersr'   messagesrZ   rY   r   r   F)r   r]   forward_headers)r]   rY   r[   r   r'   r'   )	r%   urlr   r    r!   r"   r#   r]   r$   )r&   r[   )complete_input_dictr   r]   )inputr   additional_args)r   requestis_streaming_requestrX   r0   rd   stream
iter_bytesr5    ))-litellm.litellm_core_utils.get_litellm_paramsrV   r9   r-   r:   r/   litellmmodule_level_aclientmodule_level_clientr   r;   r   update_environment_variablesr
   r<   r=   get_complete_urlr   "encode_bedrock_runtime_modelid_arnstrrE   URLget_api_keyvalidate_environmentr   forward_headers_from_requestsign_requestrD   dictr   build_requestre   rg   pre_call_async_passthrough_requestsendrG   hasattr_sync_streamingrI   rJ   )$r%   r&   r'   r   r   r   r   r   r*   r   r    r!   r"   r#   r$   r   rK   rV   r-   r/   	_is_asyncrX   litellm_params_dictr0   updated_urlbase_target_urlencoded_url_strprovider_api_keyauth_headersr]   signed_json_bodyrd   re   r[   rQ   r6   s$                                       rT   r>   r>      sv   D Q03&I~11F00F2FJJ?T4UV4D/	51E -6v644*/!Tt 5  ()6::6G+H 		>	>12 
? 
  )$7#8
CDD#2#C#C1* $D $ K i',Kx,W%HH
 ii0 '227;"77   8 L #??'-2G !0 < <*!Tt[! != !G 
4&&7d?Wmm)) %-T4%-T4 * 
G +??'T'R @  "6  4TL   #/K(
 ! 
-%9$7 /  (.}}'9'9'Rf'9'gH%%' ,//4H&x1DoVV   
"G#11+ 2 
 	

s%   	J. AJ. ,J. .
K8KKrd   re   rX   rW   r0   r   c                   #    U R                   R                  XS9n[        R                  " U5      (       aF  U(       a  [	        UUUS9$ UI Sh  vN nUR                  5       I Sh  vN   UR                  5         U$ [        S5      e N9 N#7f)zf
Handle async passthrough requests.
Uses async client to send request and properly handles streaming.
rf   )rQ   rX   r0   Nz$Expected coroutine from async client)r   r{   r7   rC   _async_streamingareadrG   r=   )r   rd   re   rX   r0   response_resultrQ   s          rT   rz   rz   \  s      mm(((VO ?++#($7 /  -,H.."""%%'O >?? -"s$   ABBB&B
'"B
BrQ   c              #      #    SSK Jn   / nU R                  5        H  nUR                  U5        Uv   M     UR	                  UR
                  UUS9  g ! [         a  nUeS nAff = f7f)Nr   )executor	raw_bytesr0   )r:   r   rh   appendsubmit"flush_passthrough_collected_chunksr=   )rQ   rX   r0   r   r   chunkr6   s          rT   r}   r}   }  sr     
 '!#	((*EU#K + 	BB+ 	 	

  s)   A(A	A A(
A%A  A%%A(c                  #     U I S h  vN n/ nUR                  5         S h  vN nUR                  U5        U7v   M!   N7 N
 [        R                  " UR	                  UUS95        g ! [
         a  nUeS nAff = f7f)Nr   )aiter_bytesr   r7   create_task(async_flush_passthrough_collected_chunksr=   )rQ   rX   r0   iter_responser   r   r6   s          rT   r   r     s     
&!#	(446 	%U#K '	6
 	HH# / I 	
  sR   A?A+ AA+ AAAA+ A%A+ *A?+
A<5A77A<<A?)2__doc__r7   r?   	functoolsr   typingr   r   r   r   r   r	   r
   r   r   rE   httpx._typesr   r   r   rk   1litellm.litellm_core_utils.get_llm_provider_logicr   &litellm.llms.custom_httpx.http_handlerr   r   *litellm.llms.custom_httpx.llm_http_handlerr   litellm.passthrough.utilsr   r:   r   rI   utilsr   *litellm.litellm_core_utils.litellm_loggingr   rW   0litellm.llms.base_llm.passthrough.transformationr   rq   rw   rF   r*   boolr>   Requestrz   r}   r   ri       rT   <module>r      s     
 
 
  C C  N P I 1  *,  'WV  *."!+/&*!$((,%)=A!y
y
 y
 	y

 "#y
 smy
 c]y
 #4.y
 d^y
 c]y
 4.y
 L!y
 3-y
 _%y
 k"y
  U;(889:!y
$ 5>>>#s(334%y
 y
x  *."!+/&*#(!$((,%)=A#u
u
 u
 	u

 "#u
 smu
 c]u
 #4.u
 d^u
 !u
 c]u
 4.u
 L!u
 3-u
 _%u
  k"!u
" U;(889:#u
& 	NNc3&'c3ennnS#X.FFGGHc3m38	'u
 u
p@+//0@]]@ @ -	@
 -@ 5>>>#s(334@Bnn, -,S%..01, -r   