Merge pull request #5075 from BerriAI/litelm_use_file_checksum

[Feat] /audio/transcription use file checksum for cache key
This commit is contained in:
Ishaan Jaff 2024-08-06 16:48:31 -07:00 committed by GitHub
commit c11f575029
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View file

@ -10,6 +10,7 @@
import ast
import asyncio
import hashlib
import io
import json
import logging
import time
@ -1889,8 +1890,10 @@ class Cache:
metadata = kwargs.get("metadata", {})
litellm_params = kwargs.get("litellm_params", {})
# get checksum of file content
param_value = (
getattr(file, "name", None)
metadata.get("file_checksum")
or getattr(file, "name", None)
or metadata.get("file_name")
or litellm_params.get("file_name")
)

View file

@ -13,6 +13,7 @@ import base64
import binascii
import copy
import datetime
import hashlib
import inspect
import itertools
import json
@ -554,6 +555,15 @@ def function_setup(
):
_file_name: BinaryIO = args[1] if len(args) > 1 else kwargs["file"]
file_name = getattr(_file_name, "name", "audio_file")
file_descriptor = _file_name.fileno()
file_stat = os.fstat(file_descriptor)
file_size = str(file_stat.st_size)
file_checksum = _file_name.name + file_size
if "metadata" in kwargs:
kwargs["metadata"]["file_checksum"] = file_checksum
else:
kwargs["metadata"] = {"file_checksum": file_checksum}
messages = file_name
elif (
call_type == CallTypes.aspeech.value or call_type == CallTypes.speech.value