opanai
适合国内开发者的openai库
使用前
请先去获取apikey
安装
npm i china-openai
导入所需的模块
const { imagesGenerate, chatCompletions } = require('china-openai')
使用
const apiKey = "YOUR_API_KEY";
const chatCompletion = async () => {
try {
const model = "gpt-3.5-turbo";
const messages = [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Who won the World Series in 2021?" }
];
const response = await chatCompletions({
model: model,
messages: messages,
stream: false,
config:{ apiKey: apiKey, isAgent: true }
});
res.send({
data: response
});
} catch (err) {
throw err;
}
};
chatCompletion();
const generateImages = async () => {
try {
const model = "your_model_name";
const prompt = "your_prompt_text";
const n = 1;
const images = await imagesGenerate({
model: model,
prompt: prompt,
n: n,
});
console.log(images);
} catch (err) {
console.error(err);
}
};
generateImages();