Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: merge release/2.157.4 into main #1731

Merged
merged 9 commits into from
Jul 4, 2024
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools", "wheel"]

[project]
name = "kili"
version = "2.156.2"
version = "2.157.4"
description = "Python client for Kili Technology labeling tool"
readme = "README.md"
authors = [{ name = "Kili Technology", email = "[email protected]" }]
Expand Down
2 changes: 1 addition & 1 deletion src/kili/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Kili Python SDK."""

__version__ = "2.156.2"
__version__ = "2.157.4"
2 changes: 1 addition & 1 deletion src/kili/entrypoints/mutations/asset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MutationsAsset(BaseOperationEntrypointMixin):
def append_many_to_dataset(
self,
project_id: str,
content_array: Optional[Union[List[str], List[dict]]] = None,
content_array: Optional[Union[List[str], List[dict], List[List[dict]]]] = None,
multi_layer_content_array: Optional[List[List[dict]]] = None,
external_id_array: Optional[List[str]] = None,
id_array: Optional[List[str]] = None,
Expand Down
2 changes: 1 addition & 1 deletion src/kili/presentation/client/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ def is_rectangle(coco_annotation, coco_image, kili_annotation):
self, # pyright: ignore[reportGeneralTypeIssues]
asset_ids=resolved_asset_ids,
project_id=ProjectId(project_id),
export_type="latest",
export_type="normal" if fmt == "llm_v1" else "latest",
label_format=fmt,
split_option=layout,
single_file=single_file,
Expand Down
15 changes: 9 additions & 6 deletions src/kili/services/asset_import/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import warnings

SEPARATOR = "___"


def is_chat_format(data, required_keys):
"""Checks if llm file data is in chat format."""
Expand Down Expand Up @@ -43,8 +45,8 @@ def process_json(data):
if item["content"] is None:
raise ValueError("Chat item content cannot be null.")

# Check if the model is null (indicating a prompt)
if item["model"] is None:
# Check if the prompt comes from a user or a model
if item["role"] in ["user", "system"]:
# If there's an existing prompt being processed, add it to the prompts list
if current_prompt is not None:
transformed_data["prompts"].append(
Expand All @@ -68,8 +70,9 @@ def process_json(data):
"title": item["role"],
}
)
# Collect model for this item
models.append(item["model"])
# Add model if not None
if item["model"] is not None:
models.append(item["model"])

if current_prompt is None:
raise ValueError(
Expand All @@ -85,12 +88,12 @@ def process_json(data):
}
)

chat_item_ids = "_".join(item_ids)
chat_item_ids = SEPARATOR.join(item_ids)

# Prepare additional_json_metadata
additional_json_metadata = {
"chat_id": chat_id,
"models": "_".join(models[-2:]), # Join the last two models
"models": SEPARATOR.join(models[-len(completions) :]), # Join the evaluated models
"chat_item_ids": chat_item_ids, # Concatenate all item IDs
"text": f"Chat_id: {chat_id}\n\nChat_item_ids: {chat_item_ids}",
}
Expand Down
28 changes: 16 additions & 12 deletions src/kili/services/export/format/llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
from typing import Dict, List, Optional, Union

from kili.services.asset_import.helpers import SEPARATOR
from kili.services.export.exceptions import NotCompatibleInputType
from kili.services.export.format.base import AbstractExporter
from kili.services.types import Job
Expand Down Expand Up @@ -53,23 +54,26 @@ def process(self, assets: List[Dict]) -> List[Dict[str, Union[List[str], str]]]:
def _process(self, assets: List[Dict]) -> List[Dict[str, Union[List[str], str]]]:
result = []
for asset in assets:
jobs_config = self.project["jsonInterface"]["jobs"]
latest_label = asset["latestLabel"]
result.append(
{
"raw_data": _format_raw_data(asset),
"status": asset["status"],
"external_id": asset["externalId"],
"metadata": asset["jsonMetadata"],
"labels": [
{
"author": latest_label["author"]["email"],
"created_at": latest_label["createdAt"],
"label_type": latest_label["labelType"],
"label": _format_json_response(
jobs_config, latest_label["jsonResponse"]
),
}
list(
map(
lambda label: {
"author": label["author"]["email"],
"created_at": label["createdAt"],
"label_type": label["labelType"],
"label": _format_json_response(
self.project["jsonInterface"]["jobs"], label["jsonResponse"]
),
},
asset["labels"],
)
)
],
}
)
Expand Down Expand Up @@ -110,7 +114,7 @@ def _format_raw_data(asset) -> List[Dict]:
and isinstance(asset["jsonMetadata"]["chat_item_ids"], str)
and len(asset["jsonMetadata"]["chat_item_ids"]) > 0
):
chat_items_ids = str.split(asset["jsonMetadata"]["chat_item_ids"], "_")
chat_items_ids = str.split(asset["jsonMetadata"]["chat_item_ids"], SEPARATOR)
else:
chat_items_ids = []

Expand All @@ -119,7 +123,7 @@ def _format_raw_data(asset) -> List[Dict]:
and isinstance(asset["jsonMetadata"]["models"], str)
and len(asset["jsonMetadata"]["models"]) > 0
):
models = str.split(asset["jsonMetadata"]["models"], "_")
models = str.split(asset["jsonMetadata"]["models"], SEPARATOR)
else:
models = []

Expand Down
14 changes: 7 additions & 7 deletions tests/unit/services/asset_import/test_import_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_upload_from_one_local_file_in_chat_format(self, *_):
[False],
[""],
[
'{"chat_id": "6e4094947af4902cd252421aba9a077e8e4402dd", "models": "model-large_model-medium", "chat_item_ids": "0455df65c2d6bb821a9dc9108ac1d79964a0f571_4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d_7326ff17cbfe7e3cb91b008cf0c496fcd17a1074_375b55d44af2c8c801992089c797df8e12605dfb_9231d8819ac96cc8a6c4b7780c301b796c3f8bf2", "text": "Chat_id: 6e4094947af4902cd252421aba9a077e8e4402dd\\n\\nChat_item_ids: 0455df65c2d6bb821a9dc9108ac1d79964a0f571_4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d_7326ff17cbfe7e3cb91b008cf0c496fcd17a1074_375b55d44af2c8c801992089c797df8e12605dfb_9231d8819ac96cc8a6c4b7780c301b796c3f8bf2"}'
'{"chat_id": "6e4094947af4902cd252421aba9a077e8e4402dd", "models": "model-large___model-medium", "chat_item_ids": "0455df65c2d6bb821a9dc9108ac1d79964a0f571___4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d___7326ff17cbfe7e3cb91b008cf0c496fcd17a1074___375b55d44af2c8c801992089c797df8e12605dfb___9231d8819ac96cc8a6c4b7780c301b796c3f8bf2", "text": "Chat_id: 6e4094947af4902cd252421aba9a077e8e4402dd\\n\\nChat_item_ids: 0455df65c2d6bb821a9dc9108ac1d79964a0f571___4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d___7326ff17cbfe7e3cb91b008cf0c496fcd17a1074___375b55d44af2c8c801992089c797df8e12605dfb___9231d8819ac96cc8a6c4b7780c301b796c3f8bf2"}'
],
)
self.kili.graphql_client.execute.assert_called_with(*expected_parameters)
Expand All @@ -69,7 +69,7 @@ def test_upload_from_one_local_file_in_chat_format_with_given_json_metadata(self
[False],
[""],
[
'{"customKey": "customValue", "chat_id": "6e4094947af4902cd252421aba9a077e8e4402dd", "models": "model-large_model-medium", "chat_item_ids": "0455df65c2d6bb821a9dc9108ac1d79964a0f571_4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d_7326ff17cbfe7e3cb91b008cf0c496fcd17a1074_375b55d44af2c8c801992089c797df8e12605dfb_9231d8819ac96cc8a6c4b7780c301b796c3f8bf2", "text": "Chat_id: 6e4094947af4902cd252421aba9a077e8e4402dd\\n\\nChat_item_ids: 0455df65c2d6bb821a9dc9108ac1d79964a0f571_4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d_7326ff17cbfe7e3cb91b008cf0c496fcd17a1074_375b55d44af2c8c801992089c797df8e12605dfb_9231d8819ac96cc8a6c4b7780c301b796c3f8bf2"}'
'{"customKey": "customValue", "chat_id": "6e4094947af4902cd252421aba9a077e8e4402dd", "models": "model-large___model-medium", "chat_item_ids": "0455df65c2d6bb821a9dc9108ac1d79964a0f571___4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d___7326ff17cbfe7e3cb91b008cf0c496fcd17a1074___375b55d44af2c8c801992089c797df8e12605dfb___9231d8819ac96cc8a6c4b7780c301b796c3f8bf2", "text": "Chat_id: 6e4094947af4902cd252421aba9a077e8e4402dd\\n\\nChat_item_ids: 0455df65c2d6bb821a9dc9108ac1d79964a0f571___4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d___7326ff17cbfe7e3cb91b008cf0c496fcd17a1074___375b55d44af2c8c801992089c797df8e12605dfb___9231d8819ac96cc8a6c4b7780c301b796c3f8bf2"}'
],
)
self.kili.graphql_client.execute.assert_called_with(*expected_parameters)
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_upload_from_dict_in_chat_format(self, *_):
[False],
[""],
[
'{"chat_id": "6e4094947af4902cd252421aba9a077e8e4402dd", "models": "model-large_model-medium", "chat_item_ids": "0455df65c2d6bb821a9dc9108ac1d79964a0f571_4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d_7326ff17cbfe7e3cb91b008cf0c496fcd17a1074_375b55d44af2c8c801992089c797df8e12605dfb_9231d8819ac96cc8a6c4b7780c301b796c3f8bf2", "text": "Chat_id: 6e4094947af4902cd252421aba9a077e8e4402dd\\n\\nChat_item_ids: 0455df65c2d6bb821a9dc9108ac1d79964a0f571_4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d_7326ff17cbfe7e3cb91b008cf0c496fcd17a1074_375b55d44af2c8c801992089c797df8e12605dfb_9231d8819ac96cc8a6c4b7780c301b796c3f8bf2"}'
'{"chat_id": "6e4094947af4902cd252421aba9a077e8e4402dd", "models": "model-large___model-medium", "chat_item_ids": "0455df65c2d6bb821a9dc9108ac1d79964a0f571___4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d___7326ff17cbfe7e3cb91b008cf0c496fcd17a1074___375b55d44af2c8c801992089c797df8e12605dfb___9231d8819ac96cc8a6c4b7780c301b796c3f8bf2", "text": "Chat_id: 6e4094947af4902cd252421aba9a077e8e4402dd\\n\\nChat_item_ids: 0455df65c2d6bb821a9dc9108ac1d79964a0f571___4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d___7326ff17cbfe7e3cb91b008cf0c496fcd17a1074___375b55d44af2c8c801992089c797df8e12605dfb___9231d8819ac96cc8a6c4b7780c301b796c3f8bf2"}'
],
)
self.kili.graphql_client.execute.assert_called_with(*expected_parameters)
Expand Down Expand Up @@ -213,7 +213,7 @@ def test_upload_from_dict_in_chat_format_with_json_metadata(self, *_):
[False],
[""],
[
'{"customKey": "customValue", "chat_id": "6e4094947af4902cd252421aba9a077e8e4402dd", "models": "model-large_model-medium", "chat_item_ids": "0455df65c2d6bb821a9dc9108ac1d79964a0f571_4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d_7326ff17cbfe7e3cb91b008cf0c496fcd17a1074_375b55d44af2c8c801992089c797df8e12605dfb_9231d8819ac96cc8a6c4b7780c301b796c3f8bf2", "text": "Chat_id: 6e4094947af4902cd252421aba9a077e8e4402dd\\n\\nChat_item_ids: 0455df65c2d6bb821a9dc9108ac1d79964a0f571_4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d_7326ff17cbfe7e3cb91b008cf0c496fcd17a1074_375b55d44af2c8c801992089c797df8e12605dfb_9231d8819ac96cc8a6c4b7780c301b796c3f8bf2"}'
'{"customKey": "customValue", "chat_id": "6e4094947af4902cd252421aba9a077e8e4402dd", "models": "model-large___model-medium", "chat_item_ids": "0455df65c2d6bb821a9dc9108ac1d79964a0f571___4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d___7326ff17cbfe7e3cb91b008cf0c496fcd17a1074___375b55d44af2c8c801992089c797df8e12605dfb___9231d8819ac96cc8a6c4b7780c301b796c3f8bf2", "text": "Chat_id: 6e4094947af4902cd252421aba9a077e8e4402dd\\n\\nChat_item_ids: 0455df65c2d6bb821a9dc9108ac1d79964a0f571___4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d___7326ff17cbfe7e3cb91b008cf0c496fcd17a1074___375b55d44af2c8c801992089c797df8e12605dfb___9231d8819ac96cc8a6c4b7780c301b796c3f8bf2"}'
],
)
self.kili.graphql_client.execute.assert_called_with(*expected_parameters)
Expand Down Expand Up @@ -255,8 +255,8 @@ def test_process_json(self, *_):
},
{
"chat_id": "6e4094947af4902cd252421aba9a077e8e4402dd",
"models": "model-large_model-medium",
"chat_item_ids": "0455df65c2d6bb821a9dc9108ac1d79964a0f571_4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d_7326ff17cbfe7e3cb91b008cf0c496fcd17a1074_375b55d44af2c8c801992089c797df8e12605dfb_9231d8819ac96cc8a6c4b7780c301b796c3f8bf2",
"text": "Chat_id: 6e4094947af4902cd252421aba9a077e8e4402dd\n\nChat_item_ids: 0455df65c2d6bb821a9dc9108ac1d79964a0f571_4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d_7326ff17cbfe7e3cb91b008cf0c496fcd17a1074_375b55d44af2c8c801992089c797df8e12605dfb_9231d8819ac96cc8a6c4b7780c301b796c3f8bf2",
"models": "model-large___model-medium",
"chat_item_ids": "0455df65c2d6bb821a9dc9108ac1d79964a0f571___4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d___7326ff17cbfe7e3cb91b008cf0c496fcd17a1074___375b55d44af2c8c801992089c797df8e12605dfb___9231d8819ac96cc8a6c4b7780c301b796c3f8bf2",
"text": "Chat_id: 6e4094947af4902cd252421aba9a077e8e4402dd\n\nChat_item_ids: 0455df65c2d6bb821a9dc9108ac1d79964a0f571___4c28c86c4b22b3397691ce5cf27197fcf7e8fb2d___7326ff17cbfe7e3cb91b008cf0c496fcd17a1074___375b55d44af2c8c801992089c797df8e12605dfb___9231d8819ac96cc8a6c4b7780c301b796c3f8bf2",
},
)
Loading