Skip to content

Commit

Permalink
Add user-specified GPT role
Browse files Browse the repository at this point in the history
Signed-off-by: bghira <bghira@users.github.com>
  • Loading branch information
bghira committed Apr 14, 2023
1 parent 02c8e84 commit d8a48c0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions discord_tron_master/classes/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

DEFAULT_USER_CONFIG = {
"steps": 100,
"gpt_role": "You are a Discord bot.",
"temperature": 0.9,
"strength": 0.5,
"resize": 1,
Expand Down
8 changes: 6 additions & 2 deletions discord_tron_master/classes/openai/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ async def random_image_prompt(self, theme: str = None):
prompt = prompt + '. Theme: ' + theme
return await self.turbo_completion("You are a Stable Diffusion Prompt Generator Bot. Respond as one would.", prompt, temperature=1.1)

async def discord_bot_response(self, prompt):
return await self.turbo_completion(self.discord_bot_role, prompt)
async def discord_bot_response(self, prompt, ctx = None):
user_role = self.discord_bot_role
if ctx is not None:
user_role = self.config.get_user_setting(ctx.author.id, "gpt_role", self.discord_bot_role)
user_temperature = self.config.get_user_setting(ctx.author.id, "temperature")
return await self.turbo_completion(user_role, prompt, temperature=user_temperature, max_tokens=2048)

async def turbo_completion(self, role, prompt, **kwargs):
if kwargs:
Expand Down
2 changes: 1 addition & 1 deletion discord_tron_master/cogs/image/img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ async def on_message(self, message):
# We were mentioned, but no attachments. They must want to converse.
logging.debug("Message contains no attachments. Initiating conversation.")
gpt = GPT()
response = await gpt.turbo_completion(role=gpt.discord_bot_role, prompt=message.content, max_tokens=2048, temperature=0.9)
response = await gpt.discord_bot_response(prompt=message.content, ctx=message)
await discord.send_large_message(message, message.author.mention + ' ' + response)
2 changes: 2 additions & 0 deletions discord_tron_master/cogs/user/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async def my_settings(self, ctx, *args):
guidance_scaling = self.config.get_user_setting(user_id, "guidance_scaling")
enable_sag = self.config.get_user_setting(user_id, "enable_sag")
seed = self.config.get_user_setting(user_id, "seed", None)
gpt_role = self.config.get_user_setting(user_id, "gpt_role")
negative_prompt = self.config.get_user_setting(
user_id,
"negative_prompt",
Expand All @@ -94,6 +95,7 @@ async def my_settings(self, ctx, *args):
f"🟠 **Self-Assisted Guidance (SAG)**: `{enable_sag}` **Default**: `False`\n❓ Use SAG scaling to make higher quality images. Requires a square aspect ratio on non-SAG models.\n"
f"🟠 **Negative Prompt:**:\n➡️ `{negative_prompt}`\n❓ Images featuring these keywords are less likely to be generated. Set via `{self.config.get_command_prefix()}negative`.\n"
f"🟠 **Positive Prompt:**:\n➡️ `{positive_prompt}`\n❓ Added to the end of every prompt, which has a limit of 77 tokens. This can become truncated. Set via `{self.config.get_command_prefix()}positive`.\n"
f"🟠 **GPT Role:**:\n➡️ `{gpt_role}`\n❓ Defines how this bot will respond to you when chatting. Use `{self.config.get_command_prefix()}settings gpt_role [new role]`.\n"
f"🟠 **Resolution:** `{resolution['width']}x{resolution['height']}`\n❓ Lower resolutions render more quickly, and has a relationship with `steps` that can really influence the output. See **{self.config.get_command_prefix()}help resolution** for more information."
)

Expand Down

0 comments on commit d8a48c0

Please sign in to comment.