o
    ưiɨ                     @   s  d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZmZmZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZmZm Z m!Z!m"Z" d d
l#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z*m+Z+ g dZ,e+							dMde-deee-ef  dee	e-  de
d deee-ef  deee-ef  deee-ef  de!fddZ.e							dNde-deee-ef  dee	e-  dee- dee- dee- de
d de
d deeee!f fdd Z/e							dNd!d"de-deee-ef  dee	e-  dee- dee- dee- de
d de
d! de!fd#d Z/e+										dOde-deee-ef  dee	e-  dee- dee- dee- de
d deee-ef  deee-ef  deee-ef  dee!eeee!f f fd$d Z/e+								dPd%ee- d&ee0 d'ee- de
d deee-ef  deee-ef  deee-ef  de fd(d)Z1e								dQd%ee- d&ee0 d'ee- dee- dee- dee- de
d d)e
d deeee f fd*d+Z2e								dQd!d,d%ee- d&ee0 d'ee- dee- dee- dee- de
d d)e
d! de fd-d+Z2e+											dRd%ee- d&ee0 d'ee- dee- dee- dee- de
d deee-ef  deee-ef  deee-ef  dee eeee f f fd.d+Z2e+					dSd/e-de
d deee-ef  deee-ef  deee-ef  de!fd0d1Z3e					dTd/e-dee- dee- dee- de
d d1e
d deeee!f fd2d3Z4e					dTd!d4d/e-dee- dee- dee- de
d d1e
d! de!fd5d3Z4e+								dUd/e-dee- dee- dee- de
d deee-ef  deee-ef  deee-ef  dee!eeee!f f fd6d3Z4e+					dSd/e-de
d deee-ef  deee-ef  deee-ef  de"fd7d8Z5e					dTd/e-dee- dee- dee- de
d d8e
d deeee"f fd9d:Z6e					dTd!d;d/e-dee- dee- dee- de
d d8e
d! de"fd<d:Z6e+								dUd/e-dee- dee- dee- de
d deee-ef  deee-ef  deee-ef  dee"eeee"f f fd=d:Z6e+								dPd/e-d%ee- d&ee0 d'ee- de
d deee-ef  deee-ef  deee-ef  defd>d?Z7e								dQd/e-d%ee- d&ee0 d'ee- dee- dee- dee- de
d d?e
d deeeef fd@dAZ8e								dQd!dBd/e-d%ee- d&ee0 d'ee- dee- dee- dee- de
d d?e
d! defdCdAZ8e+											dRd/e-d%ee- d&ee0 d'ee- dee- dee- dee- de
d deee-ef  deee-ef  deee-ef  deeeeeef f fdDdAZ8e+					dSd/e-dEe$de
d deee-ef  deee-ef  deee-ef  defdFdGZ9e					dTd/e-dEe$dee- dee- dee- de
d dGe
d deeeef fdHdIZ:e					dTd!dJd/e-dEe$dee- dee- dee- de
d dGe
d! defdKdIZ:e+								dUd/e-dEe$dee- dee- dee- de
d deee-ef  deee-ef  deee-ef  deeeeeef f fdLdIZ:dS )V    N)partial)Any	CoroutineDictListLiteralOptionalUnionoverload)request_timeout)ContainerRequestUtils)Logging)BaseContainerConfig)base_llm_http_handler)$ContainerCreateOptionalRequestParamsContainerFileListResponseContainerFileObject"ContainerListOptionalRequestParamsContainerListResponseContainerObjectDeleteContainerResult)	FileTypes)GenericLiteLLMParams)	CallTypes)ProviderConfigManagerclient)acreate_containeradelete_containeralist_container_filesalist_containersaretrieve_containeraupload_container_filecreate_containerdelete_containerlist_container_fileslist_containersretrieve_containerupload_container_fileX  openainameexpires_afterfile_idscustom_llm_providerextra_headersextra_query
extra_bodyreturnc                       t  }	z>t }
d|d< ttf| |||||||d|}t }t|j|}|
d|I dH }t	|r>|I dH }|W S |}|W S  t
yX } z
tjd|||	|dd}~ww )a4  Asynchronously calls the `create_container` function with the given arguments and keyword arguments.

    Parameters:
    - `name` (str): Name of the container to create
    - `expires_after` (Optional[Dict[str, Any]]): Container expiration time settings
    - `file_ids` (Optional[List[str]]): IDs of files to copy to the container
    - `timeout` (int): Request timeout in seconds
    - `custom_llm_provider` (Optional[Literal["openai"]]): The LLM provider to use
    - `extra_headers` (Optional[Dict[str, Any]]): Additional headers
    - `extra_query` (Optional[Dict[str, Any]]): Additional query parameters
    - `extra_body` (Optional[Dict[str, Any]]): Additional body parameters
    - `kwargs` (dict): Additional keyword arguments

    Returns:
    - `response` (ContainerObject): The created container object
    T
async_call)r*   r+   r,   timeoutr-   r.   r/   r0   N modelr-   Zoriginal_exceptionZcompletion_kwargsextra_kwargs)localsasyncioget_event_loopr   r"   contextvarscopy_contextrunrun_in_executoriscoroutine	Exceptionlitellmexception_type)r*   r+   r,   r4   r-   r.   r/   r0   kwargs
local_varsloopfuncctxfunc_with_contextinit_responseresponsee rM   N/home/app/Keep/.python/lib/python3.10/site-packages/litellm/containers/main.pyr   +   sJ   


r   api_keyapi_baseapi_versionTc          
      K      d S NrM   
r*   r+   r,   r4   rO   rP   rQ   r-   r   rD   rM   rM   rN   r"   s      r"   F)r   c          
      K   rR   rS   rM   rT   rM   rM   rN   r"      rU   c              
   K   s:  t  }z|d}|d}|dddu }|d}|dur3t|tr)t|}tdi |}|W S td|||d|}t	j
t|d	}|du rRtd
| || t|}tj||d}|jdt|d|i||d tjj|_tj| ||||||pt|dW S  ty } z
tjd||||dd}~ww )a  Create a container using the OpenAI Container API.

    Currently supports OpenAI

    Example:
    ```python
    import litellm
    
    response = litellm.create_container(
        name="My Container",
        custom_llm_provider="openai",
    )
    print(response)
    ```
    litellm_logging_objlitellm_call_idr3   FTmock_responseNrO   rP   rQ   providerz+container operations are not supported for )container_provider_config container_create_optional_paramsr5   r7   Zoptional_paramslitellm_paramsr-   )r*   container_create_request_paramsr\   r_   logging_objr.   r4   	_is_asyncr6   rM   )r9   popget
isinstancestrjsonloadsr   r   r   get_provider_container_configrB   LlmProviders
ValueErrorupdater   Z-get_requested_container_create_optional_paramZ$get_optional_params_container_createupdate_environment_variablesdictr   r"   value	call_typer   Zcontainer_create_handlerDEFAULT_REQUEST_TIMEOUTrA   rC   )r*   r+   r,   r4   rO   rP   rQ   r-   r.   r/   r0   rD   rE   rV   rW   rb   rX   rK   r_   r\   r]   r`   rL   rM   rM   rN   r"      s|   #






afterlimitorderc                    r2   )a  Asynchronously list containers.

    Parameters:
    - `after` (Optional[str]): A cursor for pagination
    - `limit` (Optional[int]): Number of items to return (1-100, default 20)
    - `order` (Optional[str]): Sort order ('asc' or 'desc', default 'desc')
    - `timeout` (int): Request timeout in seconds
    - `custom_llm_provider` (Literal["openai"]): The LLM provider to use
    - `extra_headers` (Optional[Dict[str, Any]]): Additional headers
    - `extra_query` (Optional[Dict[str, Any]]): Additional query parameters
    - `extra_body` (Optional[Dict[str, Any]]): Additional body parameters
    - `kwargs` (dict): Additional keyword arguments

    Returns:
    - `response` (ContainerListResponse): The list of containers
    Tr3   )rr   rs   rt   r4   r-   r.   r/   r0   Nr5   r6   )r9   r:   r;   r   r%   r<   r=   r>   r?   r@   rA   rB   rC   )rr   rs   rt   r4   r-   r.   r/   r0   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rM   rN   r     sJ   


r   c          
      K   rR   rS   rM   
rr   rs   rt   r4   rO   rP   rQ   r-   r   rD   rM   rM   rN   r%   S  rU   r%   )r   c          
      K   rR   rS   rM   ru   rM   rM   rN   r%   d  rU   c                 K   s&  t  }zy|d}|d}|dddu }|d}|dur3t|tr)t|}tdi |}|W S td|||d|}t	j
t|d	}|du rRtd
| t|}|jdt|d|i||d tjj|_tj|||| ||||	|pxt|d
W S  ty } z
tjd||||dd}~ww )zSList containers using the OpenAI Container API.

    Currently supports OpenAI
    rV   rW   r3   FTrX   NrY   rZ   2Container provider config not found for provider: r5   r^   )
r\   r_   ra   rr   rs   rt   r.   r/   r4   rb   r6   rM   )r9   rc   rd   re   rf   rg   rh   r   r   r   ri   rB   rj   rk   r   Z+get_requested_container_list_optional_paramrm   rn   r   r%   ro   rp   r   Zcontainer_list_handlerrq   rA   rC   )rr   rs   rt   r4   rO   rP   rQ   r-   r.   r/   r0   rD   rE   rV   rW   rb   rX   rK   r_   r\   Zcontainer_list_optional_paramsrL   rM   rM   rN   r%   w  st   





container_idc              
         t  }z<t }d|d< ttf| |||||d|}	t }
t|
j|	}|d|I dH }t	|r<|I dH }|W S |}|W S  t
yV } z
tjd||||dd}~ww )aK  Asynchronously retrieve a container.

    Parameters:
    - `container_id` (str): The ID of the container to retrieve
    - `timeout` (int): Request timeout in seconds
    - `custom_llm_provider` (Literal["openai"]): The LLM provider to use
    - `extra_headers` (Optional[Dict[str, Any]]): Additional headers
    - `extra_query` (Optional[Dict[str, Any]]): Additional query parameters
    - `extra_body` (Optional[Dict[str, Any]]): Additional body parameters
    - `kwargs` (dict): Additional keyword arguments

    Returns:
    - `response` (ContainerObject): The container object
    Tr3   rw   r4   r-   r.   r/   r0   Nr5   r6   )r9   r:   r;   r   r&   r<   r=   r>   r?   r@   rA   rB   rC   rw   r4   r-   r.   r/   r0   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rM   rN   r      F   

r    c                K   rR   rS   rM   rw   r4   rO   rP   rQ   r-   r    rD   rM   rM   rN   r&        r&   )r    c                K   rR   rS   rM   r|   rM   rM   rN   r&   *  r}   c	              
   K     t  }
zn|	d}|	d}|	dddu }|	d}|dur3t|tr)t|}tdi |}|W S td|||d|	}t	j
t|d	}|du rRtd
| |jdi d|i|d tjj|_tj| ||||||pmt|dW S  ty } z
tjd|||
|	dd}~ww )zXRetrieve a container using the OpenAI Container API.

    Currently supports OpenAI
    rV   rW   r3   FTrX   NrY   rZ   rv   r5   r^   rw   r\   r_   ra   r.   r/   r4   rb   r6   rM   )r9   rc   rd   re   rf   rg   rh   r   r   r   ri   rB   rj   rk   rm   r   r&   ro   rp   r   Zcontainer_retrieve_handlerrq   rA   rC   rw   r4   rO   rP   rQ   r-   r.   r/   r0   rD   rE   rV   rW   rb   rX   rK   r_   r\   rL   rM   rM   rN   r&   ;  h   






c              
      rx   )aL  Asynchronously delete a container.

    Parameters:
    - `container_id` (str): The ID of the container to delete
    - `timeout` (int): Request timeout in seconds
    - `custom_llm_provider` (Literal["openai"]): The LLM provider to use
    - `extra_headers` (Optional[Dict[str, Any]]): Additional headers
    - `extra_query` (Optional[Dict[str, Any]]): Additional query parameters
    - `extra_body` (Optional[Dict[str, Any]]): Additional body parameters
    - `kwargs` (dict): Additional keyword arguments

    Returns:
    - `response` (DeleteContainerResult): The deletion result
    Tr3   ry   Nr5   r6   )r9   r:   r;   r   r#   r<   r=   r>   r?   r@   rA   rB   rC   rz   rM   rM   rN   r     r{   r   c                K   rR   rS   rM   rw   r4   rO   rP   rQ   r-   r   rD   rM   rM   rN   r#     r}   r#   )r   c                K   rR   rS   rM   r   rM   rM   rN   r#     r}   c	              
   K   r~   )zVDelete a container using the OpenAI Container API.

    Currently supports OpenAI
    rV   rW   r3   FTrX   NrY   rZ   rv   r5   r^   r   r6   rM   )r9   rc   rd   re   rf   rg   rh   r   r   r   ri   rB   rj   rk   rm   r   r#   ro   rp   r   Zcontainer_delete_handlerrq   rA   rC   r   rM   rM   rN   r#     r   c	                    s   t  }
z?t }d|	d< ttf| ||||||||d	|	}t }t|j|}|d|I dH }t	|r?|I dH }|W S |}|W S  t
yY } z
tjd|||
|	dd}~ww )a%  Asynchronously list files in a container.

    Parameters:
    - `container_id` (str): The ID of the container
    - `after` (Optional[str]): A cursor for pagination
    - `limit` (Optional[int]): Number of items to return (1-100, default 20)
    - `order` (Optional[str]): Sort order ('asc' or 'desc', default 'desc')
    - `timeout` (int): Request timeout in seconds
    - `custom_llm_provider` (Literal["openai"]): The LLM provider to use
    - `extra_headers` (Optional[Dict[str, Any]]): Additional headers
    - `extra_query` (Optional[Dict[str, Any]]): Additional query parameters
    - `extra_body` (Optional[Dict[str, Any]]): Additional body parameters
    - `kwargs` (dict): Additional keyword arguments

    Returns:
    - `response` (ContainerFileListResponse): The list of container files
    Tr3   )	rw   rr   rs   rt   r4   r-   r.   r/   r0   Nr5   r6   )r9   r:   r;   r   r$   r<   r=   r>   r?   r@   rA   rB   rC   )rw   rr   rs   rt   r4   r-   r.   r/   r0   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rM   rN   r   O  sL   

r   c	                K   rR   rS   rM   rw   rr   rs   rt   r4   rO   rP   rQ   r-   r   rD   rM   rM   rN   r$        r$   )r   c	                K   rR   rS   rM   r   rM   rM   rN   r$     r   c                 K   s   t  }zv|d}|d}|dddu }|d}|dur3t|tr)t|}tdi |}|W S td|||d|}t	j
t|d	}|du rRtd
| |jd| |||dd|i|d tjj|_tj| |||||||	|
|put|dW S  ty } z
tjd||||dd}~ww )z]List files in a container using the OpenAI Container API.

    Currently supports OpenAI
    rV   rW   r3   FTrX   NrY   rZ   rv   r5   )rw   rr   rs   rt   r^   )rw   r\   r_   ra   rr   rs   rt   r.   r/   r4   rb   r6   rM   )r9   rc   rd   re   rf   rg   rh   r   r   r   ri   rB   rj   rk   rm   r   r$   ro   rp   r   Zcontainer_file_list_handlerrq   rA   rC   )rw   rr   rs   rt   r4   rO   rP   rQ   r-   r.   r/   r0   rD   rE   rV   rW   rb   rX   rK   r_   r\   rL   rM   rM   rN   r$     sn   






filec              
      s   t  }z=t }	d|d< ttf| ||||||d|}
t }t|j|
}|	d|I dH }t	|r=|I dH }|W S |}|W S  t
yW } z
tjd||||dd}~ww )a$  Asynchronously upload a file to a container.

    This endpoint allows uploading files directly to a container session,
    supporting various file types like CSV, Excel, Python scripts, etc.

    Parameters:
    - `container_id` (str): The ID of the container to upload the file to
    - `file` (FileTypes): The file to upload. Can be:
        - A tuple of (filename, content, content_type)
        - A tuple of (filename, content)
        - A file-like object with read() method
        - Bytes
        - A string path to a file
    - `timeout` (int): Request timeout in seconds
    - `custom_llm_provider` (Literal["openai"]): The LLM provider to use
    - `extra_headers` (Optional[Dict[str, Any]]): Additional headers
    - `extra_query` (Optional[Dict[str, Any]]): Additional query parameters
    - `extra_body` (Optional[Dict[str, Any]]): Additional body parameters
    - `kwargs` (dict): Additional keyword arguments

    Returns:
    - `response` (ContainerFileObject): The uploaded file object

    Example:
    ```python
    import litellm

    # Upload a CSV file
    response = await litellm.aupload_container_file(
        container_id="container_abc123",
        file=("data.csv", open("data.csv", "rb").read(), "text/csv"),
        custom_llm_provider="openai",
    )
    print(response)
    ```
    Tr3   )rw   r   r4   r-   r.   r/   r0   Nr5   r6   )r9   r:   r;   r   r'   r<   r=   r>   r?   r@   rA   rB   rC   )rw   r   r4   r-   r.   r/   r0   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rM   rN   r!     sH   /	

r!   c          	      K   rR   rS   rM   	rw   r   r4   rO   rP   rQ   r-   r!   rD   rM   rM   rN   r'   p     r'   )r!   c          	      K   rR   rS   rM   r   rM   rM   rN   r'     r   c
                 K   s$  ddl m} t }zr|
d}|
d}|
dddu }|
d}|d	ur9t|tr/t|}t	di |}|W S t
d|||d
|
}tjt|d}|d	u rXtd| |jdd| id|i|d tjj|_|jd||||||put|| |d
W S  ty } z
tjd||||
dd	}~ww )a  Upload a file to a container using the OpenAI Container API.

    This endpoint allows uploading files directly to a container session,
    supporting various file types like CSV, Excel, Python scripts, JSON, etc.
    This is useful when /chat/completions or /responses sends files to the
    container but the input file type is limited to PDF. This endpoint lets
    you work with other file types.

    Currently supports OpenAI

    Example:
    ```python
    import litellm

    # Upload a CSV file
    response = litellm.upload_container_file(
        container_id="container_abc123",
        file=("data.csv", open("data.csv", "rb").read(), "text/csv"),
        custom_llm_provider="openai",
    )
    print(response)

    # Upload a Python script
    response = litellm.upload_container_file(
        container_id="container_abc123",
        file=("script.py", b"print('hello world')", "text/x-python"),
        custom_llm_provider="openai",
    )
    print(response)
    ```
    r   )generic_container_handlerrV   rW   r3   FTrX   NrY   rZ   rv   r5   rw   r^   r'   )
Zendpoint_namer\   r_   ra   r.   r/   r4   rb   rw   r   r6   rM   )Z+litellm.llms.custom_httpx.container_handlerr   r9   rc   rd   re   rf   rg   rh   r   r   r   ri   rB   rj   rk   rm   r   r'   ro   rp   handlerq   rA   rC   )rw   r   r4   rO   rP   rQ   r-   r.   r/   r0   rD   r   rE   rV   rW   rb   rX   rK   r_   r\   rL   rM   rM   rN   r'     sn   0






)NNr(   r)   NNN)NNr(   NNNr)   )
NNr(   NNNr)   NNN)NNNr(   r)   NNN)NNNr(   NNNr)   )NNNr(   NNNr)   NNN)r(   r)   NNN)r(   NNNr)   )r(   NNNr)   NNN);r:   r<   rg   	functoolsr   typingr   r   r   r   r   r   r	   r
   rB   Zlitellm.constantsr   rq   Zlitellm.containers.utilsr   Z*litellm.litellm_core_utils.litellm_loggingr   ZLiteLLMLoggingObjZ/litellm.llms.base_llm.containers.transformationr   Zlitellm.mainr   Zlitellm.types.containers.mainr   r   r   r   r   r   r   Zlitellm.types.llms.openair   Zlitellm.types.routerr   Zlitellm.types.utilsr   Zlitellm.utilsr   r   __all__rf   r   r"   intr   r%   r    r&   r   r#   r   r$   r!   r'   rM   rM   rM   rN   <module>   sV   ($	
	
G





u	
E


c
?

	
Y
?

	
Y	F			
]	U				
