Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github action to run python tests and align api name #19

Merged
merged 7 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
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
33 changes: 33 additions & 0 deletions .github/workflows/test_python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Python Tests

on:
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
test-python-sdk:
name: Python SDK Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./python
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install -r dev-requirements.txt
- name: Run Python Unit Tests
run: |
pytest ./tests -v
8 changes: 4 additions & 4 deletions python/starpoint/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def insert(
return {}
return response.json()

def transpose_and_insert(
def column_insert(
self,
embeddings: List[float],
document_metadatas: List[Dict[Any, Any]],
Expand Down Expand Up @@ -465,14 +465,14 @@ def insert(
collection_name=collection_name,
)

def transpose_and_insert(
def column_insert(
self,
embeddings: List[float],
document_metadatas: List[Dict[Any, Any]],
collection_id: Optional[UUID] = None,
collection_name: Optional[str] = None,
) -> Dict[Any, Any]:
return self.writer.transpose_and_insert(
return self.writer.column_insert(
embeddings=embeddings,
document_metadatas=document_metadatas,
collection_id=collection_id,
Expand Down Expand Up @@ -598,7 +598,7 @@ def build_and_insert_embeddings_from_openai(
try:
sorted_embedding_data = sorted(embedding_data, key=lambda x: x["index"])
embeddings = map(lambda x: x.get("embedding"), sorted_embedding_data)
self.transpose_and_insert(
self.column_insert(
embeddings=embeddings,
document_metadatas=document_metadatas,
collection_id=collection_id,
Expand Down
34 changes: 17 additions & 17 deletions python/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def test_writer_insert_SSLError(


@patch("starpoint.db.Writer.insert")
def test_writer_transpose_and_insert(insert_mock: MagicMock, writer: db.Writer):
def test_writer_column_insert(insert_mock: MagicMock, writer: db.Writer):
test_embeddings = [0.88, 0.71]
test_document_metadatas = [{"mock": "metadata"}, {"mock2": "metadata2"}]
expected_insert_document = [
Expand All @@ -291,7 +291,7 @@ def test_writer_transpose_and_insert(insert_mock: MagicMock, writer: db.Writer):
},
]

writer.transpose_and_insert(
writer.column_insert(
embeddings=test_embeddings, document_metadatas=test_document_metadatas
)

Expand All @@ -303,7 +303,7 @@ def test_writer_transpose_and_insert(insert_mock: MagicMock, writer: db.Writer):


@patch("starpoint.db.Writer.insert")
def test_writer_transpose_and_insert_collection_id_collection_name_passed_through(
def test_writer_column_insert_collection_id_collection_name_passed_through(
insert_mock: MagicMock, writer: db.Writer
):
test_embeddings = [0.88]
Expand All @@ -317,7 +317,7 @@ def test_writer_transpose_and_insert_collection_id_collection_name_passed_throug
expected_collection_id = "mock_id"
expected_collection_name = "mock_name"

writer.transpose_and_insert(
writer.column_insert(
embeddings=test_embeddings,
document_metadatas=test_document_metadatas,
collection_id=expected_collection_id,
Expand All @@ -332,7 +332,7 @@ def test_writer_transpose_and_insert_collection_id_collection_name_passed_throug


@patch("starpoint.db.Writer.insert")
def test_writer_transpose_and_insert_shorter_metadatas_length(
def test_writer_column_insert_shorter_metadatas_length(
insert_mock: MagicMock, writer: db.Writer, monkeypatch: MonkeyPatch
):
test_embeddings = [0.88, 0.71]
Expand All @@ -347,7 +347,7 @@ def test_writer_transpose_and_insert_shorter_metadatas_length(
logger_mock = MagicMock()
monkeypatch.setattr(db, "LOGGER", logger_mock)

writer.transpose_and_insert(
writer.column_insert(
embeddings=test_embeddings, document_metadatas=test_document_metadatas
)

Expand All @@ -362,7 +362,7 @@ def test_writer_transpose_and_insert_shorter_metadatas_length(


@patch("starpoint.db.Writer.insert")
def test_writer_transpose_and_insert_shorter_embeddings_length(
def test_writer_column_insert_shorter_embeddings_length(
insert_mock: MagicMock, writer: db.Writer, monkeypatch: MonkeyPatch
):
test_embeddings = [0.88]
Expand All @@ -377,7 +377,7 @@ def test_writer_transpose_and_insert_shorter_embeddings_length(
logger_mock = MagicMock()
monkeypatch.setattr(db, "LOGGER", logger_mock)

writer.transpose_and_insert(
writer.column_insert(
embeddings=test_embeddings, document_metadatas=test_document_metadatas
)

Expand Down Expand Up @@ -597,13 +597,13 @@ def test_client_insert(mock_writer: MagicMock, mock_reader: MagicMock):

@patch("starpoint.db.Reader")
@patch("starpoint.db.Writer")
def test_client_transpose_and_insert(mock_writer: MagicMock, mock_reader: MagicMock):
def test_client_column_insert(mock_writer: MagicMock, mock_reader: MagicMock):
client = db.Client(api_key=uuid4())

client.transpose_and_insert(embeddings=[1.1], document_metadatas={"mock": "value"})
client.column_insert(embeddings=[1.1], document_metadatas={"mock": "value"})

mock_reader.assert_called_once() # Only called during init
mock_writer().transpose_and_insert.assert_called_once()
mock_writer().column_insert.assert_called_once()


@patch("starpoint.db.Reader")
Expand Down Expand Up @@ -750,10 +750,10 @@ def test_client_build_and_insert_embeddings_from_openai_input_string_success(

assert actual_embedding_response == expected_embedding_response
collision_mock.assert_called_once()
mock_writer().transpose_and_insert.assert_called_once()
mock_writer().column_insert.assert_called_once()

# independently check args since embeddings is a map() generator and cannot be checked against simple equality
insert_call_kwargs = mock_writer().transpose_and_insert.call_args.kwargs
insert_call_kwargs = mock_writer().column_insert.call_args.kwargs
assert [mock_embedding] == list(insert_call_kwargs.get("embeddings"))
assert [{"input": mock_input}] == insert_call_kwargs.get("document_metadatas")
assert insert_call_kwargs.get("collection_id") is None # default value
Expand Down Expand Up @@ -795,10 +795,10 @@ def test_client_build_and_insert_embeddings_from_openai_input_list_success(

assert actual_embedding_response == expected_embedding_response
collision_mock.assert_called_once()
mock_writer().transpose_and_insert.assert_called_once()
mock_writer().column_insert.assert_called_once()

# independently check args since embeddings is a map() generator and cannot be checked against simple equality
insert_call_kwargs = mock_writer().transpose_and_insert.call_args.kwargs
insert_call_kwargs = mock_writer().column_insert.call_args.kwargs
assert [0.77, 0.88] == list(insert_call_kwargs.get("embeddings"))
assert [
{"input": "mock_input1"},
Expand Down Expand Up @@ -836,7 +836,7 @@ def test_client_build_and_insert_embeddings_from_openai_no_data_in_response(

assert actual_embedding_response == expected_embedding_response
collision_mock.assert_called_once()
mock_writer().transpose_and_insert.assert_not_called()
mock_writer().column_insert.assert_not_called()
logger_mock.warning.assert_called_once_with(db.NO_EMBEDDING_DATA_FOUND)


Expand All @@ -863,7 +863,7 @@ def test_client_build_and_insert_embeddings_from_openai_exception_during_write(
}
openai_mock.Embedding.create.return_value = expected_embedding_response

mock_writer().transpose_and_insert.side_effect = RuntimeError("Test Exception")
mock_writer().column_insert.side_effect = RuntimeError("Test Exception")

logger_mock = MagicMock()
monkeypatch.setattr(db, "LOGGER", logger_mock)
Expand Down