Skip to content

Commit

Permalink
Add unit tests for vector database implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-nightly[bot] authored Jun 21, 2024
1 parent c1a55ac commit a23bef5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sweepai/core/vector_db_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import numpy as np
import requests
import openai
from unittest.mock import patch, MagicMock
from sweepai.core.vector_db import (
cosine_similarity,
Expand All @@ -9,7 +10,8 @@
openai_with_expo_backoff,
normalize_l2,
)
from sweepai.config.server import CACHE_DIRECTORY
# Remove or comment out the unused import
# from sweepai.config.server import CACHE_DIRECTORY

# Mock the Cache class
@pytest.fixture
Expand Down Expand Up @@ -67,11 +69,11 @@ def test_openai_call_embedding_token_limit():
with patch('sweepai.core.vector_db.tiktoken_client.count', return_value=10000):
with patch('sweepai.core.vector_db.tiktoken_client.truncate_string', return_value="truncated"):
with patch('sweepai.core.vector_db.openai_call_embedding_router', side_effect=[
openai.BadRequestError("maximum context length"),
openai.BadRequestError("maximum context length", response=MagicMock(), body={}),
np.array([[1, 2, 3]])
]) as mock_router:
result = openai_call_embedding([long_text])

assert np.array_equal(result, np.array([[1, 2, 3]]))
assert mock_router.call_count == 2
mock_router.assert_called_with(["truncated"], "document")
Expand Down

0 comments on commit a23bef5

Please sign in to comment.