forked from xuRay2024/git-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.mjs
More file actions
35 lines (30 loc) · 833 Bytes
/
main.mjs
File metadata and controls
35 lines (30 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import dotenv from "dotenv";
import OpenAI from "openai";
dotenv.config();
const client = new OpenAI({
apiKey: process.env.API_KEY,
baseURL: "https://www.gptapi.us",
});
const main = async () => {
try {
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [
{
role: "user",
content: [
{
type: "text",
text: "给我返回一个模拟的人物信息:firstName 和 lastName, Do not include any explanations, only provide a RFC8259 compliant JSON response following this format without deviation",
},
],
},
],
max_tokens: 300,
});
console.log(response.choices[0].message.content);
} catch (error) {
console.error("error:", error.message);
}
};
main();