ai-openai 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/index.js +46 -0
- package/package.json +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joltz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# openai-helper
|
|
2
|
+
|
|
3
|
+
An **unofficial helper API** for OpenAI-like models hosted on HuggingFace.
|
|
4
|
+
Simplifies calling AI models for chat responses, learning advice, and more.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- Free HuggingFace-hosted OpenAI-like model
|
|
11
|
+
- SkillGap AI system prompt built-in
|
|
12
|
+
- Simple JSON API
|
|
13
|
+
- Easy integration with websites, Discord bots, or other apps
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
## Setup
|
|
17
|
+
|
|
18
|
+
1. Get your free HuggingFace token at https://huggingface.co/settings/tokens
|
|
19
|
+
2. Input your HuggingFace token in the HUGGINGFACE variable.
|
|
20
|
+
3. Then run your project.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
const { chat } = require("ai-openai"); // import from npm package
|
|
25
|
+
require("dotenv").config();
|
|
26
|
+
|
|
27
|
+
(async () => {
|
|
28
|
+
try {
|
|
29
|
+
const reply = await chat("What is x if y = 2x + 3 and y = 7?"); // call function directly
|
|
30
|
+
console.log("AI reply:", reply);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error(err);
|
|
33
|
+
}
|
|
34
|
+
})();
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install openai-helper
|
package/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const axios = require("axios");
|
|
2
|
+
require("dotenv").config();
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Send a message to HuggingFace chat API and get a reply
|
|
6
|
+
* @param {string} message - The user's message
|
|
7
|
+
* @param {string} token - HuggingFace API token (optional, defaults to env)
|
|
8
|
+
* @returns {Promise<string>} - AI reply
|
|
9
|
+
*/
|
|
10
|
+
async function chat(message, token = process.env.HUGGINGFACE) {
|
|
11
|
+
if (!token) throw new Error("HuggingFace token is required");
|
|
12
|
+
if (!message) throw new Error("Message is required");
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const response = await axios.post(
|
|
16
|
+
"https://router.huggingface.co/v1/chat/completions",
|
|
17
|
+
{
|
|
18
|
+
model: "openai/gpt-oss-120b" , // or any HF chat-compatible model
|
|
19
|
+
messages: [
|
|
20
|
+
{
|
|
21
|
+
role: "system",
|
|
22
|
+
content: `
|
|
23
|
+
You are a helpful assistant.
|
|
24
|
+
`
|
|
25
|
+
},
|
|
26
|
+
{ role: "user", content: message }
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
headers: {
|
|
31
|
+
Authorization: `Bearer ${token}`,
|
|
32
|
+
"Content-Type": "application/json"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const aiText = response.data?.choices?.[0]?.message?.content || "No response";
|
|
38
|
+
return aiText;
|
|
39
|
+
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.error(err.response?.data || err.message);
|
|
42
|
+
throw new Error("Something went wrong with the AI API call");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = { chat };
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ai-openai",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Unofficial helper for OpenAI-like models via HuggingFace",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "node test.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"openai",
|
|
11
|
+
"huggingface",
|
|
12
|
+
"ai",
|
|
13
|
+
"chat"
|
|
14
|
+
],
|
|
15
|
+
"author": "Joltz",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"axios": "^1.5.0",
|
|
19
|
+
"dotenv": "^16.3.1"
|
|
20
|
+
}
|
|
21
|
+
}
|