Skip to content

Commit

Permalink
Merge pull request #22 from nalbam/main
Browse files Browse the repository at this point in the history
chore: Update conversation function to handle multiple contexts
  • Loading branch information
nalbam authored Aug 28, 2024
2 parents c0afbdb + 080066b commit 8ec739a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ env:
BOT_CURSOR: ${{ vars.BOT_CURSOR }}
DYNAMODB_TABLE_NAME: ${{ vars.DYNAMODB_TABLE_NAME }}
KNOWLEDGE_BASE_ID: ${{ vars.KNOWLEDGE_BASE_ID }}
MODEL_ID_IMAGE: ${{ vars.MODEL_ID_IMAGE }}
MODEL_ID_TEXT: ${{ vars.MODEL_ID_TEXT }}
PERSONAL_MESSAGE: ${{ vars.PERSONAL_MESSAGE }}
SYSTEM_MESSAGE: ${{ vars.SYSTEM_MESSAGE }}

AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down Expand Up @@ -56,10 +56,10 @@ jobs:
echo "BOT_CURSOR=${BOT_CURSOR}" >> .env
echo "DYNAMODB_TABLE_NAME=${DYNAMODB_TABLE_NAME}" >> .env
echo "KNOWLEDGE_BASE_ID=${KNOWLEDGE_BASE_ID}" >> .env
echo "MODEL_ID_IMAGE=${MODEL_ID_IMAGE}" >> .env
echo "MODEL_ID_TEXT=${MODEL_ID_TEXT}" >> .env
echo "SLACK_BOT_TOKEN=${SLACK_BOT_TOKEN}" >> .env
echo "SLACK_SIGNING_SECRET=${SLACK_SIGNING_SECRET}" >> .env
echo "PERSONAL_MESSAGE=${PERSONAL_MESSAGE}" >> .env
echo "SYSTEM_MESSAGE=${SYSTEM_MESSAGE}" >> .env
- name: Deploy to AWS Lambda 🚀
Expand Down
23 changes: 13 additions & 10 deletions handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
ALLOWED_CHANNEL_IDS = os.environ.get("ALLOWED_CHANNEL_IDS", "None")

# Set up System messages
PERSONAL_MESSAGE = os.environ.get(
"PERSONAL_MESSAGE", "당신은 친절하고 전문적인 AI 비서 입니다."
)
SYSTEM_MESSAGE = os.environ.get("SYSTEM_MESSAGE", "None")

MAX_LEN_SLACK = int(os.environ.get("MAX_LEN_SLACK", 3000))
Expand Down Expand Up @@ -304,16 +307,14 @@ def conversation(say: Say, thread_ts, query, channel, client_msg_id):
latest_ts = result["ts"]

prompts = []
prompts.append(
"Human: You are a advisor AI system, and provides answers to questions by using fact based and statistical information when possible."
)
prompts.append(
"If you don't know the answer, just say that you don't know, don't try to make up an answer."
)
prompts.append("Human: {}".format(PERSONAL_MESSAGE))
prompts.append("답변을 모르면 모른다고 하세요. 답을 지어내려고 하지 마세요.")

if SYSTEM_MESSAGE != "None":
prompts.append(SYSTEM_MESSAGE)

prompts.append("<question> 태그로 감싸진 질문에 답변을 제공하세요.")

try:
# Get the knowledge base contexts
if KNOWLEDGE_BASE_ID != "None":
Expand All @@ -322,7 +323,7 @@ def conversation(say: Say, thread_ts, query, channel, client_msg_id):
contexts = invoke_knowledge_base(query)

prompts.append(
"Use the following pieces of information to provide a concise answer to the question enclosed in <question> tags."
"<context> 에 정보가 제공 되면, 해당 정보를 사용하여 답변해 주세요."
)
prompts.append("<context>")
prompts.append("\n\n".join(contexts))
Expand All @@ -334,9 +335,12 @@ def conversation(say: Say, thread_ts, query, channel, client_msg_id):

contexts = conversations_replies(channel, thread_ts, client_msg_id)

prompts.append("<context>")
prompts.append(
"<history> 에 정보가 제공 되면, 대화 기록을 참고하여 답변해 주세요."
)
prompts.append("<history>")
prompts.append("\n\n".join(contexts))
prompts.append("</context>")
prompts.append("</history>")

# Add the question to the prompts
prompts.append("")
Expand All @@ -345,7 +349,6 @@ def conversation(say: Say, thread_ts, query, channel, client_msg_id):
prompts.append("</question>")
prompts.append("")

# prompts.append("The response should be specific and use statistics or numbers when possible.")
prompts.append("Assistant:")

# Combine the prompts
Expand Down

0 comments on commit 8ec739a

Please sign in to comment.