首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不使用API键的GPT-3完成

不使用API键的GPT-3完成
EN

Stack Overflow用户
提问于 2022-05-01 20:31:58
回答 1查看 685关注 0票数 2

对不起,如果这是一个简单的问题,但我是新手。

İ下面有我的代码,但是API返回说İ没有正确的API键。

代码语言:javascript
复制
const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

async function test() {
  const response = await openai.createCompletion("text-davinci-002", {
    prompt: "Summarize this for a college student:\n\nJupiter is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-half times that of all the other planets in the Solar System combined. Jupiter is one of the brightest objects visible to the naked eye in the night sky, and has been known to ancient civilizations since before recorded history. It is named after the Roman god Jupiter.[19] When viewed from Earth, Jupiter can be bright enough for its reflected light to cast visible shadows,[20] and is on average the third-brightest natural object in the night sky after the Moon and Venus.",
    temperature: 0.7,
    max_tokens: 64,
    top_p: 1,
    frequency_penalty: 0,
    presence_penalty: 0,
  });
  console.log(response)
}

test()

API键似乎是在process.env文件中找到的,而İ没有,当İ创建一个名为process.env的文件并创建一个名为OPENAI_API_KEY的变量时,它似乎不起作用。当apiKey设置为实际键时,它返回一些内容,但这似乎是一个迂回的解决方案。谢谢

EN

回答 1

Stack Overflow用户

发布于 2022-05-01 21:21:41

process.env不是文件夹,它用于从主机操作系统获取环境变量。您可以简单地将process.env.OPENAI_API_KEY替换为"your-api-key-here"

process.env在发布到github之类的东西时最常用,在那里您需要将api键保密,这样就没有其他人可以使用它们了,但是在部署时仍然可以使用它们。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72080207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档