FilesOperations Class
Constructor
FilesOperations(*args, **kwargs)
Methods
| delete |
Delete a previously uploaded file. |
| get |
Returns information about a specific file. Does not retrieve file content. |
| get_content |
Returns file content as byte stream for given file_id. |
| list |
Gets a list of previously uploaded files. |
| save |
Synchronously saves file content retrieved using a file identifier to the specified local directory. |
| upload |
Uploads a file for use by other operations, delegating to the generated operations. |
| upload_and_poll |
Uploads a file for use by other operations, delegating to the generated operations. |
delete
Delete a previously uploaded file.
delete(file_id: str, **kwargs: Any) -> None
Parameters
| Name | Description |
|---|---|
|
file_id
Required
|
The ID of the file to delete. |
Returns
| Type | Description |
|---|---|
Exceptions
| Type | Description |
|---|---|
get
Returns information about a specific file. Does not retrieve file content.
get(file_id: str, **kwargs: Any) -> FileInfo
Parameters
| Name | Description |
|---|---|
|
file_id
Required
|
The ID of the file to retrieve. Required. |
Returns
| Type | Description |
|---|---|
|
FileInfo. The FileInfo is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
get_content
Returns file content as byte stream for given file_id.
get_content(file_id: str, **kwargs: Any) -> Iterator[bytes]
Parameters
| Name | Description |
|---|---|
|
file_id
Required
|
The ID of the file to retrieve. |
Returns
| Type | Description |
|---|---|
|
An iterator that yields bytes from the file content. |
Exceptions
| Type | Description |
|---|---|
|
If the HTTP request fails. |
list
Gets a list of previously uploaded files.
list(*, purpose: str | FilePurpose | None = None, **kwargs: Any) -> FileListResponse
Keyword-Only Parameters
| Name | Description |
|---|---|
|
purpose
|
str or
FilePurpose
The purpose of the file. Known values are: "assistants", "assistants_output", and "vision". Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
FileListResponse. The FileListResponse is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
save
Synchronously saves file content retrieved using a file identifier to the specified local directory.
save(file_id: str, file_name: str, target_dir: str | Path | None = None) -> None
Parameters
| Name | Description |
|---|---|
|
file_id
Required
|
The unique identifier for the file to retrieve. |
|
file_name
Required
|
The name of the file to be saved. |
|
target_dir
|
The directory where the file should be saved. Defaults to the current working directory. Default value: None
|
Exceptions
| Type | Description |
|---|---|
|
If the target path is not a directory or the file name is invalid. |
|
|
If file content retrieval fails or no content is found. |
|
|
If retrieved chunks are not bytes-like objects. |
|
|
If writing to the file fails. |
upload
Uploads a file for use by other operations, delegating to the generated operations.
upload(*, file_path: str, purpose: str | _models.FilePurpose, **kwargs: Any) -> _models.FileInfo
Parameters
| Name | Description |
|---|---|
|
body
|
Optional[<xref:JSON>]
JSON. Required if file and purpose are not provided. Default value: None
|
Keyword-Only Parameters
| Name | Description |
|---|---|
|
file
|
Optional[<xref:FileType>]
File content. Required if body and purpose are not provided. Default value: None
|
|
file_path
|
Path to the file. Required if body and purpose are not provided. Default value: None
|
|
purpose
|
Known values are: "assistants", "assistants_output", and "vision". Required if body and file are not provided. Default value: None
|
|
filename
|
The name of the file. Default value: None
|
Returns
| Type | Description |
|---|---|
|
FileInfo. The FileInfo is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
|
If the file_path is invalid. |
|
|
If there are issues with reading the file. |
|
|
HttpResponseError for HTTP errors.
|
upload_and_poll
Uploads a file for use by other operations, delegating to the generated operations.
upload_and_poll(body: JSON, *, polling_interval: float = 1, timeout: float | None = None, **kwargs: Any) -> _models.FileInfo
Parameters
| Name | Description |
|---|---|
|
body
|
Optional[<xref:JSON>]
JSON. Required if file and purpose are not provided. Default value: None
|
Keyword-Only Parameters
| Name | Description |
|---|---|
|
file
|
Optional[<xref:FileType>]
File content. Required if body and purpose are not provided. Default value: None
|
|
file_path
|
Path to the file. Required if body and purpose are not provided. Default value: None
|
|
purpose
|
Known values are: "assistants", "assistants_output", and "vision". Required if body and file are not provided. Default value: None
|
|
filename
|
The name of the file. Default value: None
|
|
polling_interval
|
Time to wait before polling for the status of the uploaded file. Default value is 1. Default value: 1
|
|
timeout
|
Time to wait before polling for the status of the uploaded file. Default value: None
|
Returns
| Type | Description |
|---|---|
|
FileInfo. The FileInfo is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
|
If the file_path is invalid. |
|
|
If there are issues with reading the file. |
|
|
If the operation times out while polling for status. |
|
|
HttpResponseError for HTTP errors.
|