import os
def process_input(task_description, task_file_name):
"""
Enriches task description with file context information.
Args:
task_description: The original task description
task_file_name: Optional file path associated with the task
Returns:
Enhanced task description with file handling instructions
"""
if not task_file_name:
return task_description
if not os.path.isfile(task_file_name):
raise FileNotFoundError(f"Error: File not found {task_file_name}")
extension_mappings = {
'image': ['jpg', 'jpeg', 'png', 'gif', 'webp'],
'text': ['txt'],
'json': ['json', 'jsonld'],
'excel': ['xlsx', 'xls'],
'pdf': ['pdf'],
'document': ['docx', 'doc'],
'html': ['html', 'htm'],
'ppt': ['pptx', 'ppt'],
'wav': ['wav'],
'mp3': ['mp3', 'm4a'],
'zip': ['zip']
}
ext = task_file_name.rsplit('.', 1)[-1].lower()
file_category = ext
for category, extensions in extension_mappings.items():
if ext in extensions:
file_category = category.capitalize()
break
file_instruction = (
f"\nNote: A {file_category} file '{task_file_name}' is associated with this task. "
f"You should use available tools to read its content if necessary through {task_file_name}. "
f"Additionally, if you need to analyze this file by Linux commands or python codes, "
f"you should upload it to the sandbox first. Files in the sandbox cannot be accessed by other tools.\n\n"
)
return task_description + file_instruction