File size: 449 Bytes
d75499c 2e81bd8 d75499c 2e81bd8 d75499c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import json
import os
# 构建config.json文件的路径
config_file_path = os.path.join("config", "config.json")
# 读取配置文件
with open(config_file_path, "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
|