
    h                         d dl mZ d dlmZmZmZmZmZ ddlm	Z	 erd dl
mZ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)    )abstractmethod)TYPE_CHECKINGListOptionalTupleUnion   )BaseLLMModelInfo)URLHeadersResponse)Logging)CostResponseTypesBaseLLMExceptionc                   f   e Zd Zedededefd       Zdededee   ddfdZ	ed	ee   d
ee   dededee   dede
def   fd       Z	 d"dededee   d	edee   de
eee   f   fdZdededeedf   ddfdZdededddedddeded   fdZdee   dddedededed   fdZd ee   dee   fd!Zy)#BasePassthroughConfigendpointrequest_datareturnc                      y)z=
        Check if the request is a streaming request
        N )selfr   r   s      l/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/llms/base_llm/passthrough/transformation.pyis_streaming_requestz*BasePassthroughConfig.is_streaming_request   s    
 	    base_target_urlrequest_query_paramsr   c                    ddl m} ddl}|j                  |      j                  }|j                  d      sd|z   }|j                  |      }|j                  |      }|r'|j                   ||      j                  d            }|S )aQ  
        Helper function to add query params to the url
        Args:
            endpoint: str - the endpoint to add to the url
            base_target_url: str - the base url to add the endpoint to
            request_query_params: dict - the query params to add to the url
        Returns:
            str - the formatted url
        r   )	urlencodeN/)pathascii)query)urllib.parser    httpxr   r"   
startswith	copy_withencode)	r   r   r   r   r    r&   encoded_endpointbase_urlupdated_urls	            r   
format_urlz BasePassthroughConfig.format_url   s     	+ 99X.33  **3/"%55 99_-((.>(?%// 45<<WE 0 K r   api_baseapi_keymodellitellm_paramsc                      y)z
        Get the complete url for the request
        Returns:
            - complete_url: URL - the complete url for the request
            - base_target_url: str - the base url to add the endpoint to. Useful for auth headers.
        Nr   )r   r.   r/   r0   r   r   r1   s          r   get_complete_urlz&BasePassthroughConfig.get_complete_url;   s      	r   Nheadersc                 
    |dfS )a0  
        Some providers like Bedrock require signing the request. The sign request funtion needs access to `request_data` and `complete_url`
        Args:
            headers: dict
            optional_params: dict
            request_data: dict - the request body being sent in http request
            api_base: str - the complete url being sent in http request
        Returns:
            dict - the signed headers

        Update the headers with the signed headers in this function. The return values will be sent as headers in the http request.
        Nr   )r   r4   r1   r   r.   r0   s         r   sign_requestz"BasePassthroughConfig.sign_requestM   s    ( }r   error_messagestatus_coder   r   c                 $    ddl m}  ||||      S )Nr   r   )r8   messager4   ))litellm.llms.base_llm.chat.transformationr   )r   r7   r8   r4   r   s        r   get_error_classz%BasePassthroughConfig.get_error_classc   s     	O#]G
 	
r   custom_llm_providerhttpx_responser   logging_objLiteLLMLoggingObjr   c                      y Nr   )r   r0   r=   r>   r   r?   r   s          r   logging_non_streaming_responsez4BasePassthroughConfig.logging_non_streaming_responsel   s     	r   
all_chunkslitellm_logging_objc                      y rB   r   )r   rD   rE   r0   r=   r   s         r   handle_logging_collected_chunksz5BasePassthroughConfig.handle_logging_collected_chunksw   s     r   	raw_bytesc                     dj                  |      j                  d      }|j                  d      D cg c]#  }|j                         s|j                         % }}|S c c}w )a  
        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
        r   zutf-8
)joindecodesplitstrip)r   rH   combined_strlineliness        r   _convert_raw_bytes_to_str_linesz5BasePassthroughConfig._convert_raw_bytes_to_str_lines   sV     xx	*11': +7*<*<T*BS$djjlSS Ts   A 
A rB   )__name__
__module____qualname__r   strdictboolr   r   r-   r   r3   bytesr6   intr   r<   rC   r   rG   rR   r   r   r   r   r      s   S    "" " 'tn	"
 
"H 3- # 	
  'tn  
ucz	 .  $  tn	
  } 
tXe_$	%,
 
/2
=B4?=S
	
		 !	 #		
 	 )	 	 
%	&	I 1 	
 !  
%	&e c r   r   N)abcr   typingr   r   r   r   r   
base_utilsr
   r&   r   r   r   *litellm.litellm_core_utils.litellm_loggingr   r@   litellm.types.utilsr   chat.transformationr   r   r   r   r   <module>ra      s2     > > ),,W56B, Br   