ai-openai 1.0.15 → 1.0.17
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 +24 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,49 +13,51 @@ Simplifies calling AI models for chat responses, learning advice, and more.
|
|
|
13
13
|
- Easy integration with websites, Discord bots, or other apps
|
|
14
14
|
|
|
15
15
|
---
|
|
16
|
+
|
|
16
17
|
## Setup
|
|
17
18
|
|
|
18
|
-
1. Get your free HuggingFace token at https://huggingface.co/settings/tokens
|
|
19
|
-
2. Create a
|
|
19
|
+
1. Get your free HuggingFace token at https://huggingface.co/settings/tokens
|
|
20
|
+
2. Create a `.env` file in your project root and add your HuggingFace token:
|
|
20
21
|
HUGGINGFACE=your_token_here
|
|
21
22
|
3. Then run your project.
|
|
22
23
|
|
|
24
|
+
---
|
|
25
|
+
|
|
23
26
|
## Usage
|
|
27
|
+
|
|
24
28
|
```js
|
|
25
29
|
const { chat } = require("ai-openai"); // import from npm package
|
|
26
30
|
require("dotenv").config();
|
|
27
31
|
|
|
28
32
|
(async () => {
|
|
29
33
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
// Default usage
|
|
35
|
+
const reply = await chat("What is x if y = 2x + 3 and y = 7?");
|
|
36
|
+
console.log("Default model reply:", reply);
|
|
37
|
+
|
|
38
|
+
// Using a custom model
|
|
39
|
+
const reply2 = await chat("Explain black holes briefly.", {
|
|
40
|
+
model: "mistralai/Mistral-7B-Instruct-v0.2"
|
|
41
|
+
});
|
|
42
|
+
console.log("Custom model reply:", reply2);
|
|
43
|
+
|
|
44
|
+
// Using a custom system prompt
|
|
45
|
+
const reply3 = await chat("Explain black holes briefly.", {
|
|
46
|
+
system: "You are a physics professor explaining to a high school student."
|
|
47
|
+
});
|
|
48
|
+
console.log("Custom system prompt reply:", reply3);
|
|
49
|
+
|
|
32
50
|
} catch (err) {
|
|
33
51
|
console.error(err);
|
|
34
52
|
}
|
|
35
53
|
})();
|
|
36
54
|
```
|
|
37
|
-
|
|
38
|
-
The default model used is openai/gpt-oss-120b
|
|
55
|
+
- **Note:** The default model is openai/gpt-oss-120b.
|
|
39
56
|
|
|
40
57
|
---
|
|
41
58
|
|
|
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
|
-
|
|
57
|
-
```
|
|
58
59
|
## Installation
|
|
59
60
|
|
|
60
61
|
```bash
|
|
61
62
|
npm install ai-openai
|
|
63
|
+
|