-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchatter.py
73 lines (62 loc) · 2.26 KB
/
chatter.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
import os
from dotenv import load_dotenv
import revChatGPT
from revChatGPT.V3 import Chatbot
load_dotenv()
api_key = os.environ.get("CHATGPT_API_KEY")
chatbot = Chatbot(api_key)
class Chatter:
def __init__(self):
"""Chatter is a wrapper of the Reverse Engineered ChatGPT"""
self.chatbot = Chatbot(api_key)
return None
def get_response(self, prompt):
"""Basic ChatGPT query. Give a prompt, get a response.
Parameters
----------
prompt : str
the instructions/dialogue provided to ChatGPT
"""
response = ""
for data in self.chatbot.ask(prompt):
response += data
return response.strip()
def parse_tweet_job(self, job):
"""Creates a prompt from a tweet job dict
Parameters
----------
job : dict
expects a tweet job dict with the following keys:
{
"topic": topic,
"message": message,
"tone": tone,
"act_like": act_like,
}
"""
prompt = f"Write a tweet in the style of {job['act_like']} about {job['topic']} with a {job['tone']} tone. Message: {job['message']}."
return prompt
def tweets_from_job(self, job, num_options=2):
"""Given a tweet job dict, generates tweet options.
Parameters
----------
job : dict
expects a tweet job dict with the following keys:
{
"topic": topic,
"message": message,
"tone": tone,
"act_like": act_like,
}
num_options : int, optional
the number of tweet options to generate, by default 2
"""
prompts = [
f"Write a short tweet in the style of {job['act_like']} about {job['topic']} with a {job['tone']} tone. Message: {job['message']}.",
f"Write a thread of 1-4 tweets in the style of {job['act_like']} about {job['topic']} with a {job['tone']} tone. Message: {job['message']}.",
]
options = []
for prompt in prompts:
tweet = self.get_response(prompt)
options.append(tweet)
return options