-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved file classification for tool resources
- Loading branch information
Showing
2 changed files
with
32 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,38 @@ | ||
import mimetypes | ||
|
||
code_interpreter_types = [ | ||
"application/csv", "image/jpeg", "image/gif", "image/png", | ||
"application/x-tar", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", | ||
"application/xml", "text/xml", "application/zip" | ||
] | ||
|
||
dual_types = [ | ||
"text/x-c", "text/x-csharp", "text/x-c++", "application/msword", | ||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document", | ||
"text/html", "text/x-java", "application/json", "text/markdown", | ||
"application/pdf", "text/x-php", | ||
"application/vnd.openxmlformats-officedocument.presentationml.presentation", | ||
"text/x-python", "text/x-script.python", "text/x-ruby", "text/x-tex", | ||
"text/plain", "text/css", "text/javascript", "application/x-sh", | ||
"application/typescript" | ||
] | ||
|
||
def determine_file_type(file_path): | ||
mime_type, _ = mimetypes.guess_type(file_path) | ||
if mime_type: | ||
if mime_type in [ | ||
'application/json', 'text/csv', 'application/xml', | ||
'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | ||
'application/zip' | ||
]: | ||
if mime_type in code_interpreter_types: | ||
return "assistants.code_interpreter" | ||
elif mime_type in [ | ||
'text/plain', 'text/markdown', 'application/pdf', | ||
'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' | ||
]: | ||
return "assistants.file_search" | ||
elif mime_type.startswith('image/'): | ||
return "vision" | ||
return "assistants.file_search" | ||
elif mime_type in dual_types: | ||
return "assistants.file_search" | ||
raise ValueError(f"Unsupported file type: {mime_type}") | ||
|
||
def get_tools(file_path): | ||
mime_type, _ = mimetypes.guess_type(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"}] | ||
else: | ||
raise ValueError(f"Unsupported file type: {mime_type}") |