-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make embedder a dependency
- Loading branch information
1 parent
771815c
commit 8e7e17e
Showing
19 changed files
with
71 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from server.dependencies.embedder import embedder as embedder | ||
from server.dependencies.redis import redis_client as redis_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import Iterator | ||
|
||
from server.features.embeddings import Embedder | ||
|
||
|
||
def embedder() -> Iterator[Embedder]: | ||
""" | ||
Summary | ||
------- | ||
load the embeddings model | ||
Returns | ||
------- | ||
embedding (Embedding): the embeddings model | ||
""" | ||
embedder = Embedder() | ||
|
||
try: | ||
yield embedder | ||
|
||
finally: | ||
del embedder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from server.features.embeddings.embedding import Embedding as Embedding | ||
from server.features.embeddings.embedding import Embedder as Embedder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,6 @@ async def chat_model(app: Litestar) -> AsyncIterator[None]: | |
|
||
try: | ||
yield | ||
|
||
finally: | ||
del app.state.chat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,5 +29,6 @@ async def create_redis_index(app: Litestar) -> AsyncIterator[None]: | |
|
||
try: | ||
yield | ||
|
||
finally: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,5 +40,6 @@ async def download_nltk(app: Litestar) -> AsyncIterator[None]: | |
|
||
try: | ||
yield | ||
|
||
finally: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from server.utils.network import huggingface_download as huggingface_download |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from server.utils.network.huggingface_download import ( | ||
huggingface_download as huggingface_download, | ||
) |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...r/helpers/network/huggingface_download.py → server/utils/network/huggingface_download.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
# pylint: disable=missing-function-docstring,redefined-outer-name | ||
|
||
from typing import Literal | ||
from typing import Iterable, Literal | ||
|
||
from numpy import array_equal | ||
from pytest import fixture | ||
|
||
from server.features.embeddings import Embedding | ||
from server.features.embeddings import Embedder | ||
|
||
type Text = Literal['Hello world!'] | ||
|
||
|
||
@fixture() | ||
def embedding(): | ||
yield Embedding(force_download=True) | ||
def embedding() -> Iterable[Embedder]: | ||
embedder = Embedder() | ||
|
||
try: | ||
yield embedder | ||
|
||
finally: | ||
del embedder | ||
|
||
|
||
@fixture() | ||
def text(): | ||
yield 'Hello world!' | ||
|
||
|
||
def test_encodings(embedding: Embedding, text: Text): | ||
def test_encodings(embedding: Embedder, text: Text): | ||
assert array_equal(embedding.encode_query(text), embedding.encode_normalise(text)) is False | ||
|
||
|
||
def test_encode_query(embedding: Embedding, text: Text): | ||
def test_encode_query(embedding: Embedder, text: Text): | ||
assert len(embedding.encode_query(text)) > 0 | ||
|
||
|
||
def test_encode_normalise(embedding: Embedding, text: Text): | ||
def test_encode_normalise(embedding: Embedder, text: Text): | ||
assert len(embedding.encode_normalise(text)) > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters