Save datapoints provided, after annotatation, for later retrieval. Args: data: JsonDict of datapoints to add, in dict under key 'inputs', per format for other requests. dataset_name: Dataset containing the format of data to add, necessary for proper datapoint annotat
(
self,
data: types.JsonDict,
dataset_name: Optional[str] = None,
**unused_kw
)
| 339 | return data['inputs'] # pytype: disable=bad-return-type # always-use-return-annotations |
| 340 | |
| 341 | def _post_new_data( |
| 342 | self, |
| 343 | data: types.JsonDict, |
| 344 | dataset_name: Optional[str] = None, |
| 345 | **unused_kw |
| 346 | ) -> dict[str, str]: |
| 347 | """Save datapoints provided, after annotatation, for later retrieval. |
| 348 | |
| 349 | Args: |
| 350 | data: JsonDict of datapoints to add, in dict under key 'inputs', per |
| 351 | format for other requests. |
| 352 | dataset_name: Dataset containing the format of data to add, necessary for |
| 353 | proper datapoint annotation. |
| 354 | |
| 355 | Returns: |
| 356 | A dict of two URLs (minus the root of the webserver). 'load' value is |
| 357 | for loading LIT with those datapoints. 'remove' value is for removing |
| 358 | those new datapoints from this server after they have been loaded, if |
| 359 | desired. |
| 360 | |
| 361 | Raises: |
| 362 | KeyError: If the `data` dictionary does not have an "inputs" field. |
| 363 | ValueError: If a "dataset_name" is not provided. |
| 364 | """ |
| 365 | if dataset_name is None: |
| 366 | raise ValueError('Must provide a "dataset_name" to save new datapoints.') |
| 367 | if 'inputs' not in data: |
| 368 | raise KeyError('Data dict does not contain "inputs" field.') |
| 369 | |
| 370 | data_with_metadata = [ |
| 371 | {'data': d, 'meta': {'added': True, 'source': 'POST', 'parentId': None}} |
| 372 | for d in data['inputs'] |
| 373 | ] |
| 374 | annotation_input = {'inputs': data_with_metadata} |
| 375 | annotated_data = self._annotate_new_data(annotation_input, dataset_name) |
| 376 | datapoints_id = utils.get_uuid() |
| 377 | with self._saved_datapoints_lock: |
| 378 | self._saved_datapoints[datapoints_id] = annotated_data |
| 379 | return { |
| 380 | 'load': f'?saved_datapoints_id={datapoints_id}', |
| 381 | 'remove': f'/remove_new_data?saved_datapoints_id={datapoints_id}', |
| 382 | } |
| 383 | |
| 384 | def _fetch_new_data( |
| 385 | self, unused_data, saved_datapoints_id: Optional[str] = None, **unused_kw |
nothing calls this directly
no test coverage detected