Trouble with the built in inference API example

Hi I’m just starting out with the inference API examples. While I can get other examples to work using the same formatting , I get this error

{“error”:“d argument needs to be of type (SquadExample, dict)”}

When using the example for deepset/roberta-base-squad2 · Hugging Face

import json
import requests

API_URL = "https://api-inference.huggingface.co/models/deepset/roberta-base-squad2"
headers = {"Authorization": "Bearer api_xxx"}

def query(payload):
	data = json.dumps(payload)
	response = requests.request("POST", API_URL, headers=headers, data=data)
	return json.loads(response.content.decode("utf-8"))

data = query(
    {
        "inputs": {
            "question": "What's my name?",
            "context": "My name is Clara and I live in Berkeley.",
        }
    }
)

I’d love know how else to format the query, or what else I should double check.

Thanks for reading.

Hi @LowellR

I just tried your exact pasted code and it worked fine.

{'answer': 'Clara', 'end': 16, 'score': 0.9326569437980652, 'start': 11}

Could you confirm if you are running this same code?
Thanks!

Thanks for taking a look @osanseviero I appreciate you testing it out. I must have some sort of formatting issue. I’ll take another look.