Spaces:
Sleeping
Sleeping
pratikshahp
commited on
Create helper.py
Browse files
helper.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Add your utilities or helper functions to this file.
|
2 |
+
|
3 |
+
import os
|
4 |
+
from dotenv import load_dotenv, find_dotenv
|
5 |
+
import json
|
6 |
+
from together import Together
|
7 |
+
|
8 |
+
# these expect to find a .env file at the directory above the lesson.
|
9 |
+
# the format for that file is (without the comment)
|
10 |
+
# API_KEYNAME=AStringThatIsTheLongAPIKeyFromSomeService
|
11 |
+
def load_env():
|
12 |
+
_ = load_dotenv(find_dotenv())
|
13 |
+
|
14 |
+
def load_world(filename):
|
15 |
+
with open(filename, 'r') as f:
|
16 |
+
return json.load(f)
|
17 |
+
|
18 |
+
def save_world(world, filename):
|
19 |
+
with open(filename, 'w') as f:
|
20 |
+
json.dump(world, f)
|
21 |
+
|
22 |
+
def get_together_api_key():
|
23 |
+
load_env()
|
24 |
+
together_api_key = os.getenv("TOGETHER_API_KEY")
|
25 |
+
return together_api_key
|