Skip to content

release: 0.2.0-alpha.61 #463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2025
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.60"
".": "0.2.0-alpha.61"
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 0.2.0-alpha.61 (2025-04-25)

Full Changelog: [v0.2.0-alpha.60...v0.2.0-alpha.61](https://github.com/openlayer-ai/openlayer-python/compare/v0.2.0-alpha.60...v0.2.0-alpha.61)

### Features

* feat: add convenience function that copies tests from one project to another ([d59dfe0](https://github.com/openlayer-ai/openlayer-python/commit/d59dfe023b6d6e164c6e272cc410dc6b5f4bcec8))

## 0.2.0-alpha.60 (2025-04-25)

Full Changelog: [v0.2.0-alpha.59...v0.2.0-alpha.60](https://github.com/openlayer-ai/openlayer-python/compare/v0.2.0-alpha.59...v0.2.0-alpha.60)
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.60"
version = "0.2.0-alpha.61"
description = "The official Python library for the openlayer API"
dynamic = ["readme"]
license = "Apache-2.0"
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.60" # x-release-please-version
__version__ = "0.2.0-alpha.61" # x-release-please-version
76 changes: 76 additions & 0 deletions src/openlayer/lib/core/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""Module containing convenience functions for the tests API."""

from typing import Optional, List
from openlayer import Openlayer


def copy_tests(
client: Openlayer,
origin_project_id: str,
target_project_id: str,
verbose: bool = False,
test_ids: Optional[List[str]] = None,
) -> None:
"""Copy tests from one project to another.

Args:
client (Openlayer): The Openlayer client.
origin_project_id (str): The ID of the origin project (where the tests
are).
target_project_id (str): The ID of the target project (where the tests
will be copied to).
verbose (bool): Whether to print verbose output.
test_ids (List[str]): The IDs of the tests to copy. If not provided, all
tests will be copied.
"""
tests = client.projects.tests.list(project_id=origin_project_id)

if test_ids is None and verbose:
print("Copying all tests from the origin project to the target project.")
else:
print(
"Copying the following tests from the origin project to"
f" the target project: {test_ids}"
)

for test in tests.items:
if test.id in test_ids:
thresholds = _parse_thresholds(test.thresholds)
client.projects.tests.create(
project_id=target_project_id,
name=test.name,
description=test.description,
type=test.type,
subtype=test.subtype,
thresholds=thresholds,
uses_production_data=test.uses_production_data,
evaluation_window=test.evaluation_window,
delay_window=test.delay_window,
uses_training_dataset=test.uses_training_dataset,
uses_validation_dataset=test.uses_validation_dataset,
uses_ml_model=test.uses_ml_model,
)
if verbose:
print(
f"Copied test '{test.id}' - '{test.name}' from the"
" origin project to the target project."
)


def _parse_thresholds(thresholds: List[dict]) -> List[dict]:
"""Parse the thresholds from the test to the format required by the create
test endpoint."""
thresholds = []
for threshold in thresholds:
current_threshold = {
"insightName": threshold.insight_name,
"measurement": threshold.measurement,
"operator": threshold.operator,
"value": threshold.value,
}

if threshold.get("insightParameters"):
current_threshold["insightParameters"] = threshold["insightParameters"]
thresholds.append(current_threshold)

return thresholds