Download src/get_api_key.py from kkAIGC/SQLBot: direct link, hf CLI and curl.
- Browser
- Download file 449 Bytes
-
https://huggingface.co/spaces/kkAIGC/SQLBot/resolve/e3f66aa03cc1eaf24d4480233bf429cd41e2707f/src/get_api_key.py
- Command line
-
hf download hf://spaces/kkAIGC/SQLBot@e3f66aa03cc1eaf24d4480233bf429cd41e2707f/src/get_api_key.py
-
curl -L -o get_api_key.py https://huggingface.co/spaces/kkAIGC/SQLBot/resolve/e3f66aa03cc1eaf24d4480233bf429cd41e2707f/src/get_api_key.py
449 Bytes
| 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 | |