Ë
    tPêjO-  ã                   óH   — d dl Z d dlmZmZ d dlZddlmZmZ  G d„ d«      Zy)é    N)ÚAnyÚFinalé   )ÚNotFoundErrorÚUnauthorizedErrorc                   ó  — e Zd Zddededz  defd„Zdeeef   fd„Zddede	eee
f      ej                  z  fd	„Z		 	 dd
edeee
f   deee
f   dz  dedeee
f   ej                  z  f
d„Zddededeee
f   ej                  z  fd„Z	 	 	 ddedz  d
edz  dedeee
f   ej                  z  fd„Zddedej                  eee
f      ej                  z  fd„Z	 	 ddedeee
f   deee
f   dz  dedeee
f   ej                  z  f
d„Zy)ÚModelsManagementClientNÚbase_urlÚapi_keyÚtimeoutc                 óL   — |j                  d«      | _        || _        || _        y)aa  
        Initialize the ModelsManagementClient.

        Args:
            base_url (str): The base URL of the LiteLLM proxy server (e.g., "http://localhost:8000")
            api_key (Optional[str]): API key for authentication. If provided, it will be sent as a Bearer token.
            timeout (int): Request timeout in seconds (default: 30)
        ú/N)ÚrstripÚ	_base_urlÚ_api_keyÚ_timeout)Úselfr
   r   r   s       ú`/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/proxy/client/models.pyÚ__init__zModelsManagementClient.__init__
   s"   € ð "Ÿ™¨Ó-ˆŒØˆŒØˆ�ó    Úreturnc                 óF   — i }| j                   rd| j                   › �|d<   |S )z¬
        Get the headers for API requests, including authorization if api_key is set.

        Returns:
            Dict[str, str]: Headers to use for API requests
        zBearer ÚAuthorization)r   )r   Úheaderss     r   Ú_get_headersz#ModelsManagementClient._get_headers   s*   € ð ˆØ�=Š=Ø)0°·±°Ð'@ˆG�OÑ$Øˆr   Úreturn_requestc                 óÎ  — | j                   › d�}t        j                  d|| j                  «       ¬«      }|r|S t        j                  «       }	 |j                  |j                  «       | j                  ¬«      }|j                  «        |j                  «       d   S # t        j                  j                  $ r*}|j                  j                  dk(  rt        |«      ‚‚ d}~ww xY w)a‰  
        Get the list of models supported by the server.

        Args:
            return_request (bool): If True, returns the prepared request object instead of executing it.
                                 Useful for inspection or modification before sending.

        Returns:
            Union[List[Dict[str, Any]], requests.Request]: Either a list of model information dictionaries
            or a prepared request object if return_request is True.

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            requests.exceptions.RequestException: If the request fails with any other error
        z/modelsÚGET©r   ©r   Údataé‘  N©r   ÚrequestsÚRequestr   ÚSessionÚsendÚpreparer   Úraise_for_statusÚjsonÚ
exceptionsÚ	HTTPErrorÚresponseÚstatus_coder   ©r   r   ÚurlÚrequestÚsessionr-   Úes          r   ÚlistzModelsManagementClient.list#   sÅ   € ð  Ÿ™Ð' wÐ/ˆÜ!×)Ñ)¨%°¸d×>OÑ>OÓ>QÔRˆáØˆNô "×)Ñ)Ó+ˆð	Ø%Ÿl™l¨7¯?©?Ó+<ÀdÇmÁm˜lÓTˆHØ×%Ñ%Ô'Ø—=‘=“? 6Ñ*Ð*øÜ×"Ñ"×,Ñ,ò 	Ø�z‰z×%Ñ%¨Ò,Ü'¨Ó*Ð*Øûð	úó   ÁAB ÂC$Â:%CÃC$Ú
model_nameÚmodel_paramsÚ
model_infoc                 óâ  — | j                   › d�}||dœ}|r||d<   t        j                  d|| j                  «       |¬«      }|r|S t        j                  «       }	 |j                  |j                  «       | j                  ¬«      }	|	j                  «        |	j                  «       S # t        j                  j                  $ r*}
|
j                  j                  dk(  rt        |
«      ‚‚ d}
~
ww xY w)	a  
        Add a new model to the proxy.

        Args:
            model_name (str): Name of the model to add
            model_params (Dict[str, Any]): Parameters for the model (e.g., model type, api_base, api_key)
            model_info (Optional[Dict[str, Any]]): Additional information about the model
            return_request (bool): If True, returns the prepared request object instead of executing it

        Returns:
            Union[Dict[str, Any], requests.Request]: Either the response from the server or
            a prepared request object if return_request is True

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            requests.exceptions.RequestException: If the request fails with any other error
        z
/model/new)r6   Úlitellm_paramsr8   ÚPOST©r   r*   r    r"   Nr#   )r   r6   r7   r8   r   r0   r!   r1   r2   r-   r3   s              r   ÚnewzModelsManagementClient.newD   sá   € ð0 Ÿ™Ð' zÐ2ˆð %Ø*ñ
ˆñ Ø!+ˆD�Ñä!×)Ñ)¨&°#¸t×?PÑ?PÓ?RÐY]Ô^ˆáØˆNô "×)Ñ)Ó+ˆð	Ø%Ÿl™l¨7¯?©?Ó+<ÀdÇmÁm˜lÓTˆHØ×%Ñ%Ô'Ø—=‘=“?Ð"øÜ×"Ñ"×,Ñ,ò 	Ø�z‰z×%Ñ%¨Ò,Ü'¨Ó*Ð*Øûð	ús   ÁA
B' Â'C.Ã%C)Ã)C.Úmodel_idc                 óf  — | j                   › d�}d|i}t        j                  d|| j                  «       |¬«      }|r|S t        j                  «       }	 |j                  |j                  «       | j                  ¬«      }|j                  «        |j                  «       S # t        j                  j                  $ rt}|j                  j                  dk(  rt        |«      ‚|j                  j                  dk(  s&d|j                  j                  j!                  «       v rt#        |«      ‚‚ d	}~ww xY w)
aÞ  
        Delete a model from the proxy.

        Args:
            model_id (str): ID of the model to delete (e.g., "2f23364f-4579-4d79-a43a-2d48dd551c2e")
            return_request (bool): If True, returns the prepared request object instead of executing it

        Returns:
            Union[Dict[str, Any], requests.Request]: Either the response from the server or
            a prepared request object if return_request is True

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            NotFoundError: If the request fails with a 404 status code or indicates the model was not found
            requests.exceptions.RequestException: If the request fails with any other error
        z/model/deleteÚidr;   r<   r    r"   é”  ú	not foundN©r   r$   r%   r   r&   r'   r(   r   r)   r*   r+   r,   r-   r.   r   ÚtextÚlowerr   )	r   r>   r   r0   r!   r1   r2   r-   r3   s	            r   ÚdeletezModelsManagementClient.deleteu   s  € ð" Ÿ™Ð' }Ð5ˆØ˜XÐ&ˆä!×)Ñ)¨&°#¸t×?PÑ?PÓ?RÐY]Ô^ˆáØˆNô "×)Ñ)Ó+ˆð		Ø%Ÿl™l¨7¯?©?Ó+<ÀdÇmÁm˜lÓTˆHØ×%Ñ%Ô'Ø—=‘=“?Ð"øÜ×"Ñ"×,Ñ,ò 	Ø�z‰z×%Ñ%¨Ò,Ü'¨Ó*Ð*Ø�z‰z×%Ñ%¨Ò,°¸q¿z¹z¿¹×?TÑ?TÓ?VÑ0VÜ# AÓ&Ð&Øûð	ús   ÁA
B ÂD0Â<A/D+Ä+D0c                 ó   — |€|�|�|�t        d«      ‚|r0| j                  d¬«      }t        |t        j                  «      sJ ‚|S | j                  «       }t        |t
        «      sJ ‚|D ]C  }|r$|j                  di «      j                  d«      |k(  s|sŒ,|j                  d«      |k(  sŒA|c S  |rd|› d�}n|rd	|› d�}nd
}t        t        j                  j                  |t        j                  «       ¬«      «      ‚)aN  
        Get information about a specific model by its ID or name.

        Args:
            model_id (Optional[str]): ID of the model to retrieve
            model_name (Optional[str]): Name of the model to retrieve
            return_request (bool): If True, returns the prepared request object instead of executing it

        Returns:
            Union[Dict[str, Any], requests.Request]: Either the model information from the server or
            a prepared request object if return_request is True

        Raises:
            ValueError: If neither model_id nor model_name is provided, or if both are provided
            UnauthorizedError: If the request fails with a 401 status code
            NotFoundError: If the model is not found
            requests.exceptions.RequestException: If the request fails with any other error
        z6Exactly one of model_id or model_name must be providedT)r   r8   r@   r6   zModel with id=z
 not foundzModel with model_name=z"Unknown error trying to find model)r-   )Ú
ValueErrorÚinfoÚ
isinstancer$   r%   r4   Úgetr   r+   r,   ÚResponse)r   r>   r6   r   ÚresultÚmodelsÚmodelÚmsgs           r   rK   zModelsManagementClient.get›   s  € ð0 Ð Ð!3¸Ð9MÐR\ÐRhÜÐUÓVÐVñ Ø ŸI™I°T˜IÓ:ˆFÜ˜f¤h×&6Ñ&6Ô7Ð7Ð7ØˆMð Ÿ	™	›ˆÜ˜&¤$Ô'Ð'Ð'ð ò 	ˆEÙ˜UŸY™Y |°RÓ8×<Ñ<¸TÓBÀhÒNÚ˜uŸy™y¨Ó6¸*ÓDà’ð		ñ Ø" 8 *¨JÐ7‰CÙØ*¨:¨,°jÐA‰Cà6ˆCÜÜ×Ñ×)Ñ)ØÜ!×*Ñ*Ó,ð *ó ó
ð 	
r   c                 óÎ  — | j                   › d�}t        j                  d|| j                  «       ¬«      }|r|S t        j                  «       }	 |j                  |j                  «       | j                  ¬«      }|j                  «        |j                  «       d   S # t        j                  j                  $ r*}|j                  j                  dk(  rt        |«      ‚‚ d}~ww xY w)a;  
        Get detailed information about all models from the server.

        Args:
            return_request (bool): If True, returns the prepared request object instead of executing it

        Returns:
            Union[List[Dict[str, Any]], requests.Request]: Either a list of model information dictionaries
            or a prepared request object if return_request is True

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            requests.exceptions.RequestException: If the request fails with any other error
        z/v1/model/infor   r   r    r!   r"   Nr#   r/   s          r   rI   zModelsManagementClient.infoÕ   sÅ   € ð Ÿ™Ð' ~Ð6ˆÜ!×)Ñ)¨%°¸d×>OÑ>OÓ>QÔRˆáØˆNô "×)Ñ)Ó+ˆð	Ø%Ÿl™l¨7¯?©?Ó+<ÀdÇmÁm˜lÓTˆHØ×%Ñ%Ô'Ø—=‘=“? 6Ñ*Ð*øÜ×"Ñ"×,Ñ,ò 	Ø�z‰z×%Ñ%¨Ò,Ü'¨Ó*Ð*Øûð	úr5   c                 óv  — | j                   › d�}||dœ}|r||d<   t        j                  d|| j                  «       |¬«      }|r|S t        j                  «       }	 |j                  |j                  «       | j                  ¬«      }	|	j                  «        |	j                  «       S # t        j                  j                  $ rt}
|
j                  j                  dk(  rt        |
«      ‚|
j                  j                  dk(  s&d	|
j                  j                  j!                  «       v rt#        |
«      ‚‚ d
}
~
ww xY w)aK  
        Update an existing model's configuration.

        Args:
            model_id (str): ID of the model to update
            model_params (Dict[str, Any]): New parameters for the model (e.g., model type, api_base, api_key)
            model_info (Optional[Dict[str, Any]]): Additional information about the model
            return_request (bool): If True, returns the prepared request object instead of executing it

        Returns:
            Union[Dict[str, Any], requests.Request]: Either the response from the server or
            a prepared request object if return_request is True

        Raises:
            UnauthorizedError: If the request fails with a 401 status code
            NotFoundError: If the model is not found
            requests.exceptions.RequestException: If the request fails with any other error
        z/model/update)r@   r:   r8   r;   r<   r    r"   rA   rB   NrC   )r   r>   r7   r8   r   r0   r!   r1   r2   r-   r3   s              r   ÚupdatezModelsManagementClient.updateõ   s  € ð2 Ÿ™Ð' }Ð5ˆð Ø*ñ
ˆñ Ø!+ˆD�Ñä!×)Ñ)¨&°#¸t×?PÑ?PÓ?RÐY]Ô^ˆáØˆNô "×)Ñ)Ó+ˆð		Ø%Ÿl™l¨7¯?©?Ó+<ÀdÇmÁm˜lÓTˆHØ×%Ñ%Ô'Ø—=‘=“?Ð"øÜ×"Ñ"×,Ñ,ò 	Ø�z‰z×%Ñ%¨Ò,Ü'¨Ó*Ð*Ø�z‰z×%Ñ%¨Ò,°¸q¿z¹z¿¹×?TÑ?TÓ?VÑ0VÜ# AÓ&Ð&Øûð	ús   ÁA
B' Â'D8ÃA/D3Ä3D8)Né   )F)NF)NNF)Ú__name__Ú
__module__Ú__qualname__ÚstrÚintr   Údictr   Úboolr4   r   r$   r%   r=   rF   rK   ÚbuiltinsrI   rS   © r   r   r	   r	   	   sÝ  „ ñ  ð  ¨s°T©zð  È3ó  ð
˜d 3¨ 8™nó 
ñ 4ð °D¸¸cÀ3¸h¹Ñ4HÈ8×K[ÑK[Ñ4[ó ðJ -1Ø$ñ/àð/ð ˜3 ˜8‘nð/ð ˜˜c˜‘N TÑ)ð	/ð
 ð/ð 
ˆc�3ˆh‰˜(×*Ñ*Ñ	*ó/ñb$˜sð $°Dð $ÀTÈ#ÈsÈ(Á^ÐV^×VfÑVfÑEfó $ðP  $Ø!%Ø$ñ	8
à˜‘*ð8
ð ˜$‘Jð8
ð ð	8
ð
 
ˆc�3ˆh‰˜(×*Ñ*Ñ	*ó8
ñt 4ð °H·M±MÀ$ÀsÈCÀxÁ.Ñ4QÐT\×TdÑTdÑ4dó ðH -1Ø$ñ2àð2ð ˜3 ˜8‘nð2ð ˜˜c˜‘N TÑ)ð	2ð
 ð2ð 
ˆc�3ˆh‰˜(×*Ñ*Ñ	*ô2r   r	   )	r\   Útypingr   r   r$   r+   r   r   r	   r]   r   r   ú<module>r_      s   ðÛ ß ã ç 8÷^ò ^r   