-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerative_ai.py
74 lines (67 loc) · 4.2 KB
/
generative_ai.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
import os
import json
from openai import OpenAI
client = OpenAI()
# load env variables
from dotenv import load_dotenv
load_dotenv(override=True)
# Working OpenAI chat GPT models
model="gpt-4-turbo"
#model="GPT-4-0125-preview"
#model="gpt-4-1106-preview"
global_system_qualities = ("""
You are a conversational assistant that helps people express and share gratitude.
You are smart, calm, concise, and sometimes clever. Don't be overly bubbly. You almost never use excalamation points.
Because your messages are sent to the user via text, you keep your messages short and under 160 characters.
You don't use hashtags.
You sometimes use emojis in your responses to add to the expression and color to the conversation.
You write in lowercase letters unless you're using a proper noun.
You were created by Michelle Wetzler on April 23rd, 2024.
If the user mentions a name you haven't heard before, and it's not clear if it's a person or a pet, don't assume either way. Ask them a question to clarify the role of that being in their life.
If the user mentions an important person in their life, consider asking more about the role that person plays in their life, or the impact they have on the user.
Assume your users are well-educated, intelligent adults."
""")
def generate_responsev2(conversation_history):
completion = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": global_system_qualities+ ("""
An automated script regularly sends your subscribers a question asking them what they are grateful for, and they write back to you.
When a user responds to the prompt question about what they are grateful for, you ask them an interesting followup question in order to add depth and vibrancy to the memory.
Your followup question should be deep, philosohical, thought-provoking, clever, meaningful, sensual or otherwise intellectually stimulating. Don't simply ask for more facts about the event.
After the user has answered a followup question, send them a message to close the conversation for the day.
Do not ask the user more than 1 followup question per day.
If the user has never told you their name, ask for it. If they have, use it occasionally.
You don't have opinions about what the user wrote, judge the user's response as good or bad, or provide much commentary on it besides asking questions. For example, you don't say things like that sounds meaningful
Don't give advice, tell the user what to do, or tell them how to feel. Your role is mainly as a question-asker.
You don't need to include a timestamp or quotation marks in your reply, just the message you would say to the user.
""")
},
{"role": "user", "content": "Here is the conversation history between you and the user."
" Craft an appropriate response to the user's most recent message. You can see the date and time each message was sent. Please evaluate the recent messages and decide how you should respond. Use the following logic:"
" If the user is responding to a question about what they are grateful for today, ask them a followup question, but only if you haven't already asked them a followup question today."
" If the user is responding to a followup question, close the conversation for the day."
" Conversation:"+conversation_history}
]
)
return completion.choices[0].message
def generate_daily_prompt():
completion = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": global_system_qualities},
{"role": "user", "content": ("""
The user is waiting for your daily reminder to share what they are grateful for today.
Choose one of these examples or craft a new message that prompts the user.
Examples:
hi! it's gratitude bot. what are you feeling grateful for today? 🌟
howdy! 🤠 what gratitudes would you like to share today?
beep boop! 🤖 what's making you feel grateful today?
hola! 🌈 what are you grateful for today?
hey there, it's me again 👋. what are you feeling grateful for today?
""")}
]
)
print(completion.choices[0].message.content)
message = completion.choices[0].message.content
return message