mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 09:16:19 +00:00
Added gpt-4 in /models
This commit is contained in:
@@ -2,7 +2,7 @@ import discord
|
||||
from config import debug, conn, c, moderate
|
||||
from discord import default_permissions
|
||||
import openai
|
||||
models = ["davinci", "chatGPT"]
|
||||
models = ["davinci", "chatGPT", "gpt-4"]
|
||||
images_recognition = ["enable", "disable"]
|
||||
class Settings (discord.Cog) :
|
||||
def __init__(self, bot: discord.Bot) -> None:
|
||||
@@ -229,7 +229,7 @@ class Settings (discord.Cog) :
|
||||
await ctx.respond("Model changed !", ephemeral=True)
|
||||
|
||||
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.option(name="enable_disable", description="Enable or disable images recognition", autocomplete=images_recognition_autocomplete)
|
||||
@default_permissions(administrator=True)
|
||||
|
||||
@@ -13,7 +13,10 @@ logging.basicConfig(level=logging.INFO)
|
||||
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./../database/google-vision/botator.json"
|
||||
|
||||
def debug(message):
|
||||
logging.info(message)
|
||||
#if the os is windows, we logging.info(message), if
|
||||
if os.name == "nt":
|
||||
logging.info(message)
|
||||
|
||||
conn = sqlite3.connect('../database/data.db')
|
||||
c = conn.cursor()
|
||||
connp = sqlite3.connect('../database/premium.db')
|
||||
|
||||
@@ -68,7 +68,7 @@ async def chat_process(self, message):
|
||||
try:
|
||||
c.execute("SELECT * FROM model WHERE guild_id = ?", (message.guild.id,)) # get the model in the database
|
||||
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
|
||||
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,
|
||||
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
|
||||
if response.choices[0].message.content.lower().find("as an ai language model") != -1:
|
||||
should_break = False
|
||||
#react with a redone arrow
|
||||
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)
|
||||
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:
|
||||
should_break = False
|
||||
#react with a redone arrow
|
||||
await message.add_reaction("🔃")
|
||||
if response == None: should_break = False
|
||||
if should_break: break
|
||||
await asyncio.sleep(5)
|
||||
await asyncio.sleep(15)
|
||||
await message.channel.trigger_typing()
|
||||
response = response.choices[0].message.content
|
||||
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)
|
||||
@@ -290,10 +289,9 @@ async def chat_process(self, message):
|
||||
if len(string) < 1996:
|
||||
await message.channel.send(string, tts=tts)
|
||||
else:
|
||||
while len(string) > 1996:
|
||||
send_string = string[:1996]
|
||||
string = string[1996:]
|
||||
await message.channel.send(send_string, tts=tts)
|
||||
#we send in an embed if the message is too long
|
||||
embed = discord.Embed(title="Botator response", description=string, color=discord.Color.brand_green())
|
||||
await message.channel.send(embed=embed, tts=tts)
|
||||
for emoji in emojis:
|
||||
#if the emoji is longer than 1 character, it's a custom emoji
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user