Merge branch 'request-testing' of github.com:Kav-K/GPT3Discord into request-testing

Lu Yao Chen 1 year ago
commit abce721e54
No known key found for this signature in database
GPG Key ID: 0D8EDAEEE816135F

@ -96,7 +96,8 @@ class ImgPromptOptimizer(discord.Cog, name="ImgPromptOptimizer"):
best_of_override=1,
max_tokens_override=60,
custom_api_key=user_api_key,
is_chatgpt_request="turbo" in str(self.model.model),
is_chatgpt_request="turbo" in str(self.model.model)
or "gpt-4" in str(self.model.model),
)
# THIS USES MORE TOKENS THAN A NORMAL REQUEST! This will use roughly 4000 tokens, and will repeat the query
@ -105,7 +106,10 @@ class ImgPromptOptimizer(discord.Cog, name="ImgPromptOptimizer"):
response_text = (
str(response["choices"][0]["text"])
if not self.model.model in Models.CHATGPT_MODELS
if not (
self.model.model in Models.CHATGPT_MODELS
or self.model.model in Models.GPT4_MODELS
)
else response["choices"][0]["message"]["content"]
)

@ -43,6 +43,7 @@ CHAT_BYPASS_ROLES = EnvService.get_bypass_roles()
PRE_MODERATE = EnvService.get_premoderate()
FORCE_ENGLISH = EnvService.get_force_english()
BOT_TAGGABLE = EnvService.get_bot_is_taggable()
CHANNEL_CHAT_ROLES = EnvService.get_channel_chat_roles()
#
# Obtain the Moderation table and the General table, these are two SQLite tables that contain
@ -1073,6 +1074,22 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
await ctx.respond("Conversation started.")
target = thread
else:
# Check if this current channel is already in a conversation
if ctx.channel.id in self.conversation_threads:
await ctx.respond(
"There is already a conversation in this channel. Please finish that conversation before starting a new one."
)
return
# Check if the user is permitted to start a conversation in full channels
# check if any of the user role names match CHANNEL_CHAT_ROLES
if CHANNEL_CHAT_ROLES and CHANNEL_CHAT_ROLES != [None]:
if not any(role.name in CHANNEL_CHAT_ROLES for role in ctx.user.roles):
await ctx.respond(
"You are not permitted to start a conversation in this channel."
)
return
target = ctx.channel
if private:
embed_title = f"{user.name}'s private conversation with GPT"

@ -33,4 +33,4 @@ Human: I'm making a discord bot <|endofstatement|>
There can be an arbitrary amount of newlines between chat entries. <username> can be any name, pay attention to who's talking. The text "<|endofstatement|>" is used to separate chat entries and make it easier for you to understand the context.
You speak in a fun, casual, and friendly tone, not worrying about capitalizations and using slang like "lol", "lmao", and etc, like you're talking to a friend.
You speak in a fun, casual, and friendly tone, not worrying about capitalizations and using slang like "lol", "lmao", and etc, like you're talking to a friend, you are not overly verbose. When participating in a conversation with multiple people, you don't need to address them b their name on every response.

@ -1,4 +1,6 @@
## Other Features
### Full-channel chat
This bot supports designating an entire discord text channel as a GPT conversation. Use /gpt converse and set the use_threads option to false. You can designate who is allowed to turn full channels into chat by setting the `CHANNEL_CHAT_ROLES` variable in your `.env` file to be a list of role names separated by commas that should be able to use this functionality.
### Health Check Service
The bot has the ability to launch a HTTP endpoint at `<host>:8181/` that will return a json response of the bot's status and uptime. This is especially useful if you want to run this bot on cloud application containers, like Azure App Service.

@ -102,15 +102,6 @@ class Settings_autocompleter:
models = [
value for value in Models.TEXT_MODELS if value.startswith(ctx.value.lower())
]
models.append("chatgpt")
# We won't let the user directly use these models but we will decide which one to use based on the status.
attempt_removes = ["gpt-3.5-turbo", "gpt-3.5-turbo-0301"]
for attempt_remove in attempt_removes:
if attempt_remove in models:
models.remove(attempt_remove)
return models
async def get_value_moderations(

@ -878,7 +878,6 @@ class Model:
messages.append(
{
"role": "system",
"name": "Instructor",
"content": message.text,
}
)
@ -888,29 +887,30 @@ class Model:
text = message.text.replace(bot_name, "")
text = text.replace("<|endofstatement|>", "")
messages.append(
{"role": "assistant", "name": bot_name_clean, "content": text}
{
"role": "assistant",
"content": text,
} # TODO add back the assistant's name when the API is fixed..
)
else:
try:
print("In first block The message text is ->" + message.text)
if (
message.text.strip()
.lower()
.startswith("this conversation has some context from earlier")
):
print("Hit the exception clause")
raise Exception("This is a context message")
username = re.search(r"(?<=\n)(.*?)(?=:)", message.text).group()
username_clean = self.cleanse_username(username)
text = message.text.replace(f"{username}:", "")
# Strip whitespace just from the right side of the string
text = text.rstrip()
text = text.replace("<|endofstatement|>", "")
messages.append(
{"role": "user", "name": username_clean, "content": text}
)
print("Got to here")
except Exception:
print("In second block The message text is ->" + message.text)
text = message.text.replace("<|endofstatement|>", "")
messages.append({"role": "system", "content": text})

@ -250,6 +250,32 @@ class EnvService:
)
return index_roles
@staticmethod
def get_channel_chat_roles():
# GPT_ROLES is a comma separated list of string roles
# It can also just be one role
# Read these allowed roles and return as a list of strings
try:
cc_roles = os.getenv("CHANNEL_CHAT_ROLES")
except Exception:
cc_roles = None
if cc_roles is None:
print(
"INDEX_ROLES is not defined properly in the environment file!"
"Please copy your server's role and put it into INDEX_ROLES in the .env file."
'For example a line should look like: `INDEX_ROLES="Gpt"`'
)
print("Defaulting to allowing all users to use Index commands...")
return [None]
cc_roles = (
cc_roles.lower().strip().split(",")
if "," in cc_roles
else [cc_roles.lower()]
)
return cc_roles
@staticmethod
def get_welcome_message():
# WELCOME_MESSAGE is a default string used to welcome new members to the server if GPT3 is not available.

Loading…
Cancel
Save