
    ^h                         S SK r S SKrS SKJr  S SKJrJr  S SKrS SKJr  S SK	J
r  S SKJr  S SKJr  SS	KJr  SS
KJr  SSKJr  SSKJr   " S S5      rg)    N)datetime)ListOptional)verbose_proxy_logger)Logging)&PassThroughEndpointLoggingResultValues)!StandardPassThroughResponseObject   )"AnthropicPassthroughLoggingHandler)VertexPassthroughLoggingHandler)PassThroughEndpointLogging)EndpointTypec                       \ rS rSr\S\R                  S\\   S\	S\
S\S\S\4S	 j5       r\S\	S\S\S\S\
S\S
\\   S\4S j5       r\S
\\   S\\   4S j5       rSrg)PassThroughStreamingHandler   responserequest_bodylitellm_logging_objendpoint_type
start_timepassthrough_success_handler_obj	url_routec                |  #     / nU R                  5         Sh  vN nUR                  U5        U7v   M!   N
 [        R                  " 5       n	[        R
                  " [        R                  UUUU=(       d    0 UUUU	S95        g! [         a(  n
[        R                  " S[        U
5       35        e Sn
A
ff = f7f)z\
- Yields chunks from the response
- Collect non-empty chunks for post-processing (logging)
N)r   r   r   r   r   r   	raw_bytesend_timezError in chunk_processor: )aiter_bytesappendr   nowasynciocreate_taskr   #_route_streaming_logging_to_handler	Exceptionr   errorstr)r   r   r   r   r   r   r   r   chunkr   es              p/home/james-whalen/.local/lib/python3.13/site-packages/litellm/proxy/pass_through_endpoints/streaming_handler.pychunk_processor+PassThroughStreamingHandler.chunk_processor   s     	%'I'335 e  '5
  ||~H+OO(;4S'!-!3"/)'% P 	  	 &&)CCF8'LM	sC   B<B 979B 9AB B<
B9#B44B99B<r   r   c                   #    [         R                  U5      nSn	0 n
U[        R                  :X  a&  [        R
                  " U UUUUUUUS9nUS   n	US   n
O9U[        R                  :X  a%  [        R                  " U UUUUUUUS9nUS   n	US   n
U	c  [        SU 3S9n	[        R                  " U R                  U	UUS4S9R                  5         U R                  " S
U	UUSS	.U
D6I Sh  vN   g N7f)zz
Route the logging for the collected chunks to the appropriate handler

Supported endpoint types:
- Anthropic
- Vertex AI
N)r   r   r   r   r   r   
all_chunksr   resultkwargsz8cannot parse chunks to standard response object. Chunks=)r   F)targetargs)r,   r   r   	cache_hit )r   _convert_raw_bytes_to_str_linesr   	ANTHROPICr   *_handle_logging_anthropic_collected_chunks	VERTEX_AIr   '_handle_logging_vertex_collected_chunksr	   	threadingThreadsuccess_handlerstartasync_success_handler)r   r   r   r   r   r   r   r   r+    standard_logging_response_objectr-   ,anthropic_passthrough_logging_handler_result)vertex_passthrough_logging_handler_results                r'   r!   ?PassThroughStreamingHandler._route_streaming_logging_to_handler@   s[    $ 1PP


  	) L222;]  <I  <I$70O#)+%%!	<8 =XF - B(KFl444/WW(;4S'!-"/))%	 6 :(C - ?xHF+3/PST^S_`0, 	&660		
 %'!77 
3!	

 
 	
 	
s   C'C1)C/*C1returnc                     SR                  U 5      R                  S5      nUR                  S5       Vs/ s H)  o"R                  5       (       d  M  UR                  5       PM+     nnU$ s  snf )z
Converts a list of raw bytes into a list of string lines, similar to aiter_lines()

Args:
    raw_bytes: List of bytes chunks from aiter.bytes()

Returns:
    List of string lines, with each line being a complete data: {} chunk
    zutf-8
)joindecodesplitstrip)r   combined_strlineliness       r'   r2   ;PassThroughStreamingHandler._convert_raw_bytes_to_str_lines   sY     xx	*11': +7*<*<T*BS*B$jjl*BS Ts   A(A(r1   N)__name__
__module____qualname____firstlineno__staticmethodhttpxResponser   dictLiteLLMLoggingObjr   r   r   r$   r(   r   bytesr!   r2   __static_attributes__r1   rB   r'   r   r      s    $..$tn$ /$ $	$
 $ *D$ $ $L L
.L
)CL
 L
 	L

 $L
 L
 ;L
 L
 L
\ 4; 49  rB   r   )r   r7   r   typingr   r   rQ   litellm._loggingr   *litellm.litellm_core_utils.litellm_loggingr   rT   litellm.proxy._typesr   litellm.types.utilsr	   ;llm_provider_handlers.anthropic_passthrough_logging_handlerr   8llm_provider_handlers.vertex_passthrough_logging_handlerr   r9   r   typesr   r   r1   rB   r'   <module>r_      s>       !  1 S G A 8 I IrB   