From 5dd15bc7aea700d21cddde611b81c4df9cfdcbb9 Mon Sep 17 00:00:00 2001 From: Arsenii Shatokhin Date: Sat, 14 Sep 2024 07:50:50 +0400 Subject: [PATCH] Fixed some bugs with attachment uploads --- agency_swarm/util/files.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/agency_swarm/util/files.py b/agency_swarm/util/files.py index 010d6ca1..482ab0a0 100644 --- a/agency_swarm/util/files.py +++ b/agency_swarm/util/files.py @@ -1,5 +1,8 @@ import mimetypes +# Register the MIME type for .xlsx files +mimetypes.add_type('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', '.xlsx') + image_types = [ "image/jpeg", "image/jpg", "image/png", "image/webp", "image/gif" ] @@ -23,19 +26,22 @@ def get_file_purpose(file_path): mime_type, _ = mimetypes.guess_type(file_path) - if mime_type: - if mime_type in image_types: - return "vision" - if mime_type in code_interpreter_types or mime_type in dual_types: - return "assistants" + if not mime_type: + raise ValueError(f"Could not determine type for file: {file_path}") + if mime_type in image_types: + return "vision" + if mime_type in code_interpreter_types or mime_type in dual_types: + return "assistants" raise ValueError(f"Unsupported file type: {mime_type}") def get_tools(file_path): """Returns the tools for the given file path""" mime_type, _ = mimetypes.guess_type(file_path) + if not mime_type: + raise ValueError(f"Could not determine type for file: {file_path}") if mime_type in code_interpreter_types: return [{"type": "code_interpreter"}] elif mime_type in dual_types: - return [{"type": "code_interpreter"}, {"type": "retrieval"}] + return [{"type": "code_interpreter"}, {"type": "file_search"}] else: raise ValueError(f"Unsupported file type: {mime_type}") \ No newline at end of file