3.0.2 • Published 4 days ago
huggingface-chat v3.0.2
Deprecation Notice
The versions 2.x and lower are deprecated please use latest.
Huggingface chat api
A simple api for hugging face chat with login caching.
Installation
Current stable release (3.x
)
npm i huggingface-chat
Example usage
import { Login ,ChatBot} from "huggingface-chat";
const EMAIL = "email"
const PASSWD = "password"
const cachePath = "./login_cache/"
const signin = new Login(EMAIL, PASSWD)
const res = await signin.login(cachePath) // default path is ./login_cache/
const chat = new ChatBot(res) // res is cookies which is required for subsequent aip calls
await chat.intialize()
const models = chat.listAvilableModels()
console.log(models)
const sessons = chat.listAvilableSesson()
console.log(sessons)
let currentModel = chat.showCurrentModel()
console.log(currentModel)
chat.switchModel("google/gemma-1.1-7b-it")
currentModel = chat.showCurrentModel()
console.log(currentModel)
const currentChat = await chat.getNewChat("you are a drunk person") // optional if you want to set a system prompt
console.log(currentChat)
let data = await chat.chat("hi my name is jhon");
let reader = data.stream.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break; // The streaming has ended.
process.stdout.write(value)
}
data = await chat.chat("what is my name");
let response = await data.completeResponsePromise() //non streaming response
console.log(response)
data = await chat.chat("what is my name", sessons[0].id); // using existing sessons
response = await data.completeResponsePromise()
console.log(response)
Note: Supported in node 18.x and higher.
Documentations
Full API documentations of both classes can be found here Chat Login
Contributions
- If you happen to see missing feature or a bug, feel free to open an issue.
- Pull requests are welcomed too!
License
3.0.2
4 days ago
3.0.1
11 days ago
3.0.0
15 days ago
2.1.0
20 days ago
2.0.9
3 months ago
2.0.8
3 months ago
1.0.5
8 months ago
2.0.3
8 months ago
2.0.2
8 months ago
2.0.5
7 months ago
2.0.4
8 months ago
2.0.7
7 months ago
2.0.6
7 months ago
2.0.1
8 months ago
2.0.0
8 months ago
1.0.4-a
8 months ago
1.0.4
8 months ago
1.0.3
8 months ago
1.0.2-a
8 months ago
1.0.2
8 months ago
1.0.1-a
8 months ago
1.0.1
8 months ago
1.0.0
8 months ago