
    h
                        d dl Zd dlmZ d dlZd dlZd dlZddlmZ  ej                         d        Z
e
j                          ej                  d       ej                  d       ej                  dd	ed
       ej                  dded       ej                  dddd      ej                  	 	 	 ddej                   dededee   dee   deedf   fd                                                 Zy)    N)Optional   )
HTTPClientc                       y)z.Make HTTP requests to the LiteLLM proxy serverN r       b/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/proxy/client/cli/commands/http.pyhttpr
      s     	r   methoduriz--dataz-dz1Data to send in the request body (as JSON string))typehelpz--jsonz-jz6JSON data to send in the request body (as JSON string)z--headerz-HTzDHTTP headers in 'key:value' format. Can be specified multiple times.)multipler   ctxdatajsonheader.c                 0   i }|D ]9  }	 |j                  dd      \  }}	|	j                         ||j                         <   ; d}
|r	 t        j                  |      }
d}|r	 t        j                  |      }t        | j                  d   | j                  d         }	 |j                  ||||
|	      }t        j                  |
       y# t        $ r t        j                  d| d      w xY w# t        $ r}t        j                  d|       d}~ww xY w# t        $ r |}Y w xY w# t        j                  j                  $ r}t        j                  d|j                   j"                   d       	 |j                   j%                         }t        j                  |
       t        j*                         # t
        j&                  $ rA t        j                  |j                   j(                  d       Y t        j*                         w xY wd}~ww xY w)a  Make an HTTP request to the LiteLLM proxy server

    METHOD: HTTP method (GET, POST, PUT, DELETE, etc.)
    URI: URI path (will be appended to base_url)

    Examples:
        litellm http request GET /models
        litellm http request POST /chat/completions -j '{"model": "gpt-4", "messages": [{"role": "user", "content": "Hello"}]}'
        litellm http request GET /health/test_connection -H "X-Custom-Header:value"
    :   zInvalid header format: z. Expected format: 'key:value'NzInvalid JSON format: base_urlapi_key)r   r   r   r   headers)r   zError: HTTP T)err)splitstrip
ValueErrorclickBadParameterjson_libloadsr   objrequestrich
print_jsonrequests
exceptions	HTTPErrorechoresponsestatus_coder   JSONDecodeErrortextAbort)r   r   r   r   r   r   r   hkeyvalue	json_dataerequest_dataclientr*   
error_bodys                   r	   r#   r#      s   R G	baJC#(;;=GCIIK   I	B t,I
 L	 #>>$/L
 
+SWWY-?@F>> " 
 	X&;  	b$$'>qcA_%`aa	b  	B$$'<QC%@AA	B  	 L	  (( 

\!**"8"8!9:E	2*JOO, kkm '' 	2JJqzzD1kkm	2sq   6C	C/  D ,D) 	#C,/	D8DDD&%D&)H.H50F9%H9>H7HHHH)NNr   )r   r    typingr   r   r$   r&   http_clientr   groupr
   commandargumentoptionstrpass_contextContexttupler#   r   r   r	   <module>rA      s;        % 	 	
 		<	 		A	 	O	 
  =	== 
= 3-	=
 3-= #s(O=    ,=r   