|
| 1 | +import json |
| 2 | +import random |
| 3 | + |
| 4 | +import pytest |
| 5 | +from constants import EXPECTED_METADATA_SCHEMA_IDS |
| 6 | + |
| 7 | + |
| 8 | +@pytest.fixture |
| 9 | +def mmc_data_row(dataset, make_metadata_fields, embedding): |
| 10 | + row_data = { |
| 11 | + "type": "application/vnd.labelbox.conversational.model-chat-evaluation", |
| 12 | + "draft": True, |
| 13 | + "rootMessageIds": ["root1"], |
| 14 | + "actors": {}, |
| 15 | + "messages": {}, |
| 16 | + } |
| 17 | + |
| 18 | + vector = [random.uniform(1.0, 2.0) for _ in range(embedding.dims)] |
| 19 | + embeddings = [{"embedding_id": embedding.id, "vector": vector}] |
| 20 | + |
| 21 | + content_all = { |
| 22 | + "row_data": row_data, |
| 23 | + "attachments": [{"type": "RAW_TEXT", "value": "attachment value"}], |
| 24 | + "metadata_fields": make_metadata_fields, |
| 25 | + "embeddings": embeddings, |
| 26 | + } |
| 27 | + task = dataset.create_data_rows([content_all]) |
| 28 | + task.wait_till_done() |
| 29 | + assert task.status == "COMPLETE" |
| 30 | + |
| 31 | + data_row = list(dataset.data_rows())[0] |
| 32 | + |
| 33 | + yield data_row |
| 34 | + |
| 35 | + data_row.delete() |
| 36 | + |
| 37 | + |
| 38 | +def test_mmc(mmc_data_row, embedding): |
| 39 | + data_row = mmc_data_row |
| 40 | + assert json.loads(data_row.row_data) == { |
| 41 | + "type": "application/vnd.labelbox.conversational.model-chat-evaluation", |
| 42 | + "draft": True, |
| 43 | + "rootMessageIds": ["root1"], |
| 44 | + "actors": {}, |
| 45 | + "messages": {}, |
| 46 | + } |
| 47 | + |
| 48 | + metadata_fields = data_row.metadata_fields |
| 49 | + metadata = data_row.metadata |
| 50 | + assert len(metadata_fields) == 3 |
| 51 | + assert len(metadata) == 3 |
| 52 | + assert [ |
| 53 | + m["schemaId"] for m in metadata_fields |
| 54 | + ].sort() == EXPECTED_METADATA_SCHEMA_IDS.sort() |
| 55 | + |
| 56 | + attachments = list(data_row.attachments()) |
| 57 | + assert len(attachments) == 1 |
| 58 | + |
| 59 | + assert embedding.get_imported_vector_count() == 1 |
0 commit comments