Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions python/tests/unit_tests/test_expect.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,25 @@ def test_expect_explicit_none(mock_client: mock.Mock) -> None:
expect.score(1).to_be_between(0, 2)
expect.score(1).to_be_approximately(1, 2)
expect({1, 2}).to_contain(1)


@mock.patch.object(ls_client, "Client", autospec=True)
def test_embedding_distance_with_bedrock(mock_client: mock.Mock) -> None:
# Mock the bedrock encoder function
def mock_bedrock_encoder(texts):
return [[0.1, 0.2, 0.3] for _ in texts]

# Test with bedrock encoder
config = {"encoder": mock_bedrock_encoder, "metric": "cosine"}
matcher = expect.embedding_distance(
prediction="hello",
reference="hi",
config=config,
)
matcher.to_be_less_than(1.0)
matcher.to_be_greater_than(0.0)
matcher.to_be_between(0.0, 1.0)
matcher.to_be_approximately(0.5, precision=1)
matcher.to_equal(0.5)
matcher.to_be_none()
matcher.to_contain(0.5)