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.
- package/README.md +1 -1
- package/index.js +14 -7
- package/package.json +2 -1
package/README.md
CHANGED
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 {
|
|
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,
|
|
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
|
|
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 =
|
|
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