mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 19:24:27 +00:00
fix use get_file_check_sum
This commit is contained in:
parent
4220f51bb9
commit
c6799e8aad
2 changed files with 27 additions and 8 deletions
|
@ -1,6 +1,9 @@
|
|||
# What is this?
|
||||
## Helper utilities
|
||||
from typing import List, Literal, Optional, Tuple
|
||||
import os
|
||||
from typing import BinaryIO, List, Literal, Optional, Tuple
|
||||
|
||||
from litellm._logging import verbose_logger
|
||||
|
||||
|
||||
def map_finish_reason(
|
||||
|
@ -83,3 +86,20 @@ def _get_parent_otel_span_from_kwargs(kwargs: Optional[dict] = None):
|
|||
return kwargs["litellm_parent_otel_span"]
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
def get_file_check_sum(_file: BinaryIO):
|
||||
"""
|
||||
Helper to safely get file checksum - used as a cache key
|
||||
"""
|
||||
try:
|
||||
file_descriptor = _file.fileno()
|
||||
file_stat = os.fstat(file_descriptor)
|
||||
file_size = str(file_stat.st_size)
|
||||
file_checksum = _file.name + file_size
|
||||
return file_checksum
|
||||
except Exception as e:
|
||||
verbose_logger.error(f"Error getting file_checksum: {(str(e))}")
|
||||
file_checksum = _file.name
|
||||
return file_checksum
|
||||
return file_checksum
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue