Merge pull request #102 from Kav-K/context-menu-buttons

context menu buttons
Kaveen Kumarasinghe 2 years ago committed by GitHub
commit 9388ca661f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -26,17 +26,19 @@ SUPPORT SERVER FOR BOT SETUP: https://discord.gg/WvAHXDMS7Q (You can NOT use the
- **Edit Requests** - Ask GPT to edit a piece of text with a given instruction using a specific OpenAI edits model! `/gpt edit`!
- **Context menu commands** - Allow people to prompt GPT and DALL-E directly by right clicking a message:
<img src="https://i.imgur.com/fkfnJQ0.png"/>
- **Automatic retry on API errors** - The bot will automatically retry API requests if they fail due to some issue with OpenAI's APIs, this is becoming increasingly important now as their APIs become under heavy load.
- **Allow each individual user to enter their own API Key!** - Each request that a user makes will be made using their own API key! Check out the User-Input API Key section in this README for more details.
- **AI-BASED SERVER MODERATION** - GPT3Discord now has a built-in AI-based moderation system that can automatically detect and remove toxic messages from your server. This is a great way to keep your server safe and clean, and it's completely automatic and **free**! Check out the commands section to learn how to enable it!
- **Permanent memory with embeddings and PineconeDB finished!** - An initial alpha version of permanent memory is now done! This allows you to chat with GPT3 infinitely and accurately, and save tokens, by using embeddings. *Please read the Permanent Memory section for more information!*
- **AI-BASED SERVER MODERATION** - GPT3Discord now has a built-in AI-based moderation system that can automatically detect and remove toxic messages from your server. This is a great way to keep your server safe and clean, and it's completely automatic and **free**! Check out the commands section to learn how to enable it!
# Features
- **Directly prompt GPT3 with `/gpt ask <prompt>`**

@ -61,7 +61,6 @@ class Commands(discord.Cog, name="Commands"):
"""
System commands
"""
@add_to_group("system")
@discord.slash_command(
name="settings",
@ -488,3 +487,21 @@ class Commands(discord.Cog, name="Commands"):
@discord.guild_only()
async def setup(self, ctx: discord.ApplicationContext):
await self.converser_cog.setup_command(ctx)
"""
Text-based context menu commands from here
"""
@discord.message_command(
name="Ask GPT", guild_ids=ALLOWED_GUILDS, checks=[Check.check_gpt_roles()])
async def ask_gpt_action(self, ctx, message: discord.Message):
await self.converser_cog.ask_gpt_action(ctx, message)
"""
Image-based context menu commands from here
"""
@discord.message_command(
name="Draw", guild_ids=ALLOWED_GUILDS, checks=[Check.check_dalle_roles()])
async def draw_action(self, ctx, message: discord.Message):
await self.image_draw_cog.draw_action(ctx, message)

@ -40,7 +40,7 @@ class DrawDallEService(discord.Cog, name="DrawDallEService"):
print("Draw service initialized")
self.redo_users = {}
async def draw_command(self, ctx: discord.ApplicationContext, prompt: str):
async def draw_command(self, ctx: discord.ApplicationContext, prompt: str, from_action=False):
user_api_key = None
if USER_INPUT_API_KEYS:
user_api_key = await TextService.get_user_api_key(
@ -66,8 +66,11 @@ class DrawDallEService(discord.Cog, name="DrawDallEService"):
except Exception as e:
print(e)
traceback.print_exc()
await ctx.respond("Something went wrong. Please try again later.")
await ctx.send_followup(e)
await ctx.respond("Something went wrong. Please try again later.", ephemeral=from_action)
await ctx.send_followup(e, ephemeral=from_action)
async def draw_action(self, ctx, message):
await self.draw_command(ctx, message.content, from_action=True)
async def local_size_command(self, ctx: discord.ApplicationContext):
await ctx.defer()

@ -11,6 +11,7 @@ import json
import discord
from models.check_model import Check
from services.environment_service import EnvService
from services.message_queue_service import Message
from services.moderations_service import Moderation
@ -687,6 +688,7 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
top_p: float,
frequency_penalty: float,
presence_penalty: float,
from_action=None,
):
user = ctx.user
prompt = await self.mention_to_username(ctx, prompt.strip())
@ -710,6 +712,7 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
presence_penalty_override=presence_penalty,
from_ask_command=True,
custom_api_key=user_api_key,
from_action=prompt,
)
async def edit_command(
@ -972,3 +975,9 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
# Otherwise, process the settings change
await self.process_settings(ctx, parameter, value)
"""
Text-based context menu commands from here
"""
async def ask_gpt_action(self, ctx, message: discord.Message): # message commands return the message
await self.ask_command(ctx, message.content, None, None, None, None, from_action=message.content)

@ -27,7 +27,7 @@ from services.usage_service import UsageService
from services.environment_service import EnvService
__version__ = "6.5"
__version__ = "7.0"
"""

@ -50,7 +50,7 @@ class ImageService:
except ValueError as e:
message = f"Error: {e}. Please try again with a different prompt."
await ctx.channel.send(message) if not from_context else await ctx.respond(
message
message, ephemeral=True
)
return

@ -34,6 +34,7 @@ class TextService:
custom_api_key=None,
edited_request=False,
redo_request=False,
from_action=None,
):
new_prompt = (
prompt + "\nGPTie: "
@ -255,7 +256,7 @@ class TextService:
str(response["choices"][0]["text"])
)
if from_ask_command:
if from_ask_command or from_action:
# Append the prompt to the beginning of the response, in italics, then a new line
response_text = response_text.strip()
response_text = f"***{prompt}***\n\n{response_text}"
@ -455,8 +456,10 @@ class TextService:
# Error catching for OpenAI model value errors
except ValueError as e:
if from_context:
await ctx.send_followup(e)
if from_action:
await ctx.respond(e, ephemeral=True)
elif from_context:
await ctx.send_followup(e, ephemeral=True)
else:
await ctx.reply(e)
converser_cog.remove_awaiting(

Loading…
Cancel
Save