ai-openai 1.0.13 → 1.0.14

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 (2) hide show
  1. package/index.js +11 -16
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -5,17 +5,16 @@ require("dotenv").config();
5
5
  * Send a message to HuggingFace chat API and get a reply
6
6
  * @param {string} message - The user's message
7
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
+ * @param {string} options.model - Chat-completions model (default: "openai/gpt-oss-120b")
9
+ * @param {string} options.system - System prompt (default: "You are a helpful assistant.")
10
10
  * @returns {Promise<string>} - AI reply
11
11
  */
12
12
  async function chat(message, options = {}) {
13
- const {
14
- model = "openai/gpt-oss-120b",
15
- token = process.env.HUGGINGFACE
16
- } = options;
13
+ const model = options.model || "openai/gpt-oss-120b";
14
+ const system = options.system || "You are a helpful assistant.";
15
+ const token = process.env.HUGGINGFACE;
17
16
 
18
- if (!token) throw new Error("HuggingFace token is required");
17
+ if (!token) throw new Error("HuggingFace token required in .env as HUGGINGFACE");
19
18
  if (!message) throw new Error("Message is required");
20
19
 
21
20
  try {
@@ -24,24 +23,20 @@ async function chat(message, options = {}) {
24
23
  {
25
24
  model,
26
25
  messages: [
27
- {
28
- role: "system",
29
- content: `You are a helpful assistant.`
30
- },
26
+ { role: "system", content: system },
31
27
  { role: "user", content: message }
32
- ]
28
+ ],
33
29
  },
34
30
  {
35
31
  headers: {
36
32
  Authorization: `Bearer ${token}`,
37
33
  "Content-Type": "application/json"
38
- }
34
+ },
39
35
  }
40
36
  );
41
37
 
42
- const aiText =
43
- response.data?.choices?.[0]?.message?.content || "No response";
44
-
38
+ // Extract reply text from router response
39
+ const aiText = response.data?.choices?.[0]?.message?.content || "No response";
45
40
  return aiText;
46
41
 
47
42
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-openai",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Unofficial helper for OpenAI-like models via HuggingFace",
5
5
  "main": "index.js",
6
6
  "homepage": "https://ai-openai.bolt.host/",