mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-20 00:11:50 +00:00
Merge pull request #2943 from BerriAI/litellm_allow_base_64_embedding
Fix - Embedding Caching - allow base 64 embedding cache hits
This commit is contained in:
commit
3424068cad
3 changed files with 47 additions and 2 deletions
10
litellm/proxy/tests/test_openai_simple_embedding.py
Normal file
10
litellm/proxy/tests/test_openai_simple_embedding.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import openai
|
||||
|
||||
client = openai.OpenAI(api_key="sk-1234", base_url="http://0.0.0.0:4000")
|
||||
|
||||
# # request sent to model set on litellm proxy, `litellm --model`
|
||||
response = client.embeddings.create(
|
||||
model="text-embedding-ada-002", input=["test"], encoding_format="base64"
|
||||
)
|
||||
|
||||
print(response)
|
||||
|
|
@ -387,6 +387,41 @@ async def test_embedding_caching_azure_individual_items_reordered():
|
|||
assert embedding_val_1.data[1]["index"] == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_embedding_caching_base_64():
|
||||
""" """
|
||||
litellm.cache = Cache(
|
||||
type="redis",
|
||||
host=os.environ["REDIS_HOST"],
|
||||
port=os.environ["REDIS_PORT"],
|
||||
)
|
||||
import uuid
|
||||
|
||||
inputs = [
|
||||
f"{uuid.uuid4()} hello this is ishaan",
|
||||
f"{uuid.uuid4()} hello this is ishaan again",
|
||||
]
|
||||
|
||||
embedding_val_1 = await aembedding(
|
||||
model="azure/azure-embedding-model",
|
||||
input=inputs,
|
||||
caching=True,
|
||||
encoding_format="base64",
|
||||
)
|
||||
embedding_val_2 = await aembedding(
|
||||
model="azure/azure-embedding-model",
|
||||
input=inputs,
|
||||
caching=True,
|
||||
encoding_format="base64",
|
||||
)
|
||||
|
||||
assert embedding_val_2._hidden_params["cache_hit"] == True
|
||||
print(embedding_val_2)
|
||||
print(embedding_val_1)
|
||||
assert embedding_val_2.data[0]["embedding"] == embedding_val_1.data[0]["embedding"]
|
||||
assert embedding_val_2.data[1]["embedding"] == embedding_val_1.data[1]["embedding"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_redis_cache_basic():
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ class HiddenParams(OpenAIObject):
|
|||
|
||||
class Config:
|
||||
extra = "allow"
|
||||
protected_namespaces = ()
|
||||
protected_namespaces = ()
|
||||
|
||||
def get(self, key, default=None):
|
||||
# Custom .get() method to access attributes with a default value if the attribute doesn't exist
|
||||
|
|
@ -606,7 +606,7 @@ class ModelResponse(OpenAIObject):
|
|||
|
||||
|
||||
class Embedding(OpenAIObject):
|
||||
embedding: list = []
|
||||
embedding: Union[list, str] = []
|
||||
index: int
|
||||
object: str
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue