From 5c473f502ab54569287fd8c4ed9de69c37031a26 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 26 Oct 2023 13:53:50 -0500 Subject: [PATCH] chore: cleanup Former-commit-id: 7731f7db7d4501587d605bf05170d9e9bc470a11 --- apps/BingBot/bot.py | 2 +- apps/BingBot/cogs/edgegpt.py | 45 +++++++------------ apps/BingBot/cogs/event.py | 67 +++++++--------------------- apps/orchistrator/commands/ping.js | 14 ------ apps/orchistrator/commands/server.js | 10 ----- playground/agents/bingchat.py | 15 +------ 6 files changed, 35 insertions(+), 118 deletions(-) delete mode 100644 apps/orchistrator/commands/ping.js delete mode 100644 apps/orchistrator/commands/server.js diff --git a/apps/BingBot/bot.py b/apps/BingBot/bot.py index f636e969..233ca9a7 100644 --- a/apps/BingBot/bot.py +++ b/apps/BingBot/bot.py @@ -43,7 +43,7 @@ def check_verion() -> None: @bot.event async def on_ready(): 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) for Filename in os.listdir("./cogs"): if Filename.endswith(".py"): diff --git a/apps/BingBot/cogs/edgegpt.py b/apps/BingBot/cogs/edgegpt.py index 7c84b256..c95662b0 100644 --- a/apps/BingBot/cogs/edgegpt.py +++ b/apps/BingBot/cogs/edgegpt.py @@ -29,6 +29,7 @@ async def init_chatbot(user_id): 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") users_chatbot[user_id] = UserChatbot(cookies=cookie_json) users_image_generator[user_id] = ImageGenAsync(auth_cookie, quiet=True) user_conversation_style[user_id] = "balanced" @@ -37,38 +38,24 @@ class UserChatbot: def __init__(self, cookies): self.chatbot = Chatbot(cookies=cookies) - async def send_message(self, interaction, message, conversation_style, image_file=None): - if image_file: - # 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 + async def send_message(self, interaction, message, conversation_style): + await send_message(self.chatbot, interaction, message, conversation_style) - # Check the last 10 messages for attachments - image_file = None - async for msg in interaction.channel.history(limit=10): - if msg.attachments: - image_file = msg.attachments[0] - break + async def create_image(self, interaction, prompt: str, image_generator): + await create_image(interaction, prompt, image_generator) - # If an attachment was found, send it to the model - if image_file: - 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) + async def reset(self): + await self.chatbot.reset() +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: await interaction.response.defer(ephemeral=False, thinking=True) username = str(interaction.user) diff --git a/apps/BingBot/cogs/event.py b/apps/BingBot/cogs/event.py index 6d826ffa..9b81cf30 100644 --- a/apps/BingBot/cogs/event.py +++ b/apps/BingBot/cogs/event.py @@ -143,7 +143,7 @@ async def set_chatbot(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: if isinstance(message, discord.message.Message): await message.channel.typing() @@ -155,57 +155,24 @@ async def send_message(chatbot: Chatbot, message, user_message: str, image_file= try: # Change conversation style if conversation_style == "creative": - if image_file: - # Download the image from Discord - image_data = await image_file.read() - # Send the image data to the model - 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, - ) + reply = await chatbot.ask( + prompt=user_message, + conversation_style=ConversationStyle.creative, + simplify_response=True, + ) elif conversation_style == "precise": - if image_file: - # Download the image from Discord - image_data = await image_file.read() - # Send the image data to the model - 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, - ) + reply = await chatbot.ask( + prompt=user_message, + conversation_style=ConversationStyle.precise, + simplify_response=True, + ) else: - if image_file: - # Download the image from Discord - image_data = await image_file.read() - # Send the image data to the model - 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, - ) - + reply = await chatbot.ask( + prompt=user_message, + conversation_style=ConversationStyle.balanced, + simplify_response=True, + ) + # Get reply text text = f"{reply['text']}" text = re.sub(r"\[\^(\d+)\^\]", lambda match: "", text) diff --git a/apps/orchistrator/commands/ping.js b/apps/orchistrator/commands/ping.js deleted file mode 100644 index 2fee3436..00000000 --- a/apps/orchistrator/commands/ping.js +++ /dev/null @@ -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!"); - }, -}; \ No newline at end of file diff --git a/apps/orchistrator/commands/server.js b/apps/orchistrator/commands/server.js deleted file mode 100644 index ae2b6627..00000000 --- a/apps/orchistrator/commands/server.js +++ /dev/null @@ -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}`); - }, -}; diff --git a/playground/agents/bingchat.py b/playground/agents/bingchat.py index bf06ecc6..db805659 100644 --- a/playground/agents/bingchat.py +++ b/playground/agents/bingchat.py @@ -7,22 +7,9 @@ import os api_key = os.getenv("OPENAI_API_KEY") # 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 worker = Worker(llm=llm, ai_name="EdgeGPT Worker", external_tools=[edgegpt])