mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +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?
|
# What is this?
|
||||||
## Helper utilities
|
## 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(
|
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"]
|
return kwargs["litellm_parent_otel_span"]
|
||||||
except:
|
except:
|
||||||
return None
|
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
|
||||||
|
|
|
@ -55,7 +55,10 @@ import litellm._service_logger # for storing API inputs, outputs, and metadata
|
||||||
import litellm.litellm_core_utils
|
import litellm.litellm_core_utils
|
||||||
import litellm.litellm_core_utils.json_validation_rule
|
import litellm.litellm_core_utils.json_validation_rule
|
||||||
from litellm.caching import DualCache
|
from litellm.caching import DualCache
|
||||||
from litellm.litellm_core_utils.core_helpers import map_finish_reason
|
from litellm.litellm_core_utils.core_helpers import (
|
||||||
|
get_file_check_sum,
|
||||||
|
map_finish_reason,
|
||||||
|
)
|
||||||
from litellm.litellm_core_utils.exception_mapping_utils import get_error_message
|
from litellm.litellm_core_utils.exception_mapping_utils import get_error_message
|
||||||
from litellm.litellm_core_utils.llm_request_utils import _ensure_extra_body_is_safe
|
from litellm.litellm_core_utils.llm_request_utils import _ensure_extra_body_is_safe
|
||||||
from litellm.litellm_core_utils.redact_messages import (
|
from litellm.litellm_core_utils.redact_messages import (
|
||||||
|
@ -557,12 +560,8 @@ def function_setup(
|
||||||
or call_type == CallTypes.transcription.value
|
or call_type == CallTypes.transcription.value
|
||||||
):
|
):
|
||||||
_file_name: BinaryIO = args[1] if len(args) > 1 else kwargs["file"]
|
_file_name: BinaryIO = args[1] if len(args) > 1 else kwargs["file"]
|
||||||
file_name = getattr(_file_name, "name", "audio_file")
|
file_checksum = get_file_check_sum(_file=_file_name)
|
||||||
file_descriptor = _file_name.fileno()
|
file_name = _file_name.name
|
||||||
file_stat = os.fstat(file_descriptor)
|
|
||||||
file_size = str(file_stat.st_size)
|
|
||||||
|
|
||||||
file_checksum = _file_name.name + file_size
|
|
||||||
if "metadata" in kwargs:
|
if "metadata" in kwargs:
|
||||||
kwargs["metadata"]["file_checksum"] = file_checksum
|
kwargs["metadata"]["file_checksum"] = file_checksum
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue