chore: cleanup

pull/69/head
Zack 2 years ago
parent 74297ff116
commit 7731f7db7d

@ -43,7 +43,7 @@ def check_verion() -> None:
@bot.event @bot.event
async def on_ready(): async def on_ready():
bot_status = discord.Status.online bot_status = discord.Status.online
# bot_activity = discord.Activity(type=discord.ActivityType.playing, name="bing.com") bot_activity = discord.Activity(type=discord.ActivityType.playing, name="bing.com")
await bot.change_presence(status=bot_status, activity=bot_activity) await bot.change_presence(status=bot_status, activity=bot_activity)
for Filename in os.listdir("./cogs"): for Filename in os.listdir("./cogs"):
if Filename.endswith(".py"): if Filename.endswith(".py"):

@ -29,6 +29,7 @@ async def init_chatbot(user_id):
auth_cookie = os.environ.get("AUTH_COOKIE") auth_cookie = os.environ.get("AUTH_COOKIE")
auth_cookie_SRCHHPGUSR = os.environ.get("AUTH_COOKIE_SRCHHPGUSR") auth_cookie_SRCHHPGUSR = os.environ.get("AUTH_COOKIE_SRCHHPGUSR")
# auth_cookie_SRCHHPGUSR = os.environ.get("AUTH_COOKIE_SRCHHPGUSR")
users_chatbot[user_id] = UserChatbot(cookies=cookie_json) users_chatbot[user_id] = UserChatbot(cookies=cookie_json)
users_image_generator[user_id] = ImageGenAsync(auth_cookie, quiet=True) users_image_generator[user_id] = ImageGenAsync(auth_cookie, quiet=True)
user_conversation_style[user_id] = "balanced" user_conversation_style[user_id] = "balanced"
@ -37,38 +38,24 @@ class UserChatbot:
def __init__(self, cookies): def __init__(self, cookies):
self.chatbot = Chatbot(cookies=cookies) self.chatbot = Chatbot(cookies=cookies)
async def send_message(self, interaction, message, conversation_style, image_file=None): async def send_message(self, interaction, message, conversation_style):
if image_file: await send_message(self.chatbot, interaction, message, conversation_style)
# Download the image from Discord
image_data = await image_file.read()
# Send the image data to the Bing model
response = await self.chatbot.send_image(image_data)
# Send the response from the Bing model to the user
await interaction.channel.send(content=response)
else:
await send_message(self.chatbot, interaction, message, conversation_style)
class EdgeGPT(Cog_Extension):
@app_commands.command(name="bing", description="Have a chat with Bing")
async def bing(self, interaction: discord.Interaction, *, message: str):
user_id = interaction.user.id
if user_id not in users_chatbot:
await init_chatbot(user_id)
conversation_style = user_conversation_style[user_id]
usermessage = message
# Check the last 10 messages for attachments async def create_image(self, interaction, prompt: str, image_generator):
image_file = None await create_image(interaction, prompt, image_generator)
async for msg in interaction.channel.history(limit=10):
if msg.attachments:
image_file = msg.attachments[0]
break
# If an attachment was found, send it to the model async def reset(self):
if image_file: await self.chatbot.reset()
await users_chatbot[user_id].send_message(interaction, usermessage, conversation_style, image_file)
else:
await users_chatbot[user_id].send_message(interaction, usermessage, conversation_style)
class EdgeGPT(Cog_Extension):
# Chat with Bing
@app_commands.command(name="bing", description="Have a chat with Bing")
async def bing(self, interaction: discord.Interaction, *, message: str):
try:
using = await get_using_send(interaction.user.id)
except:
await set_using_send(interaction.user.id, False)
using = await get_using_send(interaction.user.id)
if not using: if not using:
await interaction.response.defer(ephemeral=False, thinking=True) await interaction.response.defer(ephemeral=False, thinking=True)
username = str(interaction.user) username = str(interaction.user)

@ -143,7 +143,7 @@ async def set_chatbot(cookies):
chatbot = Chatbot(cookies=cookies) chatbot = Chatbot(cookies=cookies)
async def send_message(chatbot: Chatbot, message, user_message: str, image_file=None): async def send_message(chatbot: Chatbot, message, user_message: str):
async with sem: async with sem:
if isinstance(message, discord.message.Message): if isinstance(message, discord.message.Message):
await message.channel.typing() await message.channel.typing()
@ -155,56 +155,23 @@ async def send_message(chatbot: Chatbot, message, user_message: str, image_file=
try: try:
# Change conversation style # Change conversation style
if conversation_style == "creative": if conversation_style == "creative":
if image_file: reply = await chatbot.ask(
# Download the image from Discord prompt=user_message,
image_data = await image_file.read() conversation_style=ConversationStyle.creative,
# Send the image data to the model simplify_response=True,
reply = await chatbot.ask( )
prompt=user_message,
conversation_style=ConversationStyle.creative,
simplify_response=True,
image=image_data,
)
else:
reply = await chatbot.ask(
prompt=user_message,
conversation_style=ConversationStyle.creative,
simplify_response=True,
)
elif conversation_style == "precise": elif conversation_style == "precise":
if image_file: reply = await chatbot.ask(
# Download the image from Discord prompt=user_message,
image_data = await image_file.read() conversation_style=ConversationStyle.precise,
# Send the image data to the model simplify_response=True,
reply = await chatbot.ask( )
prompt=user_message,
conversation_style=ConversationStyle.precise,
simplify_response=True,
image=image_data,
)
else:
reply = await chatbot.ask(
prompt=user_message,
conversation_style=ConversationStyle.precise,
simplify_response=True,
)
else: else:
if image_file: reply = await chatbot.ask(
# Download the image from Discord prompt=user_message,
image_data = await image_file.read() conversation_style=ConversationStyle.balanced,
# Send the image data to the model simplify_response=True,
reply = await chatbot.ask( )
prompt=user_message,
conversation_style=ConversationStyle.balanced,
simplify_response=True,
image=image_data,
)
else:
reply = await chatbot.ask(
prompt=user_message,
conversation_style=ConversationStyle.balanced,
simplify_response=True,
)
# Get reply text # Get reply text
text = f"{reply['text']}" text = f"{reply['text']}"

@ -1,14 +0,0 @@
/*
A ping command that replies with "Pong!" when bot is running.
*/
const { SlashCommandBuilder } = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Replies with Pong!"),
async execute(interaction) {
await interaction.reply("Pong!");
},
};

@ -1,10 +0,0 @@
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName("server")
.setDescription("Replies with server name and member count."),
async execute(interaction) {
await interaction.reply(`Server name: ${interaction.guild.name}\nTotal members: ${interaction.guild.memberCount}`);
},
};

@ -7,22 +7,9 @@ import os
api_key = os.getenv("OPENAI_API_KEY") api_key = os.getenv("OPENAI_API_KEY")
# Initialize the EdgeGPTModel # Initialize the EdgeGPTModel
edgegpt = BingChat(cookies_path="./cookies.txt") edgegpt = BingChat()
@tool
def edgegpt(task: str = None):
"""A tool to run infrence on the EdgeGPT Model"""
return EdgeGPTTool.run(task)
# Initialize the language model,
# This model can be swapped out with Anthropic, ETC, Huggingface Models like Mistral, ETC
llm = OpenAIChat(
openai_api_key=api_key,
temperature=0.5,
)
# Initialize the Worker with the custom tool # Initialize the Worker with the custom tool
worker = Worker(llm=llm, ai_name="EdgeGPT Worker", external_tools=[edgegpt]) worker = Worker(llm=llm, ai_name="EdgeGPT Worker", external_tools=[edgegpt])

Loading…
Cancel
Save