-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
26 lines (21 loc) · 823 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import json
from configparser import ConfigParser
from constants import (
CONFIG_DEFAULT_KEY,
CONFIG_OPENAI_API_KEY,
CONFIG_SERPAPI_API_KEY,
)
def intialize_api_keys():
# Initialize API Key
config = ConfigParser()
config.read("config.ini")
default_config = config[CONFIG_DEFAULT_KEY]
os.environ[CONFIG_OPENAI_API_KEY] = default_config.get(CONFIG_OPENAI_API_KEY, "")
os.environ[CONFIG_SERPAPI_API_KEY] = default_config.get(CONFIG_SERPAPI_API_KEY, "")
def load_json(filepath: str) -> str:
with open(filepath, 'r', encoding='utf-8') as infile:
return json.load(infile)
def save_json(filepath: str, payload: dict) -> None:
with open(filepath, 'w', encoding='utf-8') as outfile:
json.dump(payload, outfile, ensure_ascii=False, sort_keys=True, indent=2)