Created
February 1, 2025 16:59
-
-
Save KyMidd/0acf8d12add3370937b9da9257823ca4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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