databricks-sdk-py
databricks-sdk-py copied to clipboard
[FEATURE] add serving_endpoints.create_or_update[_and_wait] functions
Problem Statement We often have to create or update an endpoint. Currently we do things like this which is a lot of code:
existing_endpoint = next(
(e for e in w.serving_endpoints.list() if e.name == serving_endpoint_name), None
)
serving_endpoint_url = f"{host}/ml/endpoints/{serving_endpoint_name}"
if existing_endpoint == None:
print(f"Creating the endpoint {serving_endpoint_url}, this will take a few minutes to package and deploy the endpoint...")
w.serving_endpoints.create_and_wait(name=serving_endpoint_name, config=endpoint_config)
else:
print(f"Updating the endpoint {serving_endpoint_url} to version {latest_model_version}, this will take a few minutes to package and deploy the endpoint...")
w.serving_endpoints.update_config_and_wait(served_models=endpoint_config.served_models, name=serving_endpoint_name)
Proposed Solution
Instead we could add functions such as
w.serving_endpoints.create_or_update(xxx)
or
w.serving_endpoints.create_or_update_and_wait(xxx)
I am also longing for this kind of function!
At least having an endpoint_exists function would be a good first step.
alternative to iteration
def does_serving_endpoint_already_exist(self, endpoint_name):
try:
workspace_client.serving_endpoints.get(endpoint_name)
except DatabricksError as error:
if error.error_code == "RESOURCE_DOES_NOT_EXIST":
return False
else:
raise error
return True