Skip to content

Commit

Permalink
Release 1.0.0: add example
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed May 5, 2023
1 parent 649b71f commit 38b252d
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 116 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,37 @@ jobs:
- name: Run tests
run: |
poetry run pytest test_integration.py
make test
- uses: actions-ecosystem/action-regex-match@v2
id: regex-match
with:
text: ${{ github.event.head_commit.message }}
regex: "^Release ([^ ]+)"

- name: Build package
run: |
poetry build
- name: Publish to PyPI
if: ${{ steps.regex-match.outputs.match != '' }}
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }}
poetry publish
- uses: rickstaa/action-create-tag@v1
if: ${{ steps.regex-match.outputs.match != '' }}
id: "tag_create"
with:
tag: ${{ env.version }}
tag_exists_error: true
message: "Release ${{ steps.regex-match.outputs.group1 }}"

- name: Create Release
if: ${{ steps.regex-match.outputs.match != '' }}
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.version }}
name: ${{ env.version }}
draft: false
prerelease: false
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
VERSION="$(shell python3 -c 'import toml; print(toml.load("pyproject.toml")["tool"]["poetry"]["version"])')"

#* Release

release: ## [Local development] Release a new version of the API.
@echo "Releasing version ${VERSION}"; \
read -p "Commit content:" COMMIT; \
git add .; \
echo "Committing '${VERSION}: $$COMMIT'"; \
git commit -m "Release ${VERSION}: $$COMMIT"; \
git push origin main
@echo "Done, check '\033[0;31mhttps://github.com/different-ai/embedbase-qdrant/actions\033[0m'"

#* Testing

Expand Down
45 changes: 45 additions & 0 deletions examples/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from embedbase import get_app
from embedbase.embedding.base import Embedder
import uvicorn
from sentence_transformers import SentenceTransformer
from embedbase_qdrant import Qdrant

class LocalEmbedder(Embedder):
EMBEDDING_MODEL = "all-MiniLM-L6-v2"

def __init__(self, model: str = EMBEDDING_MODEL, **kwargs):
super().__init__(**kwargs)
self.model = SentenceTransformer(model)
self._dimensions = self.model.get_sentence_embedding_dimension()

@property
def dimensions(self) -> int:
"""
Return the dimensions of the embeddings
:return: dimensions of the embeddings
"""
return self._dimensions

def is_too_big(self, text: str) -> bool:
"""
Check if text is too big to be embedded,
delegating the splitting UX to the caller
:param text: text to check
:return: True if text is too big, False otherwise
"""
return len(text) > self.model.get_max_seq_length()

async def embed(self, data):
"""
Embed a list of strings or a single string
:param data: list of strings or a single string
:return: list of embeddings
"""
embeddings = self.model.encode(data)
return embeddings.tolist() if isinstance(data, list) else [embeddings.tolist()]


app = get_app().use_embedder(LocalEmbedder()).use_db(Qdrant()).run()

if __name__ == "__main__":
uvicorn.run(app, reload=True)
3 changes: 3 additions & 0 deletions examples/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
embedbase
sentence-transformers
git+https://github.com/different-ai/embedbase-qdrant.git
Loading

0 comments on commit 38b252d

Please sign in to comment.