Skip to content

Commit

Permalink
Add test cases for OpenAIEmbedder
Browse files Browse the repository at this point in the history
  • Loading branch information
lsz05 committed Apr 9, 2024
1 parent 5594e7b commit cc493e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
- name: Run tests
run: |
poetry run pytest -v -s ./tests
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

lint_check:
runs-on: ubuntu-latest
Expand Down
23 changes: 23 additions & 0 deletions tests/embedders/test_openai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import numpy as np

from jmteb.embedders.openai_embedder import OpenAIEmbedder

OUTPUT_DIM = 1536


class TestSentenceBertEmbedder:
def setup_class(cls):
cls.model = OpenAIEmbedder(model="text-embedding-3-small")

def test_encode(self):
embeddings = self.model.encode("任意のテキスト")
assert isinstance(embeddings, np.ndarray)
assert embeddings.shape == (OUTPUT_DIM,)

def test_encode_multiple(self):
embeddings = self.model.encode(["任意のテキスト"] * 3)
assert isinstance(embeddings, np.ndarray)
assert embeddings.shape == (3, OUTPUT_DIM)

def test_get_output_dim(self):
assert self.model.get_output_dim() == OUTPUT_DIM

0 comments on commit cc493e3

Please sign in to comment.