ai-openai
v1.0.20
Published
Unofficial helper for OpenAI-like models via HuggingFace
Readme
ai-openai
An unofficial helper API for OpenAI-like models hosted on HuggingFace.
Simplifies calling AI models for chat responses, learning advice, and more.
Features
- Free HuggingFace-hosted OpenAI-like model
- SkillGap AI system prompt built-in
- Simple JSON API
- Easy integration with websites, Discord bots, or other apps
Setup
- Get your free HuggingFace token at https://huggingface.co/settings/tokens
- Create a
.envfile in your project root and add your HuggingFace token: HUGGINGFACE=your_token_here - Then run your project.
Usage
const { chat } = require("ai-openai"); // import from npm package
require("dotenv").config();
(async () => {
try {
// Default usage
const reply = await chat("What is x if y = 2x + 3 and y = 7?");
console.log("Default model reply:", reply);
// Using a custom model
const reply2 = await chat("Explain black holes briefly.", {
model: "mistralai/Mistral-7B-Instruct-v0.2"
});
console.log("Custom model reply:", reply2);
// Using a custom system prompt
const reply3 = await chat("Explain black holes briefly.", {
system: "You are a physics professor explaining to a high school student."
});
console.log("Custom system prompt reply:", reply3);
} catch (err) {
console.error(err);
}
})();- Note: The default model is openai/gpt-oss-120b.
Installation
npm install ai-openai
