Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.2.0-alpha.14"
".": "0.2.0-alpha.15"
}
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
9 changes: 9 additions & 0 deletions src/openlayer/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/openlayer/_version.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions src/openlayer/lib/data/__init__.py
Original file line number Diff line number Diff line change
@@ -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
46 changes: 40 additions & 6 deletions src/openlayer/lib/data/batch_inferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import tempfile
import time
from typing import Optional
import httpx

import httpx
import pandas as pd

from ... import Openlayer
Expand All @@ -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"

Expand All @@ -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"
Expand All @@ -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(
Expand All @@ -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,
)