Skip to content

Commit

Permalink
fix: export dynamic without completions
Browse files Browse the repository at this point in the history
  • Loading branch information
baptiste-olivier committed Nov 15, 2024
1 parent d50c784 commit 4fbe5b7
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/kili/llm/services/export/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ def _build_rounds(self, chat_items, annotations, json_interface):
current_round = self._init_round([])

while has_children:
node = dict_chat_items[parent_target][0]
nodes = dict_chat_items.get(parent_target)
if nodes is None or len(nodes) == 0:
has_children = False
continue
node = nodes[0]
if node["role"].lower() == "system":
current_round["pre_prompts"].append(node)
parent_target = node["id"]
Expand Down
131 changes: 131 additions & 0 deletions tests/unit/llm/services/export/test_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,115 @@
}
]

mock_fetch_assets_no_completions = [
{
"labels": [
{
"annotations": [],
"author": {
"id": "user-1",
"email": "[email protected]",
"firstname": "Test",
"lastname": "Admin",
},
"chatItems": [
{
"id": "clziefeh6003k7tc99abderkk",
"content": "describe turtle in 100 words",
"createdAt": "2024-08-06T12:30:52.170Z",
"modelId": None,
"parentId": "cm2u6kgcc001aj7ja1stsbrvu",
"role": "USER",
},
{
"id": "cm2u6kgcc001aj7ja1stsbrvu",
"content": "You are a helpful assistant",
"createdAt": "2024-08-06T12:28:52.170Z",
"modelId": None,
"parentId": None,
"role": "SYSTEM",
},
],
"createdAt": "2024-08-06T12:30:42.122Z",
"isLatestLabelForUser": True,
"isSentBackToQueue": False,
"id": "clzief6q2003e7tc91jm46uii",
"jsonResponse": {},
"labelType": "AUTOSAVE",
"modelName": None,
}
],
"content": "",
"assetProjectModels": [
{
"id": "clzief6pr003c7tc99680e8yj",
"projectModelId": "ProjectModelA",
"configuration": {"temperature": 1, "model": "my-model-1"},
},
{
"id": "clzief6ps003d7tc9fzgj2xkf",
"projectModelId": "ProjectModelB",
"configuration": {"temperature": 0.5, "model": "my-model-2"},
},
],
"externalId": "clzief6pg003a7tc9cn0p1obf",
"jsonMetadata": {},
"status": "ONGOING",
}
]

expected_export_ongoing = [
{
"0": {
"raw_data": [
{
"id": "cm2u6kgcc001aj7ja1stsbrvu",
"role": "system",
"chat_id": "clzief6q2003e7tc91jm46uii",
"content": "You are a helpful assistant",
"model": None,
},
{
"content": "describe turtle in 100 words",
"role": "user",
"chat_id": "clzief6q2003e7tc91jm46uii",
"id": "clziefeh6003k7tc99abderkk",
"model": None,
},
],
"status": "ONGOING",
"external_id": "clzief6pg003a7tc9cn0p1obf",
"metadata": {},
"models": {
"A": {
"configuration": {
"model": "my-model-1",
"temperature": 1,
},
"id": "clzief6pr003c7tc99680e8yj",
"projectModelId": "ProjectModelA",
},
"B": {
"configuration": {
"model": "my-model-2",
"temperature": 0.5,
},
"id": "clzief6ps003d7tc9fzgj2xkf",
"projectModelId": "ProjectModelB",
},
},
"labels": [
{
"author": "[email protected]",
"created_at": "2024-08-06T12:30:42.122Z",
"label_type": "AUTOSAVE",
"label": {},
}
],
},
}
]


def test_export_dynamic(mocker):
get_project_return_val = {
Expand All @@ -471,6 +580,28 @@ def test_export_dynamic(mocker):
assert result == expected_export


def test_export_dynamic_ongoing(mocker):
get_project_return_val = {
"jsonInterface": mock_json_interface,
"inputType": "LLM_INSTR_FOLLOWING",
"title": "Test project",
"id": "project_id",
"dataConnections": None,
}
kili_api_gateway = mocker.MagicMock()
kili_api_gateway.count_assets.return_value = 3
kili_api_gateway.get_project.return_value = get_project_return_val
kili_api_gateway.list_assets.return_value = mock_fetch_assets_no_completions

kili_llm = LlmClientMethods(kili_api_gateway)

result = kili_llm.export(
project_id="project_id",
label_type_in=["DEFAULT", "REVIEW", "AUTOSAVE"],
)
assert result == expected_export_ongoing


def test_export_dynamic_empty_json_interface(mocker):
get_project_return_val = {
"jsonInterface": mock_empty_json_interface,
Expand Down

0 comments on commit 4fbe5b7

Please sign in to comment.