@@ -39,14 +39,39 @@ def save(self):
3939 raise NotImplementedError
4040
4141 def get_component_value (self , component_id : str ):
42- if component_id in self .annotation ["data" ]:
43- return self .annotation ["data" ][component_id ]["value" ]
42+ component_data = self .annotation .get ("data" , {}).get (component_id )
43+ if isinstance (component_data , dict ):
44+ return component_data .get ("value" )
45+ elif isinstance (component_data , list ):
46+ # Find the dict with the smallest element_path
47+ annotation = min (
48+ (elem for elem in component_data if isinstance (elem , dict ) and "element_path" in elem ),
49+ key = lambda x : x ["element_path" ],
50+ default = None
51+ )
52+ if annotation is not None :
53+ return annotation .get ("value" )
4454 return None
4555
56+
4657 def set_component_value (self , component_id : str , value : Any ):
47- self .annotation .setdefault ("data" , {}).setdefault (component_id , {})[
48- "value"
49- ] = value
58+ data = self .annotation .setdefault ("data" , {})
59+ component_data = data .get (component_id )
60+
61+ if component_data is None :
62+ data [component_id ] = [{"value" : value }]
63+ elif isinstance (component_data , dict ):
64+ component_data ["value" ] = value
65+ elif isinstance (component_data , list ):
66+ # Find the dict with the smallest element_path
67+ annotation = min (
68+ (elem for elem in component_data if isinstance (elem , dict ) and "element_path" in elem ),
69+ key = lambda x : x ["element_path" ],
70+ default = None
71+ )
72+ if annotation is not None :
73+ annotation ["value" ] = value
74+
5075 return self
5176
5277
@@ -71,7 +96,7 @@ def annotation(self) -> dict:
7196 project = self ._project ,
7297 folder = self ._folder ,
7398 item_id = self ._item .id ,
74- transform_version = "llmJsonV2 " ,
99+ transform_version = "llmJsonV3 " ,
75100 )
76101 if not response or response .status_code == 404 :
77102 self ._annotation = {
@@ -88,7 +113,7 @@ def save(self):
88113 project = self ._project ,
89114 folder = self ._folder ,
90115 item_id = self ._item .id ,
91- transform_version = "llmJsonV2 " ,
116+ transform_version = "llmJsonV3 " ,
92117 data = self .annotation ,
93118 overwrite = self ._overwrite ,
94119 etag = self ._etag ,
@@ -104,7 +129,7 @@ def annotation(self) -> dict:
104129 project = self ._project ,
105130 item = self ._item ,
106131 reporter = self ._controller .reporter ,
107- transform_version = "llmJsonV2 " ,
132+ transform_version = "llmJsonV3 " ,
108133 )
109134 )
110135 return self ._annotation
@@ -117,6 +142,6 @@ def save(self):
117142 item_id = self ._item .id ,
118143 data = StringIO (json .dumps (self ._annotation )),
119144 chunk_size = 5 * 1024 * 1024 ,
120- transform_version = "llmJsonV2 " ,
145+ transform_version = "llmJsonV3 " ,
121146 )
122147 )
0 commit comments