def test_authn_free_session(self, mock_env_authn_missing): deployed_model = DeployedModel.from_url(self.prediction_url, token=None, creds=None) headers = deployed_model.headers() assert (_GRPC_PREFIX + "source") not in headers assert "Access-Token" not in headers
def get_deployed_model(self, credentials=None): """ Return an object for making predictions against the deployed model. Parameters ---------- credentials : :class:`~verta.credentials.Credentials`, optional Authentication credentials to use with this deployed model. Credentials will be inferred from the environment if not explicitly provided. Returns ------- :class:`~verta.deployment.DeployedModel` Raises ------ RuntimeError If the model is not currently deployed. """ status = self.get_status() if status["status"] not in ("active", "updating"): raise RuntimeError( "model is not currently deployed (status: {})".format(status)) access_token = self.get_access_token() url = "{}://{}/api/v1/predict{}".format(self._conn.scheme, self._conn.socket, self.path) return DeployedModel.from_url(url, access_token, creds=credentials)
def test_jwt_authn_load_from_env(self, mock_env_jwt_auth): deployed_model = DeployedModel.from_url(self.prediction_url, token=None, creds=None) headers = deployed_model.headers() assert "Access-Token" not in headers assert headers.get(_GRPC_PREFIX + "source") == "JWT" assert (_GRPC_PREFIX + "bearer_access_token") in headers
def test_authn_load_from_env(self, mock_env_dev_key_auth): deployed_model = DeployedModel.from_url(self.prediction_url, token=None, creds=None) headers = deployed_model.headers() assert "Access-Token" not in headers assert headers.get(_GRPC_PREFIX + "source") == "PythonClient" assert (_GRPC_PREFIX + "email") in headers
def test_access_token_deployment(self, mock_env_authn_missing): access_token = "fake-access-token" deployed_model = DeployedModel.from_url(self.prediction_url, token=access_token, creds=None) headers = deployed_model.headers() assert (_GRPC_PREFIX + "source") not in headers assert headers.get("Access-Token") == access_token
def test_user_dev_key_deployment(self, mock_env_authn_missing): email_creds = EmailCredentials("fake-email", "fake-dev-key") deployed_model = DeployedModel.from_url(self.prediction_url, token=None, creds=email_creds) headers = deployed_model.headers() assert "Access-Token" not in headers assert headers.get(_GRPC_PREFIX + "source") == "PythonClient" assert headers.get(_GRPC_PREFIX + "email") == "fake-email"
def test_both_authn_deployment(self, mock_env_authn_missing): email_creds = EmailCredentials("fake-email", "fake-dev-key") access_token = "fake-access-token" deployed_model = DeployedModel.from_url(self.prediction_url, token=access_token, creds=email_creds) headers = deployed_model.headers() assert headers.get("Access-Token") == access_token assert headers.get(_GRPC_PREFIX + "source") == "PythonClient" assert headers.get(_GRPC_PREFIX + "email") == "fake-email"
def test_user_jwt_deployment(self, mock_env_authn_missing): jwt_creds = JWTCredentials("fake-token", "fake-token-sig") deployed_model = DeployedModel.from_url(self.prediction_url, token=None, creds=jwt_creds) headers = deployed_model.headers() assert "Access-Token" not in headers assert headers.get(_GRPC_PREFIX + "source") == "JWT" assert headers.get(_GRPC_PREFIX + "bearer_access_token") == "fake-token"
def get_deployed_model(self): """ Returns an object for making predictions against the deployed model. Returns ------- :class:`~verta.deployment.DeployedModel` Raises ------ RuntimeError If the model is not currently deployed. """ status = self.get_status() if status["status"] not in ("active", "updating"): raise RuntimeError( "model is not currently deployed (status: {})".format(status)) access_token = self.get_access_token() url = "{}://{}/api/v1/predict{}".format(self._conn.scheme, self._conn.socket, self.path) return DeployedModel.from_url(url, access_token)
nltk.download('wordnet') """) # --- # # Make Live Predictions # Access the Experiment Run through the Verta Web App and deploy it! # In[23]: run # ## Load Deployed Model # In[24]: from verta.deployment import DeployedModel deployed_model = DeployedModel(HOST, run.id) # ## Query Deployed Model # In[25]: for text in x_test: print(deployed_model.predict([text])) time.sleep(.5) # ---