JavaScript Example for inference API
Hi,Is there a JavaScript example for using inference API -🤗 Accelerated Inference API — Api inference documentation
2021-05-04T15:31:15Z
Hi@hgarg,Currently we don’t provide documentation for JS (or TS).You could probably use simplefetch:const HF_API_TOKEN = "api_xxxx";
const model = "XXX"

const data = {inputs:"Something here"};

const response = await fetch(`https://api-inference.huggingface.co/models/${model}`, {headers: {"Authorization": `Bearer ${HF_API_TOKEN}`}, method: "POST", data:JSON.stringify(data)});
const data = await response.json()should work.Cheers,Nicolas
2021-05-04T16:45:34Z
thanks@Narsil
2021-05-05T05:07:22Z
I am facing these weird problems while calling the API using JavaScript. Example…Model - EleutherAI/gpt-neo-2.7BInput - { inputs: 'cat jumps over the mouse ’ }Output -[{generated_text: “import React from ‘react’;\n” +“import { get } from ‘lodash’;\n” +“import { getText, getLanguage } from ‘…/…/…/…/…/utils/utils’;\n” +“import { Component } from '…/…/…/components”}]Model - facebook/bart-large-cnninput -{inputs: ‘The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.’}output -[{summary_text: ‘CNN.comwill featureiReporter.comin a iReporters gallery next week. Please send photos of your pets toiReport.com.    i-Reporters.i-Photography.comis a team of journalists at the U.S. Embassy in Washington, DC.’}]This happens every time, no matter the input. The same thing works fine when calling the API from python.
2021-05-07T03:52:22Z
Same here! I get the “CNN.comwill feature…” response for any input. Same outcome usingsshleifer/distilbart-cnn-12-6too. Only JS, not Py.
2021-05-07T11:05:42Z
Hi, we added NodeJS to the documentation so you can check out working examples:huggingface.coOverviewWe’re on a journey to advance and democratize artificial intelligence through open source and open science.Does that work better ? I think my example had an error.
2021-05-07T16:05:59Z
Yes, this returns the correct summary! Thanks for your help. Is there any way to specify the min_length of the summary with the API?Detailed parameters — Api inference documentationappears there’s just three unrelated options.
2021-05-07T16:28:27Z
You can use it.It’s an unofficial parameter because it’s defined intokenswhich are hard to use properly when you manipulate string. But before we have string oriented parameters you can use this one !Cheers,Nicolas