JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 109
  • Score
    100M100P100Q56636F
  • License ISC

An api for hugging face chat.

Package Exports

  • huggingface-chat

Readme

huggingface chat api

A simple api for hugging face chat with login caching

example usage

import { Login ,ChatBot} from "huggingface-chat";
import readline from 'readline';

const EMAIL = "email"
const PASSWD = "password"

const signin = new Login(EMAIL, PASSWD)

const res = await signin.loadCache("./cache/")
// const res = await signin.login()
console.log(res);

const chat = new ChatBot(res)

const { id, data }= await chat.chat("who am i")

const rl = readline.createInterface({
    input: data, // Use the response data stream
});

rl.on('line', (line) => {
    try {
        const jsonObject = JSON.parse(line.substring(5).trim());
        console.log(jsonObject.token.text);
        console.log(jsonObject.generated_text?jsonObject.generated_text:'');
    } catch (error) {
        if(line.substring(5).trim())console.error('Error parsing JSON:', line.substring(5).trim());
    }
});

rl.on('close', () => {
    console.log('Stream closed',id);
});
console.log(id);