BytesToDocx
Bases: FastAPIUploadManager
Source code in llm_utils/aiweb_common/file_operations/upload_manager.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
process_file_bytes(file, extension='.docx')
The function process_file_bytes
processes a file in bytes format, specifically for a .docx
extension, and returns a Document object while also handling background tasks.
Parameters: |
|
---|
object representing the content of a file. This method processes the file bytes, specifically for a
.docx
file. If the provided extension is not .docx
, a TypeError
is raised.
extension: The extension
parameter in the process_file_bytes
method is used to specify the
file extension that the method expects the input file to have. In this case, the default extension
is set to ".docx". If the provided extension does not match ".docx", a TypeError is raised. Defaults
to .docx
Returns: |
|
---|
a file given as bytes input.
Source code in llm_utils/aiweb_common/file_operations/upload_manager.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
FastAPIUploadManager
Bases: UploadManager
Source code in llm_utils/aiweb_common/file_operations/upload_manager.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
process_file_bytes(file, extension)
Reads the file from byte string based on the file extension and returns either a DataFrame or a markdown string.
Parameters: |
|
---|
Returns: |
|
---|
Source code in llm_utils/aiweb_common/file_operations/upload_manager.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
read_and_validate_file(encoded_file, extension)
The function reads and validates a base64 encoded file, then processes it based on the specified file extension.
Parameters: |
|
---|
encoded in base64 format. This function reads and validates the file content by decoding it from
base64 and then passing it to the read_file
method for further processing based on the specified
file extension. If any errors occur during
extension (str): Extension refers to the file format or type of the file being processed. It is
typically represented by a file extension such as ".txt", ".pdf", ".jpg", etc. In the context of the
provided code snippet, the extension parameter is used to specify the file format of the decoded
file before further
Returns: |
|
---|
None. If the read_file
method returns None, a HTTPException with status code 422 and detail
"Failed to process the file" is raised. If any other exception occurs during the process, a
HTTPException with status code 500 and the exception message is raised.
Source code in llm_utils/aiweb_common/file_operations/upload_manager.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
StreamlitUploadManager
Bases: UploadManager
Source code in llm_utils/aiweb_common/file_operations/upload_manager.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
__init__(file=None, message='Please upload a file', file_types=None, accept_multiple_files=False, document_analysis_client=None)
Allows either an already-uploaded file (passed via file
) or performs an interactive upload.
Parameters: |
|
---|
Source code in llm_utils/aiweb_common/file_operations/upload_manager.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
process_upload()
If no file has been provided during initialization, show the file uploader. Then, process the file based on its extension. Returns a tuple (processed_file, extension) or (None, None) if no file is provided.
Source code in llm_utils/aiweb_common/file_operations/upload_manager.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
upload_file()
Wraps process_upload for backward compatibility. You can choose your naming.
Source code in llm_utils/aiweb_common/file_operations/upload_manager.py
79 80 81 82 83 |
|