Skip to content

Commit

Permalink
Merge pull request #539 from MichaelDecent/0.4.5.dev1
Browse files Browse the repository at this point in the history
added fixtures RedisVectorStore_test.py
  • Loading branch information
cobycloud authored Sep 25, 2024
2 parents c0a3282 + 8885a62 commit a4366d8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
4 changes: 3 additions & 1 deletion pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_serialization(openrouter_model):

@pytest.mark.unit
def test_default_name(openrouter_model):
assert openrouter_model.name == "01-ai/yi-34b"
assert openrouter_model.name == "mistralai/pixtral-12b:free"


@pytest.mark.parametrize("model_name", get_allowed_models())
Expand All @@ -68,6 +68,7 @@ def test_no_system_context(openrouter_model, model_name):
@pytest.mark.parametrize("model_name", get_allowed_models())
@pytest.mark.unit
def test_preamble_system_context(openrouter_model, model_name):
failed_models = []
model = openrouter_model
model.name = model_name
conversation = Conversation()
Expand All @@ -86,5 +87,6 @@ def test_preamble_system_context(openrouter_model, model_name):
assert isinstance(prediction, str)
assert "Jeff" in prediction
except Exception as e:
failed_models.append(model.name)
pytest.fail(f"Error: {e}")
# pytest.skip(f"Error: {e}")
42 changes: 20 additions & 22 deletions pkgs/swarmauri/tests/unit/vector_stores/RedisVectorStore_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import pytest
from swarmauri.documents.concrete.Document import Document
from swarmauri.vector_stores.concrete.RedisVectorStore import RedisVectorStore
from dotenv import load_dotenv
from os import getenv

load_dotenv()

REDIS_HOST = getenv("REDIS_HOST")
REDIS_PORT = getenv("REDIS_HOST", "12648")
REDIS_PASSWORD = getenv("REDIS_PASSWORD")


@pytest.fixture(scope="module")
def vector_store():
if not all([REDIS_HOST, REDIS_PORT, REDIS_PASSWORD]):
pytest.skip("Skipping due to environment variable not set")
vector_store = RedisVectorStore(
redis_host="redis-12648.c305.ap-south-1-1.ec2.redns.redis-cloud.com",
redis_port=12648,
redis_password="EaNg3YcgUW94Uj1P5wT3LScNtM97avu2", # Replace with your password if needed
redis_host=REDIS_HOST,
redis_port=REDIS_PORT,
redis_password=REDIS_PASSWORD, # Replace with your password if needed
embedding_dimension=8000, # Adjust based on your embedder
)
return vector_store
Expand All @@ -25,38 +35,26 @@ def sample_document():


@pytest.mark.unit
def test_ubc_resource():
vs = RedisVectorStore(
redis_host="redis-12648.c305.ap-south-1-1.ec2.redns.redis-cloud.com",
redis_port=12648,
redis_password="EaNg3YcgUW94Uj1P5wT3LScNtM97avu2", # Replace with your password if needed
embedding_dimension=8000, # Adjust based on your embedder
)
assert vs.resource == "VectorStore"
def test_ubc_resource(vector_store):
assert vector_store.resource == "VectorStore"


@pytest.mark.unit
def test_ubc_type():
vs = RedisVectorStore(
redis_host="redis-12648.c305.ap-south-1-1.ec2.redns.redis-cloud.com",
redis_port=12648,
redis_password="EaNg3YcgUW94Uj1P5wT3LScNtM97avu2",
embedding_dimension=8000,
)
assert vs.type == "RedisVectorStore"
def test_ubc_type(vector_store):
assert vector_store.type == "RedisVectorStore"


@pytest.mark.unit
def top_k_test(vs=vector_store):
def top_k_test(vector_store):
documents = [
Document(content="test"),
Document(content="test1"),
Document(content="test2"),
Document(content="test3"),
]

vs.add_documents(documents)
assert len(vs.retrieve(query="test", top_k=2)) == 2
vector_store.add_documents(documents)
assert len(vector_store.retrieve(query="test", top_k=2)) == 2


@pytest.mark.unit
Expand Down

0 comments on commit a4366d8

Please sign in to comment.