hug-client
v1.0.3
Published
A super simple Huggingface Api client
Readme
HUGJS - Huggingface Api client
A lightweight JavaScript client for interacting with the Hugging Face chat/completions API.
npm install hug-client
#USAGE 1: index.js
#Self calling function for on page start or refresh executions
import Hug from "./hug.js";
let apiToken = "YOUR HUGGINGFACE ACCESS TOKEN";
(async ()=>{
const resp = await Hug({
messages: [
{role: "user", content: "Where was Okomfo Anokye born" //userInput,},
{role: "system", // THIS OBJECT is OPTIONALcontent: "Chat Bot" //instruction on What The model should do}
],
model: "meta-llama/Llama-3.1-8B-Instruct:cerebras"//Model Name,
}, apiToken);
console.log(resp);
})();
## USAGE 2: index.js
# Event
const apiToken = <Your Access token>
const generate = async ()=>{
const resp = await Hug({
messages: [
{role: "user", content: userInput.value},
{role: "system", content: "ChatBot AI"},
],
model: "meta-llama/Llama-3.1-8B-Instruct:cerebras"
}, api);
res.textContent = resp;
};
btn.addEventListener('click',()=>{
generate();
console.log("clicked")
})
API Reference
Hug(data, apiToken);
- data: Object containing the request payload
- messages: Array of { role, content } objects
- role: "user", "system", or "assistant"
- content: String message content
- model: String name of the Hugging Face model to query
- apiToken: Your Hugging Face API key (hf_xxx...) ## Visit: Huggingface.co site to find api/access token
Returns: A Promise resolving to the JSON response from Hugging Face.
Example payload:
{
"messages": [
{ "role": "user", "content": "Hello!" }
],
"model": "meta-llama/Llama-3-8b-chat-hf" # Visit: Huggingface.co site to find models
}
Contributors: Prince Adu. Boahene