Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created February 1, 2025 16:59
Show Gist options
  • Select an option

  • Save KyMidd/0acf8d12add3370937b9da9257823ca4 to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/0acf8d12add3370937b9da9257823ca4 to your computer and use it in GitHub Desktop.
# Common function to handle both DMs and app mentions
def handle_message_event(client, body, say, bedrock_client, app, token, registered_bot_id):
# ... Other items excluded above
# If enabled, fetch the confluence context from the knowledge base
if enable_knowledge_base:
print("πŸš€ Knowledge base enabled, fetching citations")
if os.environ.get("VERA_DEBUG", "False") == "True":
print("πŸš€ State of conversation before AI request:", conversation)
# Flatten the conversation into one string
flat_conversation = []
for item in conversation:
for content in item['content']:
if content['type'] == 'text':
flat_conversation.append(content['text'])
flat_conversation = '\n'.join(flat_conversation)
# On each conversation line, remove all text before the first colon. It appears the names and pronouns really throw off our context quality
flat_conversation = re.sub(r".*: ", "", flat_conversation)
if os.environ.get("VERA_DEBUG", "False") == "True":
print(f"πŸš€ Flat conversation: {flat_conversation}")
# Get context data from the knowledge base
knowledge_base_response = ask_bedrock_llm_with_knowledge_base(flat_conversation, ConfluenceKnowledgeBaseId, bedrock_client)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment