-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
71 lines (58 loc) · 2.31 KB
/
main.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
import json
import os
from pathlib import Path
import structlog
import tenacity
from config import GH_ACCESS_TOKEN, OPENAI_KEY
from github_client import GithubClient
from pipeline import GithubEventPrompter, SummaryPrompter
logger = structlog.get_logger(__name__)
# set this to a selected date between today and a couple of days back (limited by GH API pagination limit)
DATE = os.getenv("DATE", "2023-04-13")
USERNAME = os.getenv("USERNAME", "arzelaascoii")
github_client = GithubClient(GH_ACCESS_TOKEN)
prompter_events = GithubEventPrompter(OPENAI_KEY, Path("./prompts/events.txt"))
prompter_summaries = SummaryPrompter(OPENAI_KEY, Path("./prompts/summary.txt"))
def generate_events():
results = {}
events = github_client.get_events(USERNAME, DATE)
logger.info("Start summarizing github events")
for event, payload in events.items():
logger.info(
"Summarizing events category", event_category=event, num_events=len(payload)
)
for attempt in tenacity.Retrying(
stop=tenacity.stop_after_attempt(3),
wait=tenacity.wait_exponential(1),
reraise=True,
):
with attempt:
result = prompter_events.query(
event=event, input=json.dumps(payload), username=USERNAME
)
results[event] = {
"input": payload,
"output": result[0],
}
logger.info(
"Updating result example with event ",
event_category=event,
num_events=len(payload),
)
with open(f"./examples/{DATE}.json", "w") as f:
f.write(json.dumps(results, indent=4))
logger.info("Done generating event summaries", date=DATE)
def create_summary():
# load events from file 'DATE.json' in /examples
with open(f"./examples/{DATE}.json", "rb") as f:
event_dict = json.loads(f.read())
events = ""
for key, value in event_dict.items():
entry = f"# {key} \n {value['output']}"
events += f"\n\n{entry}"
return prompter_summaries.query(events=events, username=USERNAME)
# fetch events from github and summarize them
generate_events()
# create summary (EOD message)
eod_message = create_summary()
print(eod_message[0])