databricks / databricks-sdk-py

Databricks SDK for Python (Beta)
https://databricks-sdk-py.readthedocs.io/
Apache License 2.0
352 stars 117 forks source link

[FEATURE] add serving_endpoints.create_or_update[_and_wait] functions #662

Open QuentinAmbard opened 4 months ago

QuentinAmbard commented 4 months ago

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)

moritzmeister commented 3 months ago

I am also longing for this kind of function!

QuentinAmbard commented 3 months ago

At least having an endpoint_exists function would be a good first step.

ppiotrow commented 2 months ago

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