52 lines
1.3 KiB
Python
Executable File

import openai
import os
from discord import option
from discord.ext import commands
import discord
import requests
class Gpt(commands.Cog):
def __init__(self, bot):
self.bot: commands.Bot = bot
@commands.slash_command(
guld_ids=None,
name="gpt",
description="Talk to an LLM",
)
@option(name="question", description="The question to ask", required=True)
async def gpt(
self,
ctx,
question: str,
):
openai.api_key = os.getenv("OPENAI_API_KEY")
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
],
)
embed = discord.Embed(
description=completion.choices[0].message,
color=discord.Color.green(),
type="rich",
)
embed.set_
embed.set_author(
name="You asked me: %s" % question,
icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/0/04/ChatGPT_logo.svg/2048px-ChatGPT_logo.svg.png",
)
await ctx.followup.send(embed=embed)
def setup(bot):
bot.add_cog(Gpt(bot))