-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.py
137 lines (124 loc) · 4.24 KB
/
services.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import openai
import json
import sys
import requests
import os
from dotenv import load_dotenv
load_dotenv()
openai.api_key = os.getenv('OPENAI_API_KEY')
def codex(zice):
response = openai.Completion.create(
engine="davinci-codex",
prompt="\"\"\"\n"+zice+"\n\"\"\"",
temperature=0,
max_tokens=100,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
ceva = response.choices[0].text
return str(ceva)
def codx_simplify(zice):
response = openai.Completion.create(
engine="davinci-codex",
prompt="My second grader asked me what this passage means:\\n\"\"\"\\n"+zice +
"\\n\"\"\"\\nI rephrased it for him, in plain language a second grader can understand:\\n\"\"\"",
temperature=0,
max_tokens=200,
top_p=1,
frequency_penalty=0.2,
presence_penalty=0,
stop=["\"\"\""]
)
ceva = response.choices[0].text.split("\\n")[1]
return str(ceva)
def chat_neutral(zice):
response = openai.Completion.create(
engine="davinci-codex",
prompt=zice,
temperature=0.9,
max_tokens=50,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.6,
stop=["Human:", " AI:"]
)
ceva = response.choices[0].text
return str(ceva)
def chat_friendly(zice):
response = openai.Completion.create(
engine="davinci-codex",
prompt="You: What have you been up to?\\nFriend: Watching old movies.\\nYou: Did you watch anything interesting\\nFriend: Not really\\nYou: "+zice+"\\nFriend: ",
temperature=0.4,
max_tokens=60,
top_p=1,
frequency_penalty=0.5,
presence_penalty=0,
stop=["\\nYou:"]
)
ceva = response.choices[0].text
return str(ceva)
def chat_sarcastic(zice):
response = openai.Completion.create(
engine="davinci-codex",
prompt="Marv is a chatbot that reluctantly answers questions. You: How many pounds are in a kilogram? Marv: This again? There are 2.2 pounds in a kilogram. Please make a note of this. You: What does HTML stand for? Marv: Was Google too busy? Hypertext Markup Language. The T is for try to ask better questions in the future. You: When did the first airplane fly? Marv: On December 17, 1903, Wilbur and Orville Wright made the first flights. I wish they’d come and take me away. You: What is the meaning of life? Marv: I’m not sure. I’ll ask my friend Google. You: "+zice+". Marv:",
temperature=0.3,
max_tokens=60,
top_p=0.3,
frequency_penalty=0.5,
presence_penalty=0.0,
stop=["Marv:", "You: "]
)
ceva = response.choices[0].text
return str(ceva)
def codx_qna(zice):
response = openai.Completion.create(
engine="davinci-codex",
prompt="\\nQ: "+zice+"\\nA:",
temperature=0,
max_tokens=100,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
stop=["\\n"]
)
try:
dobis = response.choices[0].text.split("\\n")[0]
return str(dobis)
except Exception as e:
return response.choices[0].text
def codx_xplain(zice):
response = response = openai.Completion.create(
engine="davinci-codex",
prompt=zice+"\\n'''\\n#here's what the above code is doing:\\n#1.",
temperature=0,
max_tokens=64,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
stop=["\\""\\""\\"""]
)
print(response)
ceva = response.choices[0].text
return str(ceva)
def call_direct_chatbot(zice, uid):
url =os.getenv('CHATBOT_URL')
querystring = {"bid": os.getenv('bid'), "key": os.getenv('key'),
"uid": uid, "msg": zice}
headers = {
'x-rapidapi-host': os.getenv('x-rapidapi-host'),
'x-rapidapi-key': os.getenv('x-rapidapi-key')
}
response = requests.request(
"GET", url, headers=headers, params=querystring)
return response.text.split("cnt\":\"")[1].split("\"")[0]
def restart():
# global connection
import sys
print("argv was", sys.argv)
print("sys.executable was", sys.executable)
print("restart now")
import os
# connection.commit()
# connection.close()
os.execv(sys.executable, ['python'] + sys.argv)