Spaces:
Running
Running
File size: 971 Bytes
913f308 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#
# 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 |