File size: 353 Bytes
d75499c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import json
import os
# 读取配置文件
with open("config.json", "r") as config_file:
config = json.load(config_file)
# 设置环境变量
os.environ["OPENAI_API_KEY"] = config.get("OPENAI_API_KEY")
#获取api_key函数
def get_api_key(key):
if key == '':
openai.api_key = os.environ.get('OPENAI_API_KEY')
openai.api_key = key
|