-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: SimFG <bang.fu@zilliz.com>
- Loading branch information
Showing
6 changed files
with
56 additions
and
21 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from io import BytesIO | ||
|
||
import requests | ||
|
||
from gptcache.embedding.uform import UForm | ||
from gptcache.utils import import_uform, import_pillow | ||
from gptcache.utils.error import ParamError | ||
|
||
import_uform() | ||
import_pillow() | ||
|
||
|
||
def test_uform(): | ||
encoder = UForm() | ||
embed = encoder.to_embeddings("Hello, world.") | ||
assert len(embed) == encoder.dimension | ||
|
||
url = 'https://raw.githubusercontent.com/zilliztech/GPTCache/main/docs/GPTCache.png' | ||
image_bytes = requests.get(url).content | ||
image_file = BytesIO(image_bytes) | ||
|
||
encoder = UForm(embedding_type="image") | ||
embed = encoder.to_embeddings(image_file) | ||
assert len(embed) == encoder.dimension | ||
|
||
is_exception = False | ||
try: | ||
UForm(embedding_type="foo") | ||
except ParamError: | ||
is_exception = True | ||
assert is_exception |