-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment.py
104 lines (87 loc) · 3.74 KB
/
environment.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import configparser
import feedparser
import os
import time
from datetime import datetime
from utils import create_dir
def parse_authors(lines):
# parse the comma-separated author list, ignoring lines that are empty and starting with #
author_ids = []
authors = []
for line in lines:
if line.startswith("#"):
continue
if not line.strip():
continue
author_split = line.split(",")
author_ids.append(author_split[1].strip())
authors.append(author_split[0].strip())
return authors, author_ids
# load config.ini
CONFIG = configparser.ConfigParser()
CONFIG.read("configs/config.ini")
print({section: dict(CONFIG[section]) for section in CONFIG.sections()})
print(f"###################################################################")
# load authors.txt
with open("configs/authors.txt", "r", encoding="utf-8") as fopen:
author_names, author_ids = parse_authors(fopen.readlines())
AUTHOR_ID_SET = set(author_ids)
# load prompts
with open("prompts/base_prompt.txt", "r", encoding="utf-8") as f:
BASE_PROMPT = f.read()
with open("prompts/paper_topics.txt", "r", encoding="utf-8") as f:
TOPIC_PROMPT = f.read()
with open("prompts/score_criteria.txt", "r", encoding="utf-8") as f:
SCORE_PROMPT = f.read()
with open("prompts/postfix_prompt.txt", "r", encoding="utf-8") as f:
POSTFIX_PROMPT = f.read()
# keys
S2_API_KEY = os.environ.get("S2_KEY")
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
OPENAI_BASE_URL = os.environ.get("OPENAI_BASE_URL")
SLACK_KEY = os.environ.get("SLACK_KEY")
SLACK_CHANNEL_ID = os.environ.get("SLACK_CHANNEL_ID")
print(f"S2_API_KEY: {S2_API_KEY}")
print(f"OPENAI_API_KEY: {OPENAI_API_KEY}")
print(f"OPENAI_BASE_URL: {OPENAI_BASE_URL}")
print(f"SLACK_KEY: {SLACK_KEY}")
print(f"SLACK_CHANNEL_ID: {SLACK_CHANNEL_ID}")
if OPENAI_API_KEY is None:
raise ValueError("OpenAI key is not set - please set OPENAI_API_KEY to your OpenAI key")
# now time
try:
# get from ArXiv
feed = feedparser.parse("https://export.arxiv.org/rss/cs.LG") # use the cs.LG area
if len(feed.entries) > 0:
# Example `feed.published`: "Tue, 18 Feb 2025 00:00:00 -0500"
parsed_time = datetime.strptime(feed.entries[0].published, "%a, %d %b %Y %H:%M:%S %z")
NOW_YEAR = parsed_time.strftime("%Y")
NOW_MONTH = parsed_time.strftime("%m")
NOW_DAY = parsed_time.strftime("%d")
else:
raise ValueError("Feed does not contain any entries")
except Exception as e:
# use local time
NOW_YEAR = time.strftime("%Y")
NOW_MONTH = time.strftime("%m")
NOW_DAY = time.strftime("%d")
print(f"NOW_YEAR: {NOW_YEAR}")
print(f"NOW_MONTH: {NOW_MONTH}")
print(f"NOW_DAY: {NOW_DAY}")
# output path
OUTPUT_DEBUG_DIR = os.path.join(CONFIG["OUTPUT"]["output_path"], "debug", f"{NOW_YEAR}-{NOW_MONTH}", f"{NOW_YEAR}-{NOW_MONTH}-{NOW_DAY}")
OUTPUT_DEBUG_FILE_FORMAT = os.path.join(OUTPUT_DEBUG_DIR, "{}")
create_dir(OUTPUT_DEBUG_DIR)
OUTPUT_MD_DIR = os.path.join(CONFIG["OUTPUT"]["output_path"], "md", f"{NOW_YEAR}-{NOW_MONTH}")
OUTPUT_MD_FILE_FORMAT = os.path.join(OUTPUT_MD_DIR, f"{NOW_YEAR}-{NOW_MONTH}-{NOW_DAY}-" + "{}")
create_dir(OUTPUT_MD_DIR)
OUTPUT_JSON_DIR = os.path.join(CONFIG["OUTPUT"]["output_path"], "json", f"{NOW_YEAR}-{NOW_MONTH}")
OUTPUT_JSON_FILE_FORMAT = os.path.join(OUTPUT_JSON_DIR, f"{NOW_YEAR}-{NOW_MONTH}-{NOW_DAY}-" + "{}")
create_dir(OUTPUT_JSON_DIR)
print(f"OUTPUT_DEBUG_DIR: {OUTPUT_DEBUG_DIR}")
print(f"OUTPUT_DEBUG_FILE_FORMAT: {OUTPUT_DEBUG_FILE_FORMAT}")
print(f"OUTPUT_MD_DIR: {OUTPUT_MD_DIR}")
print(f"OUTPUT_MD_FILE_FORMAT: {OUTPUT_MD_FILE_FORMAT}")
print(f"OUTPUT_JSON_DIR: {OUTPUT_JSON_DIR}")
print(f"OUTPUT_JSON_FILE_FORMAT: {OUTPUT_JSON_FILE_FORMAT}")
print(f"###################################################################")