create_base64_file_validator(*allowed_mime_types)
Creates a function that validates the MIME type of a base64-encoded file.
Parameters: |
|
---|
Returns: |
|
---|
Source code in llm_utils/aiweb_common/file_operations/file_handling.py
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 |
|
create_file_validator(*allowed_mime_types)
Creates a dependency function that validates the MIME type of an uploaded file.
Parameters: |
|
---|
Returns: |
|
---|
Examples: validate_docx_file = create_file_validator("application/vnd.openxmlformats-officedocument.wordprocessingml.document") validate_pdf_file = create_file_validator("application/pdf", "application/x-pdf")
Source code in llm_utils/aiweb_common/file_operations/file_handling.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
file_to_base64(filepath)
Converts a file to a base64-encoded string.
Source code in llm_utils/aiweb_common/file_operations/file_handling.py
12 13 14 15 |
|
ingest_docx(file)
async
The function ingest_docx
reads the content of a DOCX file as bytes, writes it to a temporary file,
and then loads the document from the temporary file.
:param file: The file
parameter in the ingest_docx
function seems to be a file-like object that
supports asynchronous reading operations. When await file.read()
is called, it reads the content
of the file as bytes. This content is then written to a temporary file with a .docx
:return: The function
ingest_docxreturns a tuple containing two values:
1. The name of the temporary file where the DOCX content was written.
2. An instance of the
Document` class representing the loaded document from the temporary file.
Source code in llm_utils/aiweb_common/file_operations/file_handling.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
ingest_docx_bytes(content)
The function ingest_docx_bytes
reads the content of a DOCX file from bytes, saves it to a
temporary file, and then loads the document using the Document
class.
:param content: The ingest_docx_bytes
function you provided seems to be designed to ingest the
content of a DOCX file as bytes and load it using the python-docx
library. However, it looks like
the content parameter is missing in your message. Could you please provide the content parameter so
:return: The ingest_docx_bytes
function returns a tuple containing two values:
1. The name of the temporary file where the content was written (temp_doc.name)
2. The Document object representing the content loaded from the temporary file
Source code in llm_utils/aiweb_common/file_operations/file_handling.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
markdown_to_docx_temporary_file(content, template_location=None)
The function prepare_docx_response
converts Markdown content to a DOCX file and returns the
temporary file path.
:param content: The content
parameter in the prepare_docx_response
function is the text or data
that you want to convert to a DOCX file. This content will be processed and converted into a DOCX
file using the convert_markdown_docx
function
:param template_location: The prepare_docx_response
function takes two parameters:
:return: The function prepare_docx_response
returns the file path of the temporary .docx file that
is created after converting the provided content (in markdown format) to a .docx file using the
specified template location.
Source code in llm_utils/aiweb_common/file_operations/file_handling.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
validate_date(date_str=Query(..., description='The start date in YYYY-MM-DD format'))
Custom dependency that validates and parses a date string.
Args: date_str (str): A date string in the YYYY-MM-DD format.
Returns: datetime: The parsed datetime object.
Raises: HTTPException: If the date string is not in the correct format.
Source code in llm_utils/aiweb_common/file_operations/file_handling.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|