test -base64 cache hits

This commit is contained in:
Ishaan Jaff 2024-04-10 16:46:56 -07:00
parent 0c26404cb3
commit 8bc02b34c2
2 changed files with 45 additions and 0 deletions

View 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)

View file

@ -387,6 +387,41 @@ async def test_embedding_caching_azure_individual_items_reordered():
assert embedding_val_1.data[1]["index"] == 1 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 @pytest.mark.asyncio
async def test_redis_cache_basic(): async def test_redis_cache_basic():
""" """