from databricks.sdk import WorkspaceClient
from databricks.sdk.service.serving import EndpointTag

# Create/Update endpoint
workspace_client = WorkspaceClient()

endpoint_name = "random_name"

try:
	workspace_client.serving_endpoints.create_wait(
		name=endpoint_name,
		config=endpoint_config,
		tags=[EndpointTag.from_dict({"key": "value1", "value": "model_example"})]
	)
	
	print("Creating endpoint")

except Exception as e:
	if "already exisits" in e.args[0]:
		print("Endpoint already exists")
	
	else:
		raise(e)
		
		

# Hard-code test-sample
dataframe_records = [
    {"SeniorCitizen": 0, "tenure":12, "MonthlyCharges":65, "TotalCharges":800},
    {"SeniorCitizen": 1, "tenure":24, "MonthlyCharges":40, "TotalCharges":500}
]

print("Inference results:")
query_response = w.serving_endpoints.query(name=endpoint_name, dataframe_records=dataframe_records)
print(query_response.predictions)

Query endpoint

image.png

image.png