in dell_ai/auth.py [0:0]
def check_model_access(model_id: str, token: Optional[str] = None) -> bool:
"""
Check if the user has access to a specific model repository.
Args:
model_id: The model ID in the format "organization/model_name"
token: The Hugging Face token to use. If not provided, will use the
token from get_token().
Returns:
True if the user has access to the model repository
Raises:
AuthenticationError: If authentication fails or no token is available
GatedRepoAccessError: If the repository is gated and the user doesn't have access
ResourceNotFoundError: If the repository doesn't exist
"""
token = token or get_token()
if not token:
raise AuthenticationError("No authentication token found. Please login first.")
try:
# Use huggingface_hub's auth_check function to verify access
hf_auth_check(repo_id=model_id, token=token)
return True
except GatedRepoError as e:
# User doesn't have access to a gated repository
raise GatedRepoAccessError(model_id, original_error=e)
except RepositoryNotFoundError as e:
# Repository doesn't exist or is private and user doesn't have access
raise ResourceNotFoundError("model", model_id, original_error=e)
except Exception as e:
# Other errors (network issues, invalid token, etc.)
raise AuthenticationError(
f"Failed to check model access: {str(e)}", original_error=e
)