-
-
Save KyMidd/66d55849e4aa1cb4142082b2919a88db 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
| def handle_message_event(client, body, say, bedrock_client, app, token): | |
| ... | |
| response = ai_request(bedrock_client, conversation) | |
| # Get response | |
| response_body = response["body"].read().decode("utf-8") | |
| if os.environ.get("VERA_DEBUG", "False") == "True": | |
| print("π Response body:", response_body) | |
| # Conver to JSON | |
| response_json = json.loads(response_body) | |
| if os.environ.get("VERA_DEBUG", "False") == "True": | |
| print("π response_json['content']:", response_json["content"]) | |
| # Check if response content is empty | |
| if response_json["content"] == []: | |
| print("π Response content is empty, setting response_text to blank") | |
| response_text = "" | |
| else: | |
| # There is content in the response, set response_text to the text content | |
| response_text = response_json.get("content", [{}])[0].get("text", "") | |
| if os.environ.get("VERA_DEBUG", "False") == "True": | |
| print("π response_text:", response_text) | |
| # Check if unsupported_file_type_found | |
| if unsupported_file_type_found == True: | |
| # If true, prepend error to response text | |
| response_text = f"> `Error`: Unsupported file type found, please ensure you are sending a supported file type. Supported file types are: images (png, jpeg, gif, webp).\n{ | |
| response_text}" | |
| if os.environ.get("VERA_DEBUG", "False") == "True": | |
| print("π Response text after adding errors:", response_text) | |
| # Return response in the thread | |
| say( | |
| # text=f"Oh hi <@{user_id}>!\n\n{response_text}", | |
| text=f"{response_text}", | |
| thread_ts=thread_ts, | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment