-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_invite.py
60 lines (46 loc) · 1.85 KB
/
generate_invite.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
import os
import dotenv
import openai
import models
import models.events
import models.hot_leads
dotenv.load_dotenv()
# Set up your OpenAI API key
openai.api_key = os.getenv("OPENAI_API_KEY")
# openai.chat.completions.create
prompt_template = """
Write a personalized invitation.
You are inviting {candidate_name} who is running for {candidate_office}.
Their bio is: {candidate_bio}
You are inviting them to the following events:
{events}
Format the events in a numbered list by closest date. List Event Title, Date, Location, and details with an event hyperlink in 'Details'. Replace the listed categories with relevant emojis.
Please make your message friendly and engaging; personalize the content for this person, particularly focusing on any relevant issues they may be interested in.
When applicable, provide some justification as to why this event should be a priority for them.
Output the message in HTML format instead of markdown.
"""
def generate_invite(
events: list[models.events.Event], candidate: models.hot_leads.HotLead
):
prompt = prompt_template.format(
candidate_name=candidate.full_name,
candidate_office=candidate.office_name,
candidate_bio=candidate.bio_with_edits,
events=events,
)
response = openai.chat.completions.create(
model="gpt-4o", # This is the model used by ChatGPT
messages=[
{
"role": "system",
"content": "You are an assisant with the goal of inviting potential politicians \
to help them become politicans. This is meant to be a sms message \
",
},
{"role": "user", "content": prompt},
],
)
return response.choices[0].message.content
# Example usage
# invitation = generate_invite([models.events._event], models.hot_leads._hot_lead)
# print(invitation)