2024-02-10 07:27:06 -08:00
|
|
|
from unstructured.documents.elements import Text
|
|
|
|
from unstructured.embed.octoai import OctoAiEmbeddingConfig, OctoAIEmbeddingEncoder
|
|
|
|
|
|
|
|
|
|
|
|
def test_embed_documents_does_not_break_element_to_dict(mocker):
|
|
|
|
# Mocked client with the desired behavior for embed_documents
|
|
|
|
mock_client = mocker.MagicMock()
|
|
|
|
mock_client.embed_documents.return_value = [1, 2]
|
|
|
|
|
2024-10-15 11:01:34 -04:00
|
|
|
# Mock get_client to return our mock_client
|
|
|
|
mocker.patch.object(OctoAiEmbeddingConfig, "get_client", return_value=mock_client)
|
2024-02-10 07:27:06 -08:00
|
|
|
|
|
|
|
encoder = OctoAIEmbeddingEncoder(config=OctoAiEmbeddingConfig(api_key="api_key"))
|
|
|
|
elements = encoder.embed_documents(
|
|
|
|
elements=[Text("This is sentence 1"), Text("This is sentence 2")],
|
|
|
|
)
|
|
|
|
assert len(elements) == 2
|
|
|
|
assert elements[0].to_dict()["text"] == "This is sentence 1"
|
|
|
|
assert elements[1].to_dict()["text"] == "This is sentence 2"
|