file_handling.py
Source: src/sunholo/genai/file_handling.py
Functions
construct_file_content(gs_list, bucket: str, genai_lib=False, timeout=60, genai_lib_vertex=False)
Args:
- gs_list: a list of dicts representing files in a bucket
- bucket: The bucket the files are in
- genai_lib: whether its using the genai SDK
- timeout: timeout in seconds for the gather operation
- genai_lib_vertex: bool whether to use the vertex version of the genai library, using default credentials
download_gcs_upload_genai(img_url, mime_type, name=None, display_url=None, display_name=None, retries=3, delay=2, genai_lib=False)
Downloads and uploads a file with retries in case of failure. Thread-safe implementation using unique file paths.
Args:
-
img_url: str The URL of the file to download.
-
mime_type: str The MIME type of the file.
-
name: str Optional name, else a random one will be created
-
retries: int Number of retry attempts before failing.
-
delay: int Initial delay between retries, exponentially increasing.
-
genai_lin: bool whether to use newer genai library to upload files
Returns:
- downloaded_content: The result of the file upload if successful.
download_file_with_error_handling(img_url, mime_type, name)
No docstring available.
sanitize_file(filename)
Sanitize filename to conform to Gemini API requirements:
- Only lowercase alphanumeric characters and dashes
- Cannot begin or end with a dash