Can't query Legacy Serving Endpoint

semsim
Contributor

Hi,

I was able to deploy an endpoint using legacy serving (It's the only option we have to deploy endpoints in DB). Now I am having trouble querying the endpoint itself. When I try to query it I get the following error: 

semsim_0-1726245119742.png

 

 

 Here is the code I am using to query the endpoint:

 

mport os
import requests
import numpy as np
import pandas as pd
import json


token = user_token

def create_tf_serving_json(data):
  return {'inputs': {name: data[name].tolist() for name in data.keys()} if isinstance(data, dict) else data.tolist()}

def score_model(dataset):
  url = 'url_to_model'
  headers = {'Authorization': f'Bearer {token}', 'Content-Type': 'application/json'}
  ds_dict = {"dataframe_split": dataset.to_dict(orient='split')} if isinstance(dataset, pd.DataFrame) else create_tf_serving_json(dataset)
  data_json = json.dumps(ds_dict, allow_nan=True)
  response = requests.request(method='POST', headers=headers, url=url, data=data_json)
  if response.status_code != 200:
    raise Exception(f'Request failed with status {response.status_code}, {response.text}')
  return response.json()

# Scoring a model that accepts pandas DataFrames
data =  pd.DataFrame([{
  "sepal_length": 5.1,
  "sepal_width": 3.5,
  "petal_length": 1.4,
  "petal_width": 0.2
}])
score_model(data) #MODEL_VERSION_URI, DATABRICKS_API_TOKEN, 


# Scoring a model that accepts tensors
#data = np.asarray([[5.1, 3.5, 1.4, 0.2]])
#score_model(MODEL_VERSION_URI, DATABRICKS_API_TOKEN, data)