Merge pull request #1878 from BerriAI/litellm_improve_semantic_cache_tracing

[Feat] Semantic Caching - Track Cost of using embedding, Use Langfuse Trace ID
This commit is contained in:
Ishaan Jaff 2024-02-07 19:25:23 -08:00 • committed by GitHub
commit 717dc78d53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -427,10 +427,16 @@ class RedisSemanticCache(BaseCache):
else []
)
if llm_router is not None and self.embedding_model in router_model_names:
user_api_key = kwargs.get("metadata", {}).get("user_api_key", "")
embedding_response = await llm_router.aembedding(
model=self.embedding_model,
input=prompt,
cache={"no-store": True, "no-cache": True},
metadata={
"user_api_key": user_api_key,
"semantic-cache-embedding": True,
"trace_id": kwargs.get("metadata", {}).get("trace_id", None),
},
)
else:
# convert to embedding
@ -476,10 +482,16 @@ class RedisSemanticCache(BaseCache):
else []
)
if llm_router is not None and self.embedding_model in router_model_names:
user_api_key = kwargs.get("metadata", {}).get("user_api_key", "")
embedding_response = await llm_router.aembedding(
model=self.embedding_model,
input=prompt,
cache={"no-store": True, "no-cache": True},
metadata={
"user_api_key": user_api_key,
"semantic-cache-embedding": True,
"trace_id": kwargs.get("metadata", {}).get("trace_id", None),
},
)
else:
# convert to embedding