o
    ưis2                     @   s  d dl mZmZ d dlmZmZmZmZ d dlm	Z	 d dl
T d dlmZmZ d dlmZ d dlmZ d dlmZmZmZ e Zejd	eege	d
gdejdeege	d
gdeefdededefddZejd	eege	d
gdejdeege	d
gdeefdededefddZejdeege	d
gdejdeege	d
gdeefdedededefddZejdeege	d
gdejdeege	d
gdeefdedededefddZd dlm Z  e e dS )    )AnyDict)	APIRouterDependsRequestResponse)ORJSONResponse)*)UserAPIKeyAuthuser_api_key_auth)ProxyBaseLLMRequestProcessing)_read_request_body))get_custom_llm_provider_from_request_body,get_custom_llm_provider_from_request_headers*get_custom_llm_provider_from_request_queryz/v1/containers
containers)dependenciesresponse_classtagsz/containersrequestfastapi_responseuser_api_key_dictc              
      s&  ddl m}m}m}m}m}m}m}	m}
m	}m
}m} t| dI dH }t| dp6t| dp6t| dI dH p6d}||d< t|d}z:|jdi d| d	|d
|ddd|d|d|d|d|ddd|
d|d|d|	d|d|I dH W S  ty } z|j||||dI dH d}~ww )aH  
    Container creation endpoint for creating new containers.
    
    Follows the OpenAI Containers API spec:
    https://platform.openai.com/docs/api-reference/containers
    
    Example:
    ```bash
    curl -X POST "http://localhost:4000/v1/containers"         -H "Authorization: Bearer sk-1234"         -H "Content-Type: application/json"         -d '{
            "name": "My Container",
            "expires_after": {
                "anchor": "last_active_at",
                "minutes": 20
            }
        }'
    ```
    
    Or specify provider via header:
    ```bash
    curl -X POST "http://localhost:4000/v1/containers"         -H "Authorization: Bearer sk-1234"         -H "custom-llm-provider: azure"         -H "Content-Type: application/json"         -d '{
            "name": "My Container"
        }'
    ```
    r   general_settings
llm_routerproxy_configproxy_logging_objselect_data_generatoruser_api_baseuser_max_tokens
user_modeluser_request_timeoutuser_temperatureversionr   Nopenaicustom_llm_providerdatar   r   r   
route_typeZacreate_containerr   r   r   r   r   modelr    r"   r!   r   r   r#   er   r   r#    )litellm.proxy.proxy_serverr   r   r   r   r   r   r   r    r!   r"   r#   r   r   r   r   r   base_process_llm_request	Exception_handle_llm_api_exception)r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r(   r&   	processorr,   r-   r-   b/home/app/Keep/.python/lib/python3.10/site-packages/litellm/proxy/container_endpoints/endpoints.pycreate_container   sn   40


	
r4   c              
      s  ddl m}m}m}m}m}m}m}	m}
m	}m
}m} t| j}d|i}t| dp/t| dp/d}||d< t|d}z:|jdi d| d	|d
|ddd|d|d|d|d|ddd|
d|d|d|	d|d|I dH W S  ty } z|j||||dI dH d}~ww )a  
    Container list endpoint for retrieving a list of containers.
    
    Follows the OpenAI Containers API spec:
    https://platform.openai.com/docs/api-reference/containers
    
    Example:
    ```bash
    curl -X GET "http://localhost:4000/v1/containers?limit=20&order=desc"         -H "Authorization: Bearer sk-1234"
    ```
    
    Or specify provider via header or query param:
    ```bash
    curl -X GET "http://localhost:4000/v1/containers?custom_llm_provider=azure"         -H "Authorization: Bearer sk-1234"
    ```
    r   r   query_paramsr$   r%   r&   r'   r   r   r   r)   Zalist_containersr   r   r   r   r   r*   Nr    r"   r!   r   r   r#   r+   r-   )r.   r   r   r   r   r   r   r   r    r!   r"   r#   dictr5   r   r   r   r/   r0   r1   )r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r5   r(   r&   r2   r,   r-   r-   r3   list_containers   sl   4#



	
r7   z/v1/containers/{container_id}z/containers/{container_id}container_idc              
        ddl m}m}m}m}m}m}	m}
m}m	}m
}m} d|i}t| dp*t| dp*d}||d< t|d}z:|jdi d| d	|d
|ddd|d|d|d|d|ddd|d|d|d|
d|	d|I dH W S  ty } z|j||||dI dH d}~ww )a   
    Container retrieve endpoint for getting details of a specific container.
    
    Follows the OpenAI Containers API spec:
    https://platform.openai.com/docs/api-reference/containers
    
    Example:
    ```bash
    curl -X GET "http://localhost:4000/v1/containers/cntr_123"         -H "Authorization: Bearer sk-1234"
    ```
    
    Or specify provider via header:
    ```bash
    curl -X GET "http://localhost:4000/v1/containers/cntr_123"         -H "Authorization: Bearer sk-1234"         -H "custom-llm-provider: azure"
    ```
    r   r   r8   r$   r%   r&   r'   r   r   r   r)   Zaretrieve_containerr   r   r   r   r   r*   Nr    r"   r!   r   r   r#   r+   r-   r.   r   r   r   r   r   r   r   r    r!   r"   r#   r   r   r   r/   r0   r1   r   r8   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r(   r&   r2   r,   r-   r-   r3   retrieve_container   j   4%


	
r<   c              
      r9   )a  
    Container delete endpoint for deleting a specific container.
    
    Follows the OpenAI Containers API spec:
    https://platform.openai.com/docs/api-reference/containers
    
    Example:
    ```bash
    curl -X DELETE "http://localhost:4000/v1/containers/cntr_123"         -H "Authorization: Bearer sk-1234"
    ```
    
    Or specify provider via header:
    ```bash
    curl -X DELETE "http://localhost:4000/v1/containers/cntr_123"         -H "Authorization: Bearer sk-1234"         -H "custom-llm-provider: azure"
    ```
    r   r   r8   r$   r%   r&   r'   r   r   r   r)   Zadelete_containerr   r   r   r   r   r*   Nr    r"   r!   r   r   r#   r+   r-   r:   r;   r-   r-   r3   delete_container;  r=   r>   )!register_container_file_endpointsN)!typingr   r   Zfastapir   r   r   r   Zfastapi.responsesr   Zlitellm.proxy._typesZ$litellm.proxy.auth.user_api_key_authr
   r   Z'litellm.proxy.common_request_processingr   Z-litellm.proxy.common_utils.http_parsing_utilsr   Z0litellm.proxy.common_utils.openai_endpoint_utilsr   r   r   Zrouterpostr4   getr7   strr<   deleter>   Z1litellm.proxy.container_endpoints.handler_factoryr?   r-   r-   r-   r3   <module>   s   	_	Q
R
S