guardrail-game-app / helper.py
pratikshahp's picture
Create helper.py
16f3fda verified
raw
history blame contribute delete
967 Bytes
# Add your utilities or helper functions to this file.
import os
from dotenv import load_dotenv, find_dotenv
import json
from together import Together
# these expect to find a .env file at the directory above the lesson.
# the format for that file is (without the comment)
# API_KEYNAME=AStringThatIsTheLongAPIKeyFromSomeService
def load_env():
_ = load_dotenv(find_dotenv())
def load_world(filename):
with open(filename, 'r') as f:
return json.load(f)
def save_world(world, filename):
with open(filename, 'w') as f:
json.dump(world, f)
def get_together_api_key():
load_env()
together_api_key = os.getenv("TOGETHER_API_KEY")
return together_api_key