diff --git a/app/cogs/gpt.py b/app/cogs/gpt.py new file mode 100755 index 00000000..f77cea7e --- /dev/null +++ b/app/cogs/gpt.py @@ -0,0 +1,31 @@ +from discord import option +from discord.ext import commands + + +class Gpt(commands.Cog): + def __init__(self, bot): + self.bot: commands.Bot = bot + + @commands.slash_command( + guild_ids=None, + name="gpt", + description="Ask dalebot a question, he'll do his best to answer", + ) + @option( + name="prompt", + description="What you want to ask dale-bot", + required=True, + ) + async def gpt(self, ctx: commands.Context, prompt): + import gpt + + # try: + await ctx.defer() + embed = gpt.answer_question(prompt) + await ctx.send_followup(embed=embed) + # except Exception as e: + # await ctx.send(e) + + +def setup(bot): + bot.add_cog(Gpt(bot)) diff --git a/app/gpt.py b/app/gpt.py new file mode 100644 index 00000000..84de352f --- /dev/null +++ b/app/gpt.py @@ -0,0 +1,31 @@ +import discord +import json +import requests + + +def answer_question(prompt): + bots_context = "You are located in zipcode 94549. You are a chatbot written in python and you are answering questions for me" + + session = requests.Session() + payload = { + "model": "text-davinci-003", + "messages": [ + {"role": "system", "content": bots_context}, + {"role": "user", "content": prompt}, + ], + } + r = requests.post( + "https://sharegpt.churchless.tech/share/v1/chat", + headers={"Content-Type": "application/json"}, + data=json.dumps(payload), + ) + answer = json.loads(r.text)["choices"][0]["message"]["content"] + + embed = discord.Embed(description=answer, color=discord.Color.green(), type="rich") + embed.set_author(name="You asked me: %s" % prompt) + embed.set_thumbnail( + url="https://cdn.discordapp.com/emojis/1087404359844892712.webp" + ) + return embed + # answer = answer.replace("```python", "") + # answer = answer.replace("```", "")