forked from mistralai/client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_embedder.py
More file actions
79 lines (66 loc) · 2.43 KB
/
test_embedder.py
File metadata and controls
79 lines (66 loc) · 2.43 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import unittest.mock as mock
import pytest
from mistralai.client import MistralClient
from mistralai.models.embeddings import EmbeddingResponse
from .utils import mock_embedding_response_payload, mock_response
@pytest.fixture()
def client():
client = MistralClient()
client._client = mock.MagicMock()
return client
class TestEmbeddings:
def test_embeddings(self, client):
client._client.request.return_value = mock_response(
200,
mock_embedding_response_payload(),
)
result = client.embeddings(
model="mistral-embed",
input="What is the best French cheese?",
)
client._client.request.assert_called_once_with(
"post",
"https://api.mistral.ai/v1/embeddings",
headers={
"User-Agent": f"mistral-client-python/{client._version}",
"Accept": "application/json",
"Authorization": "Bearer None",
"Content-Type": "application/json",
},
json={"model": "mistral-embed", "input": "What is the best French cheese?"},
)
assert isinstance(
result, EmbeddingResponse
), "Should return an EmbeddingResponse"
assert len(result.data) == 1
assert result.data[0].index == 0
assert result.object == "list"
def test_embeddings_batch(self, client):
client._client.request.return_value = mock_response(
200,
mock_embedding_response_payload(batch_size=10),
)
result = client.embeddings(
model="mistral-embed",
input=["What is the best French cheese?"] * 10,
)
client._client.request.assert_called_once_with(
"post",
"https://api.mistral.ai/v1/embeddings",
headers={
"User-Agent": f"mistral-client-python/{client._version}",
"Accept": "application/json",
"Authorization": "Bearer None",
"Content-Type": "application/json",
},
json={
"model": "mistral-embed",
"input": ["What is the best French cheese?"] * 10,
},
)
assert isinstance(
result, EmbeddingResponse
), "Should return an EmbeddingResponse"
assert len(result.data) == 10
assert result.data[0].index == 0
assert result.object == "list"