Uncaught (in promise) SyntaxError: Unexpected token 'E', "Expected r"... is not valid JSON

#66
by sxmss1 - opened

im using javascript api inference and this returns an error in the console>>

"Uncaught (in promise) SyntaxError: Unexpected token 'E', "Expected r"... is not valid JSON"

the problem seems to be with

query({"inputs": "Hi? "}).then((response) => {
console.log(JSON.stringify(response));
});

when i use the default it works and returns a response in the console:

query({"inputs": "Can you please let us know more details about your "}).then((response) => {
console.log(JSON.stringify(response));
});

here is the full code, replaced my key with the default:

async function query(data) {
const response = await fetch(
"https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct",
{
headers: { Authorization: "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" },
method: "POST",
body: JSON.stringify(data),
}
);
const result = await response.json();
return result;
}

query({"inputs": "Hi? "}).then((response) => {
console.log(JSON.stringify(response));
});

1

@xumeng ?? please help bro

Facing the same issue. Following

same here

Under header add "Content-Type": "application/json" like this:

headers: {
Authorization: "Bearer hf_xxxxxxx",
"Content-Type": "application/json",
}

Sign up or log in to comment