diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 929f7775..a72db4d7 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.2.0-alpha.14" + ".": "0.2.0-alpha.15" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a999c6a..cf1967af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Removed * Deprecated and removed `publish_ground_truths` method. Use `update_data` instead. +## 0.2.0-alpha.15 (2024-07-31) + +Full Changelog: [v0.2.0-alpha.14...v0.2.0-alpha.15](https://github.com/openlayer-ai/openlayer-python/compare/v0.2.0-alpha.14...v0.2.0-alpha.15) + +### Features + +* improvement: allow specifying dataset as path for uploads ([a4d126f](https://github.com/openlayer-ai/openlayer-python/commit/a4d126f2c0b3bdf67fefbb06fb3ffa9107ea1387)) +* improvement: include method to update batch of inferences ([a8f3d82](https://github.com/openlayer-ai/openlayer-python/commit/a8f3d8246c75ff8ebff8f5e92212044fd3433d47)) + + +### Chores + +* **internal:** add type construction helper ([#287](https://github.com/openlayer-ai/openlayer-python/issues/287)) ([39fbda1](https://github.com/openlayer-ai/openlayer-python/commit/39fbda1bcaacbd8546926e7d32b7fc2ae1ad058e)) +* **internal:** version bump ([#284](https://github.com/openlayer-ai/openlayer-python/issues/284)) ([73c3067](https://github.com/openlayer-ai/openlayer-python/commit/73c30676b1e49e2355cffd232305c5aab1a0b309)) +* **tests:** update prism version ([#285](https://github.com/openlayer-ai/openlayer-python/issues/285)) ([3c0fcbb](https://github.com/openlayer-ai/openlayer-python/commit/3c0fcbbe9199b68ef5bc92247df751bfd4ae3649)) + ## 0.2.0-alpha.14 (2024-07-29) Full Changelog: [v0.2.0-alpha.13...v0.2.0-alpha.14](https://github.com/openlayer-ai/openlayer-python/compare/v0.2.0-alpha.13...v0.2.0-alpha.14) diff --git a/pyproject.toml b/pyproject.toml index 1f142618..18050322 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openlayer" -version = "0.2.0-alpha.14" +version = "0.2.0-alpha.15" description = "The official Python library for the openlayer API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/src/openlayer/_models.py b/src/openlayer/_models.py index eb7ce3bd..5148d5a7 100644 --- a/src/openlayer/_models.py +++ b/src/openlayer/_models.py @@ -406,6 +406,15 @@ def build( return cast(_BaseModelT, construct_type(type_=base_model_cls, value=kwargs)) +def construct_type_unchecked(*, value: object, type_: type[_T]) -> _T: + """Loose coercion to the expected type with construction of nested values. + + Note: the returned value from this function is not guaranteed to match the + given type. + """ + return cast(_T, construct_type(value=value, type_=type_)) + + def construct_type(*, value: object, type_: object) -> object: """Loose coercion to the expected type with construction of nested values. diff --git a/src/openlayer/_version.py b/src/openlayer/_version.py index 4e11865a..b6450f0c 100644 --- a/src/openlayer/_version.py +++ b/src/openlayer/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "openlayer" -__version__ = "0.2.0-alpha.14" # x-release-please-version +__version__ = "0.2.0-alpha.15" # x-release-please-version diff --git a/src/openlayer/lib/data/__init__.py b/src/openlayer/lib/data/__init__.py index 4df22112..89cdc091 100644 --- a/src/openlayer/lib/data/__init__.py +++ b/src/openlayer/lib/data/__init__.py @@ -1,7 +1,12 @@ """Data upload functions.""" -__all__ = ["StorageType", "upload_reference_dataframe", "upload_batch_inferences"] +__all__ = [ + "StorageType", + "upload_reference_dataframe", + "upload_batch_inferences", + "update_batch_inferences", +] from ._upload import StorageType +from .batch_inferences import update_batch_inferences, upload_batch_inferences from .reference_dataset import upload_reference_dataframe -from .batch_inferences import upload_batch_inferences diff --git a/src/openlayer/lib/data/batch_inferences.py b/src/openlayer/lib/data/batch_inferences.py index 99699c14..f796a466 100644 --- a/src/openlayer/lib/data/batch_inferences.py +++ b/src/openlayer/lib/data/batch_inferences.py @@ -5,8 +5,8 @@ import tempfile import time from typing import Optional -import httpx +import httpx import pandas as pd from ... import Openlayer @@ -19,11 +19,18 @@ def upload_batch_inferences( client: Openlayer, inference_pipeline_id: str, - dataset_df: pd.DataFrame, config: data_stream_params.Config, + dataset_df: Optional[pd.DataFrame] = None, + dataset_path: Optional[str] = None, storage_type: Optional[StorageType] = None, + merge: bool = False, ) -> None: """Uploads a batch of inferences to the Openlayer platform.""" + if dataset_df is None and dataset_path is None: + raise ValueError("Either dataset_df or dataset_path must be provided.") + if dataset_df is not None and dataset_path is not None: + raise ValueError("Only one of dataset_df or dataset_path should be provided.") + uploader = _upload.Uploader(client, storage_type) object_name = f"batch_data_{time.time()}_{inference_pipeline_id}.tar.gz" @@ -34,8 +41,11 @@ def upload_batch_inferences( # Write dataset and config to temp directory with tempfile.TemporaryDirectory() as tmp_dir: - temp_file_path = f"{tmp_dir}/dataset.csv" - dataset_df.to_csv(temp_file_path, index=False) + if dataset_df is not None: + temp_file_path = f"{tmp_dir}/dataset.csv" + dataset_df.to_csv(temp_file_path, index=False) + else: + temp_file_path = dataset_path # Copy relevant files to tmp dir config["label"] = "production" @@ -46,7 +56,11 @@ def upload_batch_inferences( tar_file_path = os.path.join(tmp_dir, object_name) with tarfile.open(tar_file_path, mode="w:gz") as tar: - tar.add(tmp_dir, arcname=os.path.basename("monitoring_data")) + tar.add(temp_file_path, arcname=os.path.basename("dataset.csv")) + tar.add( + f"{tmp_dir}/dataset_config.yaml", + arcname=os.path.basename("dataset_config.yaml"), + ) # Upload to storage uploader.upload( @@ -61,6 +75,26 @@ def upload_batch_inferences( cast_to=httpx.Response, body={ "storageUri": presigned_url_response.storage_uri, - "performDataMerge": False, + "performDataMerge": merge, }, ) + + +def update_batch_inferences( + client: Openlayer, + inference_pipeline_id: str, + dataset_df: pd.DataFrame, + config: data_stream_params.Config, + storage_type: Optional[StorageType] = None, +) -> None: + """Updates a batch of inferences on the Openlayer platform.""" + if config["inference_id_column_name"] is None: + raise ValueError("inference_id_column_name must be set in config") + upload_batch_inferences( + client=client, + inference_pipeline_id=inference_pipeline_id, + dataset_df=dataset_df, + config=config, + storage_type=storage_type, + merge=True, + )