From dee0adc42ffaa40e6bdb070fb46bbb6926a890ed Mon Sep 17 00:00:00 2001 From: Luke Robles <98352913+lrobles-iterable@users.noreply.github.com> Date: Sat, 24 Sep 2022 15:02:48 -0700 Subject: [PATCH] adding openai. might as well use it till we lose it --- app/cogs/actual_utils.py | 16 ++++++++++++++++ app/cogs/cheeky_functions.py | 8 -------- app/cogs/markov.py | 37 ------------------------------------ app/questions.py | 19 ++++++++++++++++++ app/requirements.txt | 2 +- helm/values.yaml | 1 + 6 files changed, 37 insertions(+), 46 deletions(-) delete mode 100644 app/cogs/markov.py diff --git a/app/cogs/actual_utils.py b/app/cogs/actual_utils.py index 8bfd6553..5f3c0c1a 100644 --- a/app/cogs/actual_utils.py +++ b/app/cogs/actual_utils.py @@ -47,6 +47,22 @@ class ActualUtils(commands.Cog): await ctx.message.delete() os.remove(file_path) + @commands.command(name="ask", aliases=["wolfram"]) + async def ask(self, ctx: commands.Context): + import questions + + await ctx.reply( + questions.answer_question(ctx.message.content), + ) + + @commands.command(name="openai") + async def openai(self, ctx: commands.Context): + import questions + + await ctx.reply( + questions.open_ai(ctx.message.content), + ) + @commands.command(name="trackdays") async def trackdays(self, ctx: commands.Context): role = discord.utils.find( diff --git a/app/cogs/cheeky_functions.py b/app/cogs/cheeky_functions.py index 6467eafc..7c9d3007 100644 --- a/app/cogs/cheeky_functions.py +++ b/app/cogs/cheeky_functions.py @@ -114,14 +114,6 @@ class Cheeky(commands.Cog): await ctx.reply(excuse.get_excuse()) - @commands.command(name="ask", aliases=["wolfram"]) - async def ask(self, ctx: commands.Context): - import questions - - await ctx.reply( - questions.answer_question(ctx.message.content), - ) - @commands.command(name="meme") async def meme(self, ctx: commands.Context): diff --git a/app/cogs/markov.py b/app/cogs/markov.py deleted file mode 100644 index c74b08f1..00000000 --- a/app/cogs/markov.py +++ /dev/null @@ -1,37 +0,0 @@ -from discord.ext import commands -import discord -import markovify -import random - - -class Markov(commands.Cog): - def __init__(self, bot): - self.bot: commands.Bot = bot - - @commands.command(name="markov") - async def markov(self, ctx: commands.Context, user: discord.Member): - - temp_message = await ctx.send("Just a moment, generating a markov chain") - - # Get messages from passed in user - authors_mesages = [] - for message in await ctx.history(limit=15000).flatten(): - if message.author.id == user.id and "https" not in message.content: - authors_mesages.append(message.content) - - # Make the model - user_model = markovify.Text(". ".join(authors_mesages)) - model_json = user_model.to_json() - - dummy = [] - for i in range(random.randint(3, 9)): - dummy.append(str(user_model.make_sentence(max_words=25, tries=500))) - await temp_message.edit( - "Heres a markov chain based on %s's shitposts" % user.mention - + "\n\n" - + " ".join(dummy) - ) - - -def setup(bot): - bot.add_cog(Markov(bot)) diff --git a/app/questions.py b/app/questions.py index 0a301bbd..973374a4 100644 --- a/app/questions.py +++ b/app/questions.py @@ -26,3 +26,22 @@ def answer_question(message): return "Sorry, I'm unable to answer that" return help_methods.get_help_message("message") + + +def open_ai(prompt): + import os + import openai + + openai.api_key = os.getenv("OPENAI_API_KEY") + + response = openai.Completion.create( + model="text-davinci-002", + prompt=prompt, + temperature=0.7, + max_tokens=256, + top_p=1, + frequency_penalty=0, + presence_penalty=0, + )["choices"][0]["text"] + + return response diff --git a/app/requirements.txt b/app/requirements.txt index f81e6708..8aa13617 100755 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -9,4 +9,4 @@ git+https://github.com/pycord-development/pycord@8df222d86319dd16a5e559585246343 requests wikipedia wolframalpha -markovify \ No newline at end of file +openai \ No newline at end of file diff --git a/helm/values.yaml b/helm/values.yaml index 05c7ee40..1b7be903 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -87,3 +87,4 @@ secrets: ffxiv_token: ffxiv_token gitlab_token: gitlab_token wolfram_token: wolfram_token + OPENAI_API_KEY: OPENAI_API_KEY