Files
juniteevee-cogs/chatGpt/chatgpt.py

38 lines
1.1 KiB
Python
Raw Normal View History

2022-12-05 13:27:12 -05:00
from redbot.core import commands
from redbot.core import Config
import re
import discord
from datetime import datetime
from revChatGPT.revChatGPT import Chatbot
class ChatGpt(commands.Cog):
"""Cog to enable chat powered by OpenAi Chat GPT"""
2022-12-05 14:01:20 -05:00
def __init__(self, bot):
2022-12-05 13:27:12 -05:00
self.bot = bot
2022-12-05 13:57:33 -05:00
@commands.command()
2022-12-05 14:27:09 -05:00
async def testchat(self, ctx: commands.Context, msg):
2022-12-05 13:57:33 -05:00
"""Test"""
2022-12-05 14:22:58 -05:00
config = await self.setCredentials(ctx)
2022-12-05 14:22:43 -05:00
2022-12-05 14:27:09 -05:00
chatbot = Chatbot(config, conversation_id=None)
2022-12-05 14:45:54 -05:00
chatbot.reset_chat()
chatbot.refresh_session()
2022-12-05 14:27:09 -05:00
resp = chatbot.get_chat_response(msg, output="text")
await ctx.send(f"{resp['message']}")
2022-12-05 14:22:43 -05:00
async def setCredentials(self, ctx: commands.Context):
2022-12-05 14:05:02 -05:00
openAiKeys = await self.bot.get_shared_api_tokens("openai")
2022-12-05 14:08:16 -05:00
if openAiKeys.get("email") is None or openAiKeys.get("password") is None:
return await ctx.send("The openai email and password keys have not been set.")
2022-12-05 14:22:43 -05:00
config = {
2022-12-05 14:05:02 -05:00
"email": openAiKeys.get("email"),
2022-12-05 14:39:47 -05:00
"password": openAiKeys.get("password"),
"Authorization": None,
2022-12-05 13:27:12 -05:00
}
2022-12-05 14:22:43 -05:00
return config
2022-12-05 13:27:12 -05:00