-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (54 loc) · 1.53 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
import openai
import os
import json
from better_profanity import profanity
import sys ## from sys import exit
## FOR THE CENSOR
if __name__ == "__main__":
profanity.load_censor_words()
## SET UP API KEY
ai_key = os.environ['open_ai_key']
## SET THE KEY TO THE KEY THEN DEF OPEN_AI FUNCTION (RESPONSE)
openai.api_key = ai_key
def open_ai(content):
response = openai.Completion.create(
engine="text-davinci-002",
prompt=content,
temperature=0.5,
max_tokens=1000,
top_p=1.0,
frequency_penalty=0.5,
presence_penalty=0.0,
)
json_data = json.loads(str(response))
text = (str(json_data['choices'][0]['text']))
return text
## DEF THE ASK AI FUNCTION WHICH RUNS THE QUESTIONS
def askAi():
type = str(input("A story or letter or other?: "))
abto = str(input("A " + type + " about or to someone?: "))
abto = abto.lower()
if abto == "to":
about = str(input("A " + type + " " + abto + " and about" + "?: "))
else:
about = str(input("A " + type + " " + abto + "?: "))
#.lower() the words
type = type.lower()
about = about.lower()
about = about + "."
content = ("make a 1000 word" + type + " " + abto + about)
content = content.lower()
response = open_ai(content)
censored_response = profanity.censor(response) ## run the censor
print(censored_response) ## print the censored text
## loop constantly until it's time to quit
while True:
askAi()
quit = input("Would you like to quit, y/n?: ")
quit = quit.upper()
if quit == "Y":
sys.exit
break
else:
print("Continuing")
print("")