-
-
Save KyMidd/2f9987ddeacbc721cce2ce542835fd2a 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 build_conversation_turn(content, message, headers): | |
| #... | |
| # Iterate over attachments | |
| if "attachments" in message: | |
| for file in message["attachments"]: | |
| # Isolate name of the file and remove characters before the final period | |
| file_name = file["name"] | |
| file_extension = file["name"].split(".")[-1] | |
| # File is a supported type | |
| file_url = file["contentUrl"] | |
| # Download the file from the content URL. Include headers in case the file is protected (SharePoint) | |
| file_content = download_file_for_user(file_name, file_url, headers) | |
| ### Bedrock API has strict file name reqs: document file name can only contain alphanumeric characters, whitespace characters, hyphens, parentheses, and square brackets. The name can't contain more than one consecutive whitespace character. | |
| # Remove disallowed | |
| file_name = re.sub(r"[^a-zA-Z0-9\s\-\[\]\(\)]", "", file_name) | |
| # Only single spaces allowed | |
| file_name = re.sub(r"\s{2,}", " ", file_name) | |
| # Strip leading and trailing whitespace | |
| file_name = file_name.strip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment