Skip to content

Commit

Permalink
Fixed some bugs with attachment uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Sep 14, 2024
1 parent 2107467 commit 5dd15bc
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions agency_swarm/util/files.py
Original file line number Diff line number Diff line change
@@ -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"
]
Expand All @@ -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}")

0 comments on commit 5dd15bc

Please sign in to comment.