forked from SamurAIGPT/Text-To-Video-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
34 lines (30 loc) · 1.15 KB
/
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
27
28
29
30
31
32
33
34
import os
from datetime import datetime
import json
# Log types
LOG_TYPE_GPT = "GPT"
LOG_TYPE_PEXEL = "PEXEL"
# log directory paths
DIRECTORY_LOG_GPT = ".logs/gpt_logs"
DIRECTORY_LOG_PEXEL = ".logs/pexel_logs"
# method to log response from pexel and openai
def log_response(log_type, query,response):
log_entry = {
"query": query,
"response": response,
"timestamp": datetime.now().isoformat()
}
if log_type == LOG_TYPE_GPT:
if not os.path.exists(DIRECTORY_LOG_GPT):
os.makedirs(DIRECTORY_LOG_GPT)
filename = '{}_gpt3.txt'.format(datetime.now().strftime("%Y%m%d_%H%M%S"))
filepath = os.path.join(DIRECTORY_LOG_GPT, filename)
with open(filepath, "w") as outfile:
outfile.write(json.dumps(log_entry) + '\n')
if log_type == LOG_TYPE_PEXEL:
if not os.path.exists(DIRECTORY_LOG_PEXEL):
os.makedirs(DIRECTORY_LOG_PEXEL)
filename = '{}_pexel.txt'.format(datetime.now().strftime("%Y%m%d_%H%M%S"))
filepath = os.path.join(DIRECTORY_LOG_PEXEL, filename)
with open(filepath, "w") as outfile:
outfile.write(json.dumps(log_entry) + '\n')