
    	]j                         d 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  ej                  e      Z G d d	ej                         Z G d
 dej                         Z G d dej&                        Zy)zThis file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
    N)List)settings)models)gettext_lazy)PredictionMetac                       e Zd Zd ed      fZd ed      fZd ed      fZd ed      fZd ed      fZd ed      fZ	d ed      fZ
y)	ModelProvidersOpenAIAzureOpenAIAzureAIFoundryVertexAIGemini	AnthropicCustomN)__name__
__module____qualname___OPENAIAZURE_OPENAIAZURE_AI_FOUNDRY	VERTEX_AIGEMINI	ANTHROPICCUSTOM     P/root/env/lib/python3.12/site-packages/label_studio/ml_model_providers/models.pyr	   r	      sh    q{"F !M"22L'+;)<<AjM)Iq{"FQ{^+Iq{"Fr   r	   c                   H    e Zd Zd ed      fZd ed      fZd ed      fZy)ModelProviderConnectionScopesOrganizationUserModelN)r   r   r   r   ORGUSERMODELr   r   r   r    r       s-    
!N+
+C1V9DQwZEr   r    c            	          e Zd Z ej                  dej                  ej                        Z ej                   e
d      ddd      Z ej                   e
d      ddd      Z ej                  d	ddd
      Z ej                  d	ddd      Z ej                   e
d      ddd      Z ej                   e
d      dddd      Z ej                   e
d      dddd      Z ej                  dddd      Z ej                  dej                  ej(                        Z ej,                  dej.                  dd      Z ej,                  ej4                  dej6                  d      Z ej:                   e
d      d      Z ej:                   e
d      d      Z ej@                   e
d      dd dd!      Z! ejD                   e
d"      ddd#d$%      Z# ej:                   e
d&      ddd#d'%      Z$ ej                   e
d(      d)d*d+gddd#d,-      Z% ejD                   e
d.      ddd#d/%      Z& ejD                   e
d0      ddd#d1%      Z'd2 Z(d3e)e*   fd4Z+d5 Z,y#)6ModelProviderConnection   )
max_lengthchoicesdefaultapi_keyTzModel provider API key)nullblank	help_text
auth_tokenzModel provider Auth tokeni   zAzure OpenAI deployment name)r*   r.   r/   r0   zAzure OpenAI endpointzgoogle application credentialsz7The content of GOOGLE_APPLICATION_CREDENTIALS json filezgoogle project idzGoogle project IDzgoogle locationzGoogle project locationi   z*List of available models from the providerzorganizations.Organizationmodel_provider_connections)	on_deleterelated_namer.   "created_model_provider_connections)r4   r3   r.   z
created at)auto_now_addz
updated at)auto_nowis_internalFzJWhether the model provider connection is internal, not visible to the user)r,   r0   r.   r/   budget_limitNzBBudget limit for the model provider connection (null if unlimited))r.   r/   r,   r0   budget_last_reset_datez'Date and time the budget was last resetbudget_reset_period   )Monthlyr=   )Yearlyr>   zIBudget reset period for the model provider connection (null if not reset))r*   r+   r.   r/   r,   r0   budget_total_spentz]Tracked total budget spent for the given provider connection within the current budget periodbudget_alert_thresholdz8Budget alert threshold for the given provider connectionc                     |j                   xs |j                  xs |j                  xr |j                  | j                  k(  S )N)is_administratoris_owner
is_manageractive_organization_idorganization_id)selfusers     r   has_permissionz&ModelProviderConnection.has_permission   s=    !!ET]]EdooB))T-A-AA	Br   predictions_metac                 ~    t        d |D              }| j                  xs d|z   | _        | j                  dg       y )Nc              3   <   K   | ]  }|j                   xs d   yw)r   N)
total_cost).0metas     r   	<genexpr>zZModelProviderConnection.update_budget_total_spent_from_predictions_meta.<locals>.<genexpr>   s     K$-A-Ks   r   r?   )update_fields)sumr?   save)rG   rJ   rM   s      r   /update_budget_total_spent_from_predictions_metazGModelProviderConnection.update_budget_total_spent_from_predictions_meta   s=    K:JKK
#'#:#:#?a:"M		!5 6	7r   c                     | j                   rn| j                  rb| j                  rV| j                  | j                  kD  r=t        j	                  d| j
                   d| j                   d| j                          yy)NzModel connection z has reached the budget limit: z > TF)r8   r?   r9   loggerinfoid)rG   s    r   has_reached_budget_limitz0ModelProviderConnection.has_reached_budget_limit   sr    ''!!''$*;*;;KK#DGG9,K**+3t/@/@.AC r   )-r   r   r   r   	CharFieldr	   r+   r   provider	TextFieldr   r-   r1   deployment_nameendpointgoogle_application_credentialsgoogle_project_idgoogle_locationcached_available_modelsr    r$   scope
ForeignKeyCASCADEorganizationr   AUTH_USER_MODELSET_NULL
created_byDateTimeField
created_at
updated_atBooleanFieldr8   
FloatFieldr9   r:   r;   r?   r@   rI   r   r   rT   rY   r   r   r   r(   r(      s   v38N8NXfXmXmnHfq|$dNfgG!!!!L/DTopJ&f&&#DXvwOv3TQhiH%5V%5%5	
*+K	&" )((	
3TQd 'f&&	
4tOhO /f..d$:f F = E EOlOpOpE %6$$$MiptL #""  9//	J &%%aoDIJ%%%aoEJ%&%%	-^K %6$$	.VL 2V11	
"#; +&**	
 " 
 ] +**	
q /V..	
"#LB
8PTUcPd 8r   r(   )__doc__loggingtypingr   django.confr   	django.dbr   django.utils.translationr   r   tasks.modelsr   	getLoggerr   rV   TextChoicesr	   r    r#   r(   r   r   r   <module>rx      sd         6 '			8	$#V'' # F$6$6  Cfll Cr   