From 6e48f089fbcde9739a25bc9fa485fe90c9d1d84e Mon Sep 17 00:00:00 2001 From: Soulsender Date: Fri, 6 Sep 2024 20:45:46 -0700 Subject: [PATCH] added ask frong --- cogs/ask-frong.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 cogs/ask-frong.py diff --git a/cogs/ask-frong.py b/cogs/ask-frong.py new file mode 100644 index 0000000..0c8ae31 --- /dev/null +++ b/cogs/ask-frong.py @@ -0,0 +1,34 @@ +import nextcord +from nextcord.ext import commands +from dotenv import load_dotenv +import openai +import os + +openai.api_key = str(os.getenv('OPENAI_KEY')) + +def ask_chatgpt(question): + response = openai.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": question}, + ] + ) + return response['choices'][0]['message']['content'] + +class AskFrong(commands.Cog): + def __init__(self,bot): + self.bot=bot + + @commands.Cog.listener() + async def on_ready(self): + print(f"ask-frong - Loaded") + + # for testing add guild_ids=[guild_id] + @nextcord.slash_command(name="askfrong", description="Ask the almighty.", guild_ids=[414625175217242113]) + async def askfrong(self, interaction: nextcord.Interaction, question): + answer = ask_chatgpt(question) + await interaction.response.send_message(f"{answer}") + +def setup(bot): + bot.add_cog(AskFrong(bot)) \ No newline at end of file