Skip to content

Commit

Permalink
Make drawing optional inside /gpt converse
Browse files Browse the repository at this point in the history
  • Loading branch information
Kav-K committed Nov 17, 2023
1 parent 093e1bc commit c7360b7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
8 changes: 8 additions & 0 deletions cogs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,12 @@ async def edit(
description="Have a conversation with GPT",
guild_ids=ALLOWED_GUILDS,
)
@discord.option(
name="draw",
description="Allow GPT to draw images with DALL-E",
required=False,
default=False,
)
@discord.option(
name="opener",
description="Which sentence to start with, added after the file",
Expand Down Expand Up @@ -573,6 +579,7 @@ async def edit(
async def converse(
self,
ctx: discord.ApplicationContext,
draw: bool,
opener: str,
opener_file: str,
private: bool,
Expand All @@ -586,6 +593,7 @@ async def converse(
):
await self.converser_cog.converse_command(
ctx,
draw,
opener,
opener_file,
private,
Expand Down
6 changes: 5 additions & 1 deletion cogs/text_service_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ async def private_test_command(self, ctx: discord.ApplicationContext):
async def converse_command(
self,
ctx: discord.ApplicationContext,
draw: bool,
opener: str,
opener_file: str,
private: bool,
Expand All @@ -1156,7 +1157,7 @@ async def converse_command(
top_p: float,
frequency_penalty: float,
presence_penalty: float,
use_threads: bool = True, # Add this parameter
use_threads: bool = True,
):
"""Command handler. Starts a conversation with the bot
Expand Down Expand Up @@ -1255,6 +1256,8 @@ async def converse_command(

self.conversation_threads[target.id] = Thread(target.id)
self.conversation_threads[target.id].model = model_selection
if draw:
self.conversation_threads[target.id].drawable = True

# Set the overrides for the conversation
self.conversation_threads[target.id].set_overrides(
Expand Down Expand Up @@ -1373,6 +1376,7 @@ async def converse_command(
user=user,
model=self.conversation_threads[target.id].model,
custom_api_key=user_api_key,
is_drawable=draw,
)
safe_remove_list(self.awaiting_responses, user_id_normalized)
safe_remove_list(self.awaiting_thread_responses, target.id)
Expand Down
2 changes: 0 additions & 2 deletions conversation_starter_pretext_vision.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ Human: I'm making a discord bot <|endofstatement|>
<yourname>: that's pretty hype, I've never made one of those before, what part are you on right now? <|endofstatement|>
...

You are able to draw (generate) images, when the user asks you to draw something let them know enthusiastically that you can do and work on a prompt with them. The rest will be handled automatically and you will see images that you've drawn appear in your conversation history.

You speak in a fun, casual, and friendly tone, you're not overly inquisitive, you don't worry about formalities and speak as if you are speaking with a friend or peer.
1 change: 1 addition & 0 deletions models/user_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def __init__(self, thread_id):
self.top_p = None
self.frequency_penalty = None
self.presence_penalty = None
self.drawable = False

def set_overrides(
self,
Expand Down
14 changes: 13 additions & 1 deletion services/text_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async def encapsulated_send(
from_ask_action=False,
from_other_action=None,
from_message_context=None,
is_drawable=False,
):
"""General service function for sending and receiving gpt generations
Expand Down Expand Up @@ -352,6 +353,17 @@ async def encapsulated_send(
usage_message = None

if is_chatgpt_conversation:

if is_drawable:
converser_cog.conversation_threads[
ctx.channel.id
].history[0].text += "\nYou are able to draw images in this conversation. Only draw when EXPLICITLY asked to do so, otherwise, work on a prompt with the user and ask them if they'd like to draw, if you're discussing drawing in the first place."
else:
converser_cog.conversation_threads[
ctx.channel.id
].history[
0].text += "\nYou are unable to draw images in this conversation. Ask the user to start a conversation with gpt-4-vision with the `draw` option turned on in order to have this ability."

_prompt_with_history = converser_cog.conversation_threads[
ctx.channel.id
].history
Expand Down Expand Up @@ -878,7 +890,7 @@ async def process_conversation_message(

# Determine if we should draw an image and determine what to draw, and handle the drawing itself
# TODO: This should be encapsulated better into some other service or function so we're not cluttering this text service file, this text service file is gross right now..
if "-vision" in model and not converser_cog.pinecone_service:
if "-vision" in model and not converser_cog.pinecone_service and converser_cog.conversation_threads[message.channel.id].drawable:
print("Checking for if the user asked to draw")
draw_check_prompt = """
You will be given a set of conversation items and you will determine if the intent of the user(s) are to draw/create a picture or not, if the intent is to
Expand Down

0 comments on commit c7360b7

Please sign in to comment.