-
Notifications
You must be signed in to change notification settings - Fork 7.7k
/
test_text_embedding.py
49 lines (35 loc) · 1.37 KB
/
test_text_embedding.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import pytest
from core.model_runtime.entities.text_embedding_entities import TextEmbeddingResult
from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.jina.text_embedding.text_embedding import JinaTextEmbeddingModel
def test_validate_credentials():
model = JinaTextEmbeddingModel()
with pytest.raises(CredentialsValidateFailedError):
model.validate_credentials(model="jina-embeddings-v2-base-en", credentials={"api_key": "invalid_key"})
model.validate_credentials(
model="jina-embeddings-v2-base-en", credentials={"api_key": os.environ.get("JINA_API_KEY")}
)
def test_invoke_model():
model = JinaTextEmbeddingModel()
result = model.invoke(
model="jina-embeddings-v2-base-en",
credentials={
"api_key": os.environ.get("JINA_API_KEY"),
},
texts=["hello", "world"],
user="abc-123",
)
assert isinstance(result, TextEmbeddingResult)
assert len(result.embeddings) == 2
assert result.usage.total_tokens == 6
def test_get_num_tokens():
model = JinaTextEmbeddingModel()
num_tokens = model.get_num_tokens(
model="jina-embeddings-v2-base-en",
credentials={
"api_key": os.environ.get("JINA_API_KEY"),
},
texts=["hello", "world"],
)
assert num_tokens == 6