Skip to content

Commit

Permalink
Merge pull request #6 from nalbam/main
Browse files Browse the repository at this point in the history
fix env commands
  • Loading branch information
nalbam authored Jun 10, 2024
2 parents a825439 + 22237b7 commit 357c482
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 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"
33 changes: 16 additions & 17 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ on:
- main

env:
BOT_CURSOR: ${{ secrets.BOT_CURSOR }}
ALLOWED_CHANNEL_IDS: ${{ vars.ALLOWED_CHANNEL_IDS }}
BOT_CURSOR: ${{ vars.BOT_CURSOR }}
DYNAMODB_TABLE_NAME: ${{ vars.DYNAMODB_TABLE_NAME }}
ENABLE_IMAGE: ${{ vars.ENABLE_IMAGE }}
IMAGE_MODEL_ID: ${{ vars.IMAGE_MODEL_ID }}
SYSTEM_MESSAGE: ${{ vars.SYSTEM_MESSAGE }}
TEXT_MODEL_ID: ${{ vars.TEXT_MODEL_ID }}

AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_SIGNING_SECRET: ${{ secrets.SLACK_SIGNING_SECRET }}
DYNAMODB_TABLE_NAME: ${{ secrets.DYNAMODB_TABLE_NAME }}
TEXT_MODEL_ID: ${{ secrets.TEXT_MODEL_ID }}
IMAGE_MODEL_ID: ${{ secrets.IMAGE_MODEL_ID }}
SYSTEM_MESSAGE: ${{ vars.SYSTEM_MESSAGE }}
ALLOWED_CHANNEL_IDS: ${{ secrets.ALLOWED_CHANNEL_IDS }}
ENABLE_IMAGE: ${{ secrets.ENABLE_IMAGE }}

jobs:
deploy:
Expand Down Expand Up @@ -45,19 +48,15 @@ jobs:

- name: Set up environment variables 📝
run: |
echo "ALLOWED_CHANNEL_IDS=${ALLOWED_CHANNEL_IDS}" >> .env
echo "BOT_CURSOR=${BOT_CURSOR}" >> .env
echo "SLACK_BOT_TOKEN=${SLACK_BOT_TOKEN}" >> .env
echo "SLACK_SIGNING_SECRET=${SLACK_SIGNING_SECRET}" >> .env
echo "DYNAMODB_TABLE_NAME=${DYNAMODB_TABLE_NAME}" >> .env
echo "TEXT_MODEL_ID=${TEXT_MODEL_ID}" >> .env
echo "ENABLE_IMAGE=${ENABLE_IMAGE}" >> .env
echo "IMAGE_MODEL_ID=${IMAGE_MODEL_ID}" >> .env
echo "SLACK_BOT_TOKEN=${SLACK_BOT_TOKEN}" >> .env
echo "SLACK_SIGNING_SECRET=${SLACK_SIGNING_SECRET}" >> .env
echo "SYSTEM_MESSAGE=${SYSTEM_MESSAGE}" >> .env
echo "ALLOWED_CHANNEL_IDS=${ALLOWED_CHANNEL_IDS}" >> .env
echo "ENABLE_IMAGE=${ENABLE_IMAGE}" >> .env
echo "TEXT_MODEL_ID=${TEXT_MODEL_ID}" >> .env
- name: Deploy to AWS Lambda 🚀
env:
AWS_REGION: 'us-east-1'
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: npx serverless deploy
run: npx serverless deploy --region us-east-1
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 357c482

Please sign in to comment.