我不确定如何使用我的GPT-3API密钥/环境变量创建".json“文件,但我想在Google Colab中使用它来自动生成代码。
有人能教我怎么做吗?
我想使用下面的代码从the.json文件中获取API密钥。
with open('GPT_SECRET_KEY.json') as f:
data = json.load(f)
openai.api_key = data["API_KEY"]
发布于 2021-07-19 14:32:40
要读取json文件,请执行以下操作:
import json
my_key = ''
with open('GPT_SECRET_KEY.json', 'r') as file_to_read:
json_data = json.load(file_to_read)
my_key = json_data["API_KEY"]
您的json文件的结构应该如下所示。
{
"API_KEY": "xxxxthis_is_the_key_you_are_targetingxxxx",
"API_KEY1": "xxxxxxxxxxxxxxxxxxxxxxx",
"API_KEY2": "xxxxxxxxxxxxxxxxxxxxxxx"
}
如果我的答案不够清楚,Here is a link会回答类似的问题。
https://stackoverflow.com/questions/68442098
复制相似问题