-
Notifications
You must be signed in to change notification settings - Fork 0
/
fullEmail_gpt.py
51 lines (38 loc) · 1.7 KB
/
fullEmail_gpt.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
import openai
def fullEmail_gpt_request(clean_blast):
openai.api_key = "INSERT_API_KEY"
initialPrompt = "Name and only include the events with free food, drinks, breakfast, lunch, or dinner in the following email. Only list the name of the event and nothing else. Write the characters ##### between each event:"
final_prompt = initialPrompt + clean_blast
response = openai.Completion.create(
engine="text-davinci-003",
prompt=final_prompt,
temperature=0.7,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
event_string = response['choices'][0]['text']
#print(event_string)
secondPrompt = "Name the events with free food or drinks in the following email. Use this format [event name, time, date, location, type of food/drink]. Separate each event by '####'"
final_prompt = secondPrompt + clean_blast
with open("rawEvents.txt", "a") as file:
# Get the events with free food/drink from the API
response = openai.Completion.create(
engine="text-davinci-003",
prompt=final_prompt,
temperature=0.3,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
shallowEvents = response['choices'][0]['text']
# Split the events by the delimiter
rawShallowEvents = shallowEvents.split("####")
# Iterate through the events
for event in rawShallowEvents:
# Write the events to the txt file
if "location tbd" not in event.lower() and "N/A" not in event and "No" not in event:
file.write(event +"\n")
return event_string