ai-openai 1.0.9 → 1.0.11

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/index.js +14 -7
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # openai-helper
1
+ # ai-openai
2
2
 
3
3
  An **unofficial helper API** for OpenAI-like models hosted on HuggingFace.
4
4
  Simplifies calling AI models for chat responses, learning advice, and more.
package/index.js CHANGED
@@ -4,10 +4,17 @@ require("dotenv").config();
4
4
  /**
5
5
  * Send a message to HuggingFace chat API and get a reply
6
6
  * @param {string} message - The user's message
7
- * @param {string} token - HuggingFace API token (optional, defaults to env)
7
+ * @param {object} options - Optional settings
8
+ * @param {string} options.model - Model name (optional)
9
+ * @param {string} options.token - HuggingFace API token (optional, defaults to env)
8
10
  * @returns {Promise<string>} - AI reply
9
11
  */
10
- async function chat(message, token = process.env.HUGGINGFACE) {
12
+ async function chat(message, options = {}) {
13
+ const {
14
+ model = "openai/gpt-oss-120b",
15
+ token = process.env.HUGGINGFACE
16
+ } = options;
17
+
11
18
  if (!token) throw new Error("HuggingFace token is required");
12
19
  if (!message) throw new Error("Message is required");
13
20
 
@@ -15,13 +22,11 @@ async function chat(message, token = process.env.HUGGINGFACE) {
15
22
  const response = await axios.post(
16
23
  "https://router.huggingface.co/v1/chat/completions",
17
24
  {
18
- model: "openai/gpt-oss-120b" , // or any HF chat-compatible model
25
+ model,
19
26
  messages: [
20
27
  {
21
28
  role: "system",
22
- content: `
23
- You are a helpful assistant.
24
- `
29
+ content: `You are a helpful assistant.`
25
30
  },
26
31
  { role: "user", content: message }
27
32
  ]
@@ -34,7 +39,9 @@ You are a helpful assistant.
34
39
  }
35
40
  );
36
41
 
37
- const aiText = response.data?.choices?.[0]?.message?.content || "No response";
42
+ const aiText =
43
+ response.data?.choices?.[0]?.message?.content || "No response";
44
+
38
45
  return aiText;
39
46
 
40
47
  } catch (err) {
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "ai-openai",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Unofficial helper for OpenAI-like models via HuggingFace",
5
5
  "main": "index.js",
6
+ "homepage": "https://ai-openai.bolt.host/",
6
7
  "scripts": {
7
8
  "start": "node test.js"
8
9
  },