mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-28 01:32:17 +00:00
Merge 4bf186fcad into 2dccc0dc79
This commit is contained in:
commit
9c4b552a29
2 changed files with 53 additions and 1 deletions
|
|
@ -24,7 +24,11 @@ from typing import Any, Final
|
|||
from redis import Redis
|
||||
from redis.asyncio import Redis as AsyncRedis
|
||||
from redis.commands.search.field import TagField, VectorField
|
||||
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
|
||||
|
||||
try: # redis-py >= 5 (module renamed to snake_case)
|
||||
from redis.commands.search.index_definition import IndexDefinition, IndexType
|
||||
except ModuleNotFoundError: # redis-py 4.x (last version with camelCase name)
|
||||
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
|
||||
from redis.commands.search.query import Query
|
||||
|
||||
from litellm._logging import print_verbose
|
||||
|
|
|
|||
|
|
@ -534,3 +534,51 @@ def test_importing_caching_does_not_require_redis():
|
|||
)
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert "ok" in result.stdout
|
||||
|
||||
|
||||
def test_valkey_cache_supports_redis_py_4_index_module():
|
||||
code = textwrap.dedent(
|
||||
"""
|
||||
import builtins
|
||||
import sys
|
||||
import types
|
||||
|
||||
class IndexDefinition:
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
class IndexType:
|
||||
HASH = "HASH"
|
||||
|
||||
legacy = types.ModuleType("redis.commands.search.indexDefinition")
|
||||
legacy.IndexDefinition = IndexDefinition
|
||||
legacy.IndexType = IndexType
|
||||
sys.modules[legacy.__name__] = legacy
|
||||
|
||||
original_import = builtins.__import__
|
||||
|
||||
def compatibility_import(name, *args, **kwargs):
|
||||
if name == "redis.commands.search.index_definition":
|
||||
raise ModuleNotFoundError(name=name)
|
||||
return original_import(name, *args, **kwargs)
|
||||
|
||||
builtins.__import__ = compatibility_import
|
||||
from litellm.caching.valkey_semantic_cache import ValkeySemanticCache
|
||||
|
||||
cache = ValkeySemanticCache(
|
||||
similarity_threshold=0.8,
|
||||
sync_client=object(),
|
||||
async_client=object(),
|
||||
)
|
||||
assert cache._index_definition().__class__ is IndexDefinition
|
||||
print("ok")
|
||||
"""
|
||||
)
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", code],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
env={**os.environ, "PYTHONPATH": _REPO_ROOT},
|
||||
)
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert "ok" in result.stdout
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue