Spaces:
Paused
Paused
| # | |
| # SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org> | |
| # SPDX-License-Identifier: Apache-2.0 | |
| # | |
| # Utility function to extract input text and files from a message object | |
| def extract_input_and_files(message): # Extract input and files from message | |
| """ | |
| Extracts the input text and any attached files from the message object. | |
| Returns a tuple (input, files). | |
| """ | |
| input = "" # Initialize input as empty string | |
| files = None # Initialize files as None | |
| # Check if the message is a dictionary which may contain both text and file attachments | |
| if isinstance(message, dict): # If message is a dictionary | |
| input = message.get("text", "") # Get text from message dictionary | |
| files = message.get("files")[0] if message.get("files") else None # Get first file if present | |
| else: # If message is a simple string | |
| input = message # Assign message directly to input | |
| return input, files # Return extracted input and files |