ai-openai 1.0.10 → 1.0.12

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 +21 -0
  2. package/index.js +14 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -33,6 +33,27 @@ require("dotenv").config();
33
33
  console.error(err);
34
34
  }
35
35
  })();
36
+ ```
37
+
38
+ The default model used is openai/gpt-oss-120b
39
+
40
+ ---
41
+
42
+ ## Using a Custom Model (optional)
43
+ ```js
44
+ const reply = await chat("Explain black holes", {
45
+ model: "mistralai/Mistral-7B-Instruct-v0.2"
46
+ });
47
+
48
+ ```
49
+
50
+ ## Using a custom token (optional)
51
+ If you don't want to use a .env file:
52
+ ```js
53
+ const reply = await chat("Hello!", {
54
+ token: "hf_your_token_here"
55
+ });
56
+
36
57
  ```
37
58
  ## Installation
38
59
 
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,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-openai",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "Unofficial helper for OpenAI-like models via HuggingFace",
5
5
  "main": "index.js",
6
6
  "homepage": "https://ai-openai.bolt.host/",