Added gpt-4 in /models

This commit is contained in:
Paillat
2023-03-17 11:27:25 +01:00
parent 0c3665f153
commit 60a88cc6c0
3 changed files with 17 additions and 16 deletions

View File

@@ -2,7 +2,7 @@ import discord
from config import debug, conn, c, moderate from config import debug, conn, c, moderate
from discord import default_permissions from discord import default_permissions
import openai import openai
models = ["davinci", "chatGPT"] models = ["davinci", "chatGPT", "gpt-4"]
images_recognition = ["enable", "disable"] images_recognition = ["enable", "disable"]
class Settings (discord.Cog) : class Settings (discord.Cog) :
def __init__(self, bot: discord.Bot) -> None: def __init__(self, bot: discord.Bot) -> None:
@@ -229,7 +229,7 @@ class Settings (discord.Cog) :
await ctx.respond("Model changed !", ephemeral=True) await ctx.respond("Model changed !", ephemeral=True)
async def images_recognition_autocomplete(ctx: discord.AutocompleteContext): async def images_recognition_autocomplete(ctx: discord.AutocompleteContext):
return [model for model in images_recognition if model.startswith(ctx.value)] return [state for state in images_recognition if state.startswith(ctx.value)]
@discord.slash_command(name="images", description="Enable or disable images recognition") @discord.slash_command(name="images", description="Enable or disable images recognition")
@discord.option(name="enable_disable", description="Enable or disable images recognition", autocomplete=images_recognition_autocomplete) @discord.option(name="enable_disable", description="Enable or disable images recognition", autocomplete=images_recognition_autocomplete)
@default_permissions(administrator=True) @default_permissions(administrator=True)

View File

@@ -13,7 +13,10 @@ logging.basicConfig(level=logging.INFO)
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./../database/google-vision/botator.json" os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./../database/google-vision/botator.json"
def debug(message): def debug(message):
#if the os is windows, we logging.info(message), if
if os.name == "nt":
logging.info(message) logging.info(message)
conn = sqlite3.connect('../database/data.db') conn = sqlite3.connect('../database/data.db')
c = conn.cursor() c = conn.cursor()
connp = sqlite3.connect('../database/premium.db') connp = sqlite3.connect('../database/premium.db')

View File

@@ -68,7 +68,7 @@ async def chat_process(self, message):
try: try:
c.execute("SELECT * FROM model WHERE guild_id = ?", (message.guild.id,)) # get the model in the database c.execute("SELECT * FROM model WHERE guild_id = ?", (message.guild.id,)) # get the model in the database
model = c.fetchone()[1] model = c.fetchone()[1]
except: model = "davinci" # if the model is not in the database, use davinci by default except: model = "chatGPT"
try: premium = cp.fetchone()[2] # get the premium status of the guild try: premium = cp.fetchone()[2] # get the premium status of the guild
except: premium = 0 # if the guild is not in the database, it's not premium except: premium = 0 # if the guild is not in the database, it's not premium
@@ -224,20 +224,19 @@ async def chat_process(self, message):
messages=msgs, messages=msgs,
max_tokens=512, # max tokens is 4000, that's a lot of text! (the max tokens is 2048 for the davinci model) max_tokens=512, # max tokens is 4000, that's a lot of text! (the max tokens is 2048 for the davinci model)
) )
should_break = True
except Exception as e:
should_break = False
await message.channel.send(f"```diff\n-Error: OpenAI API ERROR.\n\n{e}```", delete_after=5)
raise e
break
#if the ai said "as an ai language model..." we continue the loop" (this is a bug in the chatgpt model)
if response.choices[0].message.content.lower().find("as an ai language model") != -1: if response.choices[0].message.content.lower().find("as an ai language model") != -1:
should_break = False should_break = False
#react with a redone arrow #react with a redone arrow
await message.add_reaction("🔃") await message.add_reaction("🔃")
else: should_break = True
except Exception as e:
should_break = False
await message.channel.send(f"```diff\n-Error: OpenAI API ERROR.\n\n{e}```", delete_after=5)
#if the ai said "as an ai language model..." we continue the loop" (this is a bug in the chatgpt model)
if response == None: should_break = False if response == None: should_break = False
if should_break: break if should_break: break
await asyncio.sleep(5) await asyncio.sleep(15)
await message.channel.trigger_typing()
response = response.choices[0].message.content response = response.choices[0].message.content
if images_limit_reached == True: if images_limit_reached == True:
await message.channel.send(f"```diff\n-Warning: You have reached the image limit for this server. You can upgrade to premium to get more images recognized. More info in our server: https://discord.gg/sxjHtmqrbf```", delete_after=10) await message.channel.send(f"```diff\n-Warning: You have reached the image limit for this server. You can upgrade to premium to get more images recognized. More info in our server: https://discord.gg/sxjHtmqrbf```", delete_after=10)
@@ -290,10 +289,9 @@ async def chat_process(self, message):
if len(string) < 1996: if len(string) < 1996:
await message.channel.send(string, tts=tts) await message.channel.send(string, tts=tts)
else: else:
while len(string) > 1996: #we send in an embed if the message is too long
send_string = string[:1996] embed = discord.Embed(title="Botator response", description=string, color=discord.Color.brand_green())
string = string[1996:] await message.channel.send(embed=embed, tts=tts)
await message.channel.send(send_string, tts=tts)
for emoji in emojis: for emoji in emojis:
#if the emoji is longer than 1 character, it's a custom emoji #if the emoji is longer than 1 character, it's a custom emoji
try: try: