Fix loading OpenAI API key from ~/.r2ai.openai-key

This commit is contained in:
pancake 2024-02-29 00:59:17 +01:00
parent 52b6c26fcf
commit fc2b4342c3
1 changed files with 3 additions and 1 deletions

View File

@ -22,7 +22,9 @@ sys.path.append(f"vectordb")
OPENAI_KEY = ""
try:
if "HOME" in os.environ:
os.environ["OPENAI_KEY"] = slurp(os.environ["HOME"] + "/.r2ai.openai-key").strip()
from r2ai.utils import slurp
apikey = slurp(os.environ["HOME"] + "/.r2ai.openai-key").strip()
os.environ["OPENAI_API_KEY"] = apikey
print("[R2AI] OpenAI key loaded from ~/.r2ai.openai-key")
except:
pass