use inference api

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

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

I want to use API, but the above code that Hugging Face has put in gives an error.
please guide me

Whats the error?

Whats the error?

Screenshot from 2024-05-28 12-21-26.png

did u log the response of the api? that provies too lil information, and if possible to have the code sample would help

I was able to fix the error, but now I get a wrong response when just putting plain text in the input parameter.

This is my answer when I just type hello:

  "generated_text": "hello, it's me, Tom,\n\nas the title already suggests, i now have a question regarding the primary key on a table that is referenced by another table.\n\ni have a table that contains entries of machines (serialnumber, name, manufacurer, warranty ...)\nand another table that contains informations inside a machine (equipment, software, license ...).\nthis second table references the first table on the column serialnumber.\n\nin both"

Thats because you are not using the prompt template it requires, you need to use the correct chat template for llama.

Thats because you are not using the prompt template it requires, you need to use the correct chat template for llama.

Thank you very much for your advice, but can you show me an example of the right templates?
This is my code :

fetch("https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct", {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer hf_api'
    },
    body: JSON.stringify({
        'inputs': 'hello'
    })
})
.then(response => response.json())
.then(data => {
    console.log((data));
    
});

Sign up or log in to comment