chore: cleanup

Former-commit-id: 7731f7db7d
blog-agent
Zack 2 years ago
parent 707a9b5a32
commit 5c473f502a

@ -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"):

@ -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:
async def send_message(self, interaction, message, conversation_style):
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
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)

@ -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,50 +155,17 @@ 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,
)
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,
)
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,

@ -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")
# 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])

Loading…
Cancel
Save