33import json
44import logging
55from pathlib import Path
6- from typing import Dict , List , Union
6+ from typing import Dict , List , Optional , Union
77
88from kili .services .export .exceptions import NotCompatibleInputType
99from kili .services .export .format .base import AbstractExporter
@@ -25,8 +25,6 @@ def _check_project_compatibility(self) -> None:
2525 f"Project with input type \" { self .project ['inputType' ]} \" not compatible with LLM"
2626 " export format."
2727 )
28- if not self .single_file :
29- raise ValueError ("LLM export are always single file." )
3028
3129 def _is_job_compatible (self , job : Job ) -> bool :
3230 """Check job compatibility with the LLM format."""
@@ -41,23 +39,41 @@ def _save_assets_export(self, assets: List[Dict], output_filename: Path) -> None
4139 with output_filename .open ("wb" ) as output_file :
4240 output_file .write (export_json .encode ("utf-8" ))
4341
44- def process_and_save (self , assets : List [Dict ], output_filename : Path ) -> None :
42+ def process_and_save (
43+ self , assets : List [Dict ], output_filename : Path
44+ ) -> Optional [List [Dict [str , Union [List [str ], str ]]]]:
4545 """LLM specific process and save."""
46+ result = self ._process (assets )
47+ self ._save_assets_export (result , output_filename )
48+
49+ def process (self , assets : List [Dict ]) -> List [Dict [str , Union [List [str ], str ]]]:
50+ """LLM specific process."""
51+ return self ._process (assets )
52+
53+ def _process (self , assets : List [Dict ]) -> List [Dict [str , Union [List [str ], str ]]]:
4654 result = []
4755 for asset in assets :
4856 jobs_config = self .project ["jsonInterface" ]["jobs" ]
49- json_response = asset ["latestLabel" ][ "jsonResponse " ]
57+ latest_label = asset ["latestLabel" ]
5058 result .append (
5159 {
5260 "raw_data" : _format_raw_data (asset ),
5361 "status" : asset ["status" ],
5462 "external_id" : asset ["externalId" ],
5563 "metadata" : asset ["jsonMetadata" ],
56- "labels" : [_format_json_response (jobs_config , json_response )],
64+ "labels" : [
65+ {
66+ "author" : latest_label ["author" ]["email" ],
67+ "created_at" : latest_label ["createdAt" ],
68+ "label_type" : latest_label ["labelType" ],
69+ "label" : _format_json_response (
70+ jobs_config , latest_label ["jsonResponse" ]
71+ ),
72+ }
73+ ],
5774 }
5875 )
59-
60- self ._save_assets_export (result , output_filename )
76+ return result
6177
6278
6379def _format_json_response (
0 commit comments