admin 管理员组文章数量: 887007
在国内用接码平台买个虚拟号注册下openai
以下是油管上扒来的代码,把env里的OPEN_AI_KEY换成自己的就可以直接用了
const express = require("express");
require("dotenv").config();
const { Configuration, OpenAIApi } = require("openai");
const app = express();
app.use(express.json());
const configuration = new Configuration({
apiKey: process.env.OPEN_AI_KEY,
});
const openai = new OpenAIApi(configuration);
app.post("/find-complexity", async (req, res) => {
try {
const { prompt } = req.body;
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: `
${prompt}
The time complexity of this function is
###
`,
max_tokens: 64,
temperature: 0,
top_p: 1.0,
frequency_penalty: 0.0,
presence_penalty: 0.0,
stop: ["\n"],
});
return res.status(200).json({
success: true,
data: response.data.choices[0].text,
});
} catch (error) {
return res.status(400).json({
success: false,
error: error.response
? error.response.data
: "There was an issue on the server",
});
}
});
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Server listening on port ${port}`));
本文标签: Express nodejs OpenAI ChatGpt key
版权声明:本文标题:nodejs express接入openai key使用chatgpt 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1724643862h783742.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论