Skip to content

Commit

Permalink
user_id from env (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
luv-bansal authored Jan 13, 2025
1 parent 628bdd3 commit 37d6570
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions clarifai/client/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,17 +583,21 @@ def predict_by_bytes(self,

runner_selector = None
if deployment_id:
if not user_id:
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
raise UserError(
"User ID is required for model prediction with deployment ID, please provide user_id in the method call."
)
if not user_id:
user_id = os.environ.get('CLARIFAI_USER_ID')
runner_selector = Deployment.get_runner_selector(
user_id=user_id, deployment_id=deployment_id)
elif compute_cluster_id and nodepool_id:
if not user_id:
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
raise UserError(
"User ID is required for model prediction with compute cluster ID and nodepool ID, please provide user_id in the method call."
)
if not user_id:
user_id = os.environ.get('CLARIFAI_USER_ID')
runner_selector = Nodepool.get_runner_selector(
user_id=user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)

Expand Down Expand Up @@ -650,17 +654,21 @@ def predict_by_url(self,

runner_selector = None
if deployment_id:
if not user_id:
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
raise UserError(
"User ID is required for model prediction with deployment ID, please provide user_id in the method call."
)
if not user_id:
user_id = os.environ.get('CLARIFAI_USER_ID')
runner_selector = Deployment.get_runner_selector(
user_id=user_id, deployment_id=deployment_id)
elif compute_cluster_id and nodepool_id:
if not user_id:
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
raise UserError(
"User ID is required for model prediction with compute cluster ID and nodepool ID, please provide user_id in the method call."
)
if not user_id:
user_id = os.environ.get('CLARIFAI_USER_ID')
runner_selector = Nodepool.get_runner_selector(
user_id=user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)

Expand Down Expand Up @@ -820,17 +828,19 @@ def generate_by_bytes(self,

runner_selector = None
if deployment_id:
if not user_id:
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
raise UserError(
"User ID is required for model prediction with deployment ID, please provide user_id in the method call."
)
runner_selector = Deployment.get_runner_selector(
user_id=user_id, deployment_id=deployment_id)
elif compute_cluster_id and nodepool_id:
if not user_id:
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
raise UserError(
"User ID is required for model prediction with compute cluster ID and nodepool ID, please provide user_id in the method call."
)
if not user_id:
user_id = os.environ.get('CLARIFAI_USER_ID')
runner_selector = Nodepool.get_runner_selector(
user_id=user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)

Expand Down Expand Up @@ -888,17 +898,21 @@ def generate_by_url(self,

runner_selector = None
if deployment_id:
if not user_id:
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
raise UserError(
"User ID is required for model prediction with deployment ID, please provide user_id in the method call."
)
if not user_id:
user_id = os.environ.get('CLARIFAI_USER_ID')
runner_selector = Deployment.get_runner_selector(
user_id=user_id, deployment_id=deployment_id)
elif compute_cluster_id and nodepool_id:
if not user_id:
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
raise UserError(
"User ID is required for model prediction with compute cluster ID and nodepool ID, please provide user_id in the method call."
)
if not user_id:
user_id = os.environ.get('CLARIFAI_USER_ID')
runner_selector = Nodepool.get_runner_selector(
user_id=user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)

Expand Down Expand Up @@ -1058,17 +1072,21 @@ def input_generator():

runner_selector = None
if deployment_id:
if not user_id:
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
raise UserError(
"User ID is required for model prediction with deployment ID, please provide user_id in the method call."
)
if not user_id:
user_id = os.environ.get('CLARIFAI_USER_ID')
runner_selector = Deployment.get_runner_selector(
user_id=user_id, deployment_id=deployment_id)
elif compute_cluster_id and nodepool_id:
if not user_id:
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
raise UserError(
"User ID is required for model prediction with compute cluster ID and nodepool ID, please provide user_id in the method call."
)
if not user_id:
user_id = os.environ.get('CLARIFAI_USER_ID')
runner_selector = Nodepool.get_runner_selector(
user_id=user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)

Expand Down Expand Up @@ -1126,17 +1144,21 @@ def input_generator():

runner_selector = None
if deployment_id:
if not user_id:
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
raise UserError(
"User ID is required for model prediction with deployment ID, please provide user_id in the method call."
)
if not user_id:
user_id = os.environ.get('CLARIFAI_USER_ID')
runner_selector = Deployment.get_runner_selector(
user_id=user_id, deployment_id=deployment_id)
elif compute_cluster_id and nodepool_id:
if not user_id:
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
raise UserError(
"User ID is required for model prediction with compute cluster ID and nodepool ID, please provide user_id in the method call."
)
if not user_id:
user_id = os.environ.get('CLARIFAI_USER_ID')
runner_selector = Nodepool.get_runner_selector(
user_id=user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)

Expand Down

0 comments on commit 37d6570

Please sign in to comment.