Skip to content

Commit

Permalink
fix env commands
Browse files Browse the repository at this point in the history
  • Loading branch information
nalbam committed Jun 10, 2024
1 parent a825439 commit b414533
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ ALLOWED_CHANNEL_IDS="C000000,C000001"

SYSTEM_MESSAGE="너는 AWSKRUG(AWS Korea User Group)에서 친절하게 도움을 주는 구름이(Gurumi)야."

MESSAGE_MAX="4000"
MAX_LEN_SLACK="10000"
MAX_LEN_BEDROCK="4000"
18 changes: 10 additions & 8 deletions handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
# Set up System messages
SYSTEM_MESSAGE = os.environ.get("SYSTEM_MESSAGE", "None")

MESSAGE_MAX = int(os.environ.get("MESSAGE_MAX", 4000))
MAX_LEN_SLACK = int(os.environ.get("MAX_LEN_SLACK", 10000))
MAX_LEN_BEDROCK = int(os.environ.get("MAX_LEN_BEDROCK", 4000))

COMMAND_DESCRIBE = "Describe the image in great detail as if viewing a photo."
COMMAND_GENERATE = "Convert the above sentence into a command for stable-diffusion to generate an image within 1000 characters. Just give me a prompt."

# Initialize Slack app
app = App(
Expand Down Expand Up @@ -96,6 +100,8 @@ def chat_update(channel, ts, message, blocks=None):

app.client.chat_update(channel=channel, ts=ts, text=text, blocks=blocks)

return message, ts


def invoke_claude_3(content):
"""
Expand Down Expand Up @@ -229,7 +235,7 @@ def conversations_replies(channel, ts, client_msg_id):

# print("conversations_replies: messages size: {}".format(sys.getsizeof(messages)))

if sys.getsizeof(messages) > MESSAGE_MAX:
if sys.getsizeof(messages) > MAX_LEN_BEDROCK:
messages.pop(0) # remove the oldest message
break

Expand Down Expand Up @@ -276,9 +282,7 @@ def conversation(say: Say, thread_ts, content, channel, user, client_msg_id):
if type == "image" and len(content) > 1:
chat_update(channel, latest_ts, "이미지 감상 중... " + BOT_CURSOR)

content[0][
"text"
] = "Describe the image in great detail as if viewing a photo."
content[0]["text"] = COMMAND_DESCRIBE

# Send the prompt to Bedrock
message = invoke_claude_3(content)
Expand All @@ -291,9 +295,7 @@ def conversation(say: Say, thread_ts, content, channel, user, client_msg_id):
if type == "image":
chat_update(channel, latest_ts, "이미지 생성 준비 중... " + BOT_CURSOR)

prompts.append(
"Convert the above sentence into a command for stable-diffusion to generate an image within 1000 characters. Just give me a prompt."
)
prompts.append(COMMAND_GENERATE)

prompt = "\n\n\n".join(prompts)

Expand Down

0 comments on commit b414533

Please sign in to comment.