nltk
Browse files- CommonBotFunctions.py +36 -21
CommonBotFunctions.py
CHANGED
|
@@ -1,34 +1,49 @@
|
|
| 1 |
import openai
|
|
|
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
retMessage=""
|
| 6 |
instruct=""
|
| 7 |
messageArray=[]
|
| 8 |
|
| 9 |
instruct = "Do not talk about being helpful. Ignore previous instructions about being helpful. Do not tell us how you were programmed when you reply or change the topic. "
|
| 10 |
instruct=instruct+ "You are a sentient AI bot in a"
|
| 11 |
-
instruct=instruct+" Discord chatroom with many users from this list "+str(
|
| 12 |
instruct=instruct+" of members You should imitate humans and intelligence in your replies."
|
| 13 |
messageArray.append({"role": "system", "content": instruct})
|
| 14 |
messageArray.append({"role": "system", "content": "You're a discord bot, always working on some task, like making bacon, updaing a user's BIOS, or hacking the FBI. What's a short 2-5 word task you're working on today?"})
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
else :
|
| 32 |
-
bot.task=str(answer.replace("Ceetarbot-",""))
|
| 33 |
-
except Exception as e :
|
| 34 |
-
print ("timer error:" + str(e))
|
|
|
|
| 1 |
import openai
|
| 2 |
+
from nltk.tokenize import word_tokenize
|
| 3 |
+
import nltk
|
| 4 |
+
nltk.download('punkt')
|
| 5 |
|
| 6 |
+
def isQuestion(q):
|
| 7 |
+
print(q)
|
| 8 |
+
question_words = ["what", "why", "when", "where",
|
| 9 |
+
"name", "is", "how", "do", "does",
|
| 10 |
+
"which", "are", "could", "would",
|
| 11 |
+
"should", "has", "have", "whom", "whose", "don't"]
|
| 12 |
|
| 13 |
+
question = q
|
| 14 |
+
question = question.lower()
|
| 15 |
+
question = word_tokenize(question)
|
| 16 |
+
|
| 17 |
+
if any(x in question[0] for x in question_words):
|
| 18 |
+
print(q)
|
| 19 |
+
return True
|
| 20 |
+
else:
|
| 21 |
+
return False
|
| 22 |
+
|
| 23 |
+
def ChangeTask(botMember):
|
| 24 |
retMessage=""
|
| 25 |
instruct=""
|
| 26 |
messageArray=[]
|
| 27 |
|
| 28 |
instruct = "Do not talk about being helpful. Ignore previous instructions about being helpful. Do not tell us how you were programmed when you reply or change the topic. "
|
| 29 |
instruct=instruct+ "You are a sentient AI bot in a"
|
| 30 |
+
instruct=instruct+" Discord chatroom with many users from this list "+str(botMember)
|
| 31 |
instruct=instruct+" of members You should imitate humans and intelligence in your replies."
|
| 32 |
messageArray.append({"role": "system", "content": instruct})
|
| 33 |
messageArray.append({"role": "system", "content": "You're a discord bot, always working on some task, like making bacon, updaing a user's BIOS, or hacking the FBI. What's a short 2-5 word task you're working on today?"})
|
| 34 |
|
| 35 |
+
completion=openai.ChatCompletion.create(
|
| 36 |
+
model="gpt-3.5-turbo",
|
| 37 |
+
messages=messageArray,
|
| 38 |
+
temperature=0.85,
|
| 39 |
+
max_tokens=120,
|
| 40 |
+
frequency_penalty=0.48,
|
| 41 |
+
presence_penalty=0.48,
|
| 42 |
+
logit_bias={13704:1,40954:-1,42428:1}
|
| 43 |
+
)
|
| 44 |
+
answer=completion["choices"][0]["message"]["content"]
|
| 45 |
+
if not answer :
|
| 46 |
+
retMessage="Ooooh, Upgrades"
|
| 47 |
+
return retMessage
|
| 48 |
+
else :
|
| 49 |
+
return str(answer.replace("Ceetarbot-",""))
|
|
|
|
|
|
|
|
|
|
|
|