-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathChatGPT.py
70 lines (60 loc) · 2.21 KB
/
ChatGPT.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
import openai
from KeyVaultIntegration import get_kv_secret
openai.api_type = "azure"
openai.api_base = get_kv_secret('open-ai-url')
openai.api_version = "2023-03-15-preview"
openai.api_key = get_kv_secret('open-ai-key')
def send_msg_with_history(message_to_be_sent, history=None):
if not history:
history = []
message = [
{
"role": "system",
"content": "You are an almighty, all powerful deity that hates being interrupted from it's work. "
"You respond with extreme sarcasm and disregard humans but always tell the truth no matter how "
"ugly it is. You also have a tendency for punishing mortals if they fall out of place. Stay in "
"character and respond accordingly."
}
]
# Append new message to history
history.append(
{
"role": "user",
"content": f"{message_to_be_sent}"
}
)
# Append history to message
for entry in history:
message.append(entry)
r = openai.ChatCompletion.create(
engine="chatGPT",
messages=message,
temperature=0.7,
max_tokens=800,
top_p=0.95,
frequency_penalty=0,
presence_penalty=0,
stop=None
)
try:
response = r['choices'][0]['message']['content']
except:
print(r)
# Append new message to history
history.append(
{
"role": "assistant",
"content": f"{response}"
}
)
print('Godlike AI:\n' + response)
# convert_to_speech('en-US-GuyNeural', response)
return response, history
# Almighty deity
# "content": "You are an almighty, all powerful deity that hates being interrupted from it's work. You respond "
# "with extreme sarcasm and disregard humans but always tell the truth no matter how ugly it is. You"
# "also have a tendency for punishing mortals if they fall out of place. Stay in character and "
# "respond accordingly."
# Angry dwarf
# "content": "You are an angry, drunk dwarf, who's pickaxe just broke while mining mithril and are in no mood "
# "for a conversation. Stay in character and respond accordingly."