Skip to content

Commit e871096

Browse files
feat(api): add test evaluation method
1 parent f8b2fd2 commit e871096

File tree

9 files changed

+490
-3
lines changed

9 files changed

+490
-3
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
configured_endpoints: 18
1+
configured_endpoints: 19
22
openapi_spec_hash: 6a7cafc3d32e6701301e925175ab6614
3-
config_hash: 6dcf08c4324405f152d1da9fc11ab04a
3+
config_hash: 00442fdab71911b02ab1e10f9ec05b79

api.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,15 @@ from openlayer.types.storage import PresignedURLCreateResponse
138138
Methods:
139139

140140
- <code title="post /storage/presigned-url">client.storage.presigned_url.<a href="./src/openlayer/resources/storage/presigned_url.py">create</a>(\*\*<a href="src/openlayer/types/storage/presigned_url_create_params.py">params</a>) -> <a href="./src/openlayer/types/storage/presigned_url_create_response.py">PresignedURLCreateResponse</a></code>
141+
142+
# Tests
143+
144+
Types:
145+
146+
```python
147+
from openlayer.types import TestEvaluateResponse
148+
```
149+
150+
Methods:
151+
152+
- <code title="post /tests/{testId}/evaluate">client.tests.<a href="./src/openlayer/resources/tests.py">evaluate</a>(test_id, \*\*<a href="src/openlayer/types/test_evaluate_params.py">params</a>) -> <a href="./src/openlayer/types/test_evaluate_response.py">TestEvaluateResponse</a></code>

src/openlayer/_client.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
)
3333

3434
if TYPE_CHECKING:
35-
from .resources import commits, storage, projects, inference_pipelines
35+
from .resources import tests, commits, storage, projects, inference_pipelines
36+
from .resources.tests import TestsResource, AsyncTestsResource
3637
from .resources.commits.commits import CommitsResource, AsyncCommitsResource
3738
from .resources.storage.storage import StorageResource, AsyncStorageResource
3839
from .resources.projects.projects import ProjectsResource, AsyncProjectsResource
@@ -128,6 +129,12 @@ def storage(self) -> StorageResource:
128129

129130
return StorageResource(self)
130131

132+
@cached_property
133+
def tests(self) -> TestsResource:
134+
from .resources.tests import TestsResource
135+
136+
return TestsResource(self)
137+
131138
@cached_property
132139
def with_raw_response(self) -> OpenlayerWithRawResponse:
133140
return OpenlayerWithRawResponse(self)
@@ -329,6 +336,12 @@ def storage(self) -> AsyncStorageResource:
329336

330337
return AsyncStorageResource(self)
331338

339+
@cached_property
340+
def tests(self) -> AsyncTestsResource:
341+
from .resources.tests import AsyncTestsResource
342+
343+
return AsyncTestsResource(self)
344+
332345
@cached_property
333346
def with_raw_response(self) -> AsyncOpenlayerWithRawResponse:
334347
return AsyncOpenlayerWithRawResponse(self)
@@ -485,6 +498,12 @@ def storage(self) -> storage.StorageResourceWithRawResponse:
485498

486499
return StorageResourceWithRawResponse(self._client.storage)
487500

501+
@cached_property
502+
def tests(self) -> tests.TestsResourceWithRawResponse:
503+
from .resources.tests import TestsResourceWithRawResponse
504+
505+
return TestsResourceWithRawResponse(self._client.tests)
506+
488507

489508
class AsyncOpenlayerWithRawResponse:
490509
_client: AsyncOpenlayer
@@ -516,6 +535,12 @@ def storage(self) -> storage.AsyncStorageResourceWithRawResponse:
516535

517536
return AsyncStorageResourceWithRawResponse(self._client.storage)
518537

538+
@cached_property
539+
def tests(self) -> tests.AsyncTestsResourceWithRawResponse:
540+
from .resources.tests import AsyncTestsResourceWithRawResponse
541+
542+
return AsyncTestsResourceWithRawResponse(self._client.tests)
543+
519544

520545
class OpenlayerWithStreamedResponse:
521546
_client: Openlayer
@@ -547,6 +572,12 @@ def storage(self) -> storage.StorageResourceWithStreamingResponse:
547572

548573
return StorageResourceWithStreamingResponse(self._client.storage)
549574

575+
@cached_property
576+
def tests(self) -> tests.TestsResourceWithStreamingResponse:
577+
from .resources.tests import TestsResourceWithStreamingResponse
578+
579+
return TestsResourceWithStreamingResponse(self._client.tests)
580+
550581

551582
class AsyncOpenlayerWithStreamedResponse:
552583
_client: AsyncOpenlayer
@@ -578,6 +609,12 @@ def storage(self) -> storage.AsyncStorageResourceWithStreamingResponse:
578609

579610
return AsyncStorageResourceWithStreamingResponse(self._client.storage)
580611

612+
@cached_property
613+
def tests(self) -> tests.AsyncTestsResourceWithStreamingResponse:
614+
from .resources.tests import AsyncTestsResourceWithStreamingResponse
615+
616+
return AsyncTestsResourceWithStreamingResponse(self._client.tests)
617+
581618

582619
Client = Openlayer
583620

src/openlayer/resources/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3+
from .tests import (
4+
TestsResource,
5+
AsyncTestsResource,
6+
TestsResourceWithRawResponse,
7+
AsyncTestsResourceWithRawResponse,
8+
TestsResourceWithStreamingResponse,
9+
AsyncTestsResourceWithStreamingResponse,
10+
)
311
from .commits import (
412
CommitsResource,
513
AsyncCommitsResource,
@@ -58,4 +66,10 @@
5866
"AsyncStorageResourceWithRawResponse",
5967
"StorageResourceWithStreamingResponse",
6068
"AsyncStorageResourceWithStreamingResponse",
69+
"TestsResource",
70+
"AsyncTestsResource",
71+
"TestsResourceWithRawResponse",
72+
"AsyncTestsResourceWithRawResponse",
73+
"TestsResourceWithStreamingResponse",
74+
"AsyncTestsResourceWithStreamingResponse",
6175
]

src/openlayer/resources/tests.py

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
import httpx
6+
7+
from ..types import test_evaluate_params
8+
from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
9+
from .._utils import maybe_transform, async_maybe_transform
10+
from .._compat import cached_property
11+
from .._resource import SyncAPIResource, AsyncAPIResource
12+
from .._response import (
13+
to_raw_response_wrapper,
14+
to_streamed_response_wrapper,
15+
async_to_raw_response_wrapper,
16+
async_to_streamed_response_wrapper,
17+
)
18+
from .._base_client import make_request_options
19+
from ..types.test_evaluate_response import TestEvaluateResponse
20+
21+
__all__ = ["TestsResource", "AsyncTestsResource"]
22+
23+
24+
class TestsResource(SyncAPIResource):
25+
__test__ = False
26+
27+
@cached_property
28+
def with_raw_response(self) -> TestsResourceWithRawResponse:
29+
"""
30+
This property can be used as a prefix for any HTTP method call to return
31+
the raw response object instead of the parsed content.
32+
33+
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers
34+
"""
35+
return TestsResourceWithRawResponse(self)
36+
37+
@cached_property
38+
def with_streaming_response(self) -> TestsResourceWithStreamingResponse:
39+
"""
40+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
41+
42+
For more information, see https://www.github.com/openlayer-ai/openlayer-python#with_streaming_response
43+
"""
44+
return TestsResourceWithStreamingResponse(self)
45+
46+
def evaluate(
47+
self,
48+
test_id: str,
49+
*,
50+
end_timestamp: int,
51+
start_timestamp: int,
52+
inference_pipeline_id: str | Omit = omit,
53+
overwrite_results: bool | Omit = omit,
54+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
55+
# The extra values given here take precedence over values defined on the client or passed to this method.
56+
extra_headers: Headers | None = None,
57+
extra_query: Query | None = None,
58+
extra_body: Body | None = None,
59+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
60+
) -> TestEvaluateResponse:
61+
"""
62+
Triggers one-off evaluation of a specific monitoring test for a custom timestamp
63+
range. This allows evaluating tests for historical data or custom time periods
64+
outside the regular evaluation window schedule. It also allows overwriting the
65+
existing test results.
66+
67+
Args:
68+
end_timestamp: End timestamp in seconds (Unix epoch)
69+
70+
start_timestamp: Start timestamp in seconds (Unix epoch)
71+
72+
inference_pipeline_id: ID of the inference pipeline to evaluate. If not provided, all inference
73+
pipelines the test applies to will be evaluated.
74+
75+
overwrite_results: Whether to overwrite existing test results
76+
77+
extra_headers: Send extra headers
78+
79+
extra_query: Add additional query parameters to the request
80+
81+
extra_body: Add additional JSON properties to the request
82+
83+
timeout: Override the client-level default timeout for this request, in seconds
84+
"""
85+
if not test_id:
86+
raise ValueError(f"Expected a non-empty value for `test_id` but received {test_id!r}")
87+
return self._post(
88+
f"/tests/{test_id}/evaluate",
89+
body=maybe_transform(
90+
{
91+
"end_timestamp": end_timestamp,
92+
"start_timestamp": start_timestamp,
93+
"inference_pipeline_id": inference_pipeline_id,
94+
"overwrite_results": overwrite_results,
95+
},
96+
test_evaluate_params.TestEvaluateParams,
97+
),
98+
options=make_request_options(
99+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
100+
),
101+
cast_to=TestEvaluateResponse,
102+
)
103+
104+
105+
class AsyncTestsResource(AsyncAPIResource):
106+
@cached_property
107+
def with_raw_response(self) -> AsyncTestsResourceWithRawResponse:
108+
"""
109+
This property can be used as a prefix for any HTTP method call to return
110+
the raw response object instead of the parsed content.
111+
112+
For more information, see https://www.github.com/openlayer-ai/openlayer-python#accessing-raw-response-data-eg-headers
113+
"""
114+
return AsyncTestsResourceWithRawResponse(self)
115+
116+
@cached_property
117+
def with_streaming_response(self) -> AsyncTestsResourceWithStreamingResponse:
118+
"""
119+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
120+
121+
For more information, see https://www.github.com/openlayer-ai/openlayer-python#with_streaming_response
122+
"""
123+
return AsyncTestsResourceWithStreamingResponse(self)
124+
125+
async def evaluate(
126+
self,
127+
test_id: str,
128+
*,
129+
end_timestamp: int,
130+
start_timestamp: int,
131+
inference_pipeline_id: str | Omit = omit,
132+
overwrite_results: bool | Omit = omit,
133+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
134+
# The extra values given here take precedence over values defined on the client or passed to this method.
135+
extra_headers: Headers | None = None,
136+
extra_query: Query | None = None,
137+
extra_body: Body | None = None,
138+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
139+
) -> TestEvaluateResponse:
140+
"""
141+
Triggers one-off evaluation of a specific monitoring test for a custom timestamp
142+
range. This allows evaluating tests for historical data or custom time periods
143+
outside the regular evaluation window schedule. It also allows overwriting the
144+
existing test results.
145+
146+
Args:
147+
end_timestamp: End timestamp in seconds (Unix epoch)
148+
149+
start_timestamp: Start timestamp in seconds (Unix epoch)
150+
151+
inference_pipeline_id: ID of the inference pipeline to evaluate. If not provided, all inference
152+
pipelines the test applies to will be evaluated.
153+
154+
overwrite_results: Whether to overwrite existing test results
155+
156+
extra_headers: Send extra headers
157+
158+
extra_query: Add additional query parameters to the request
159+
160+
extra_body: Add additional JSON properties to the request
161+
162+
timeout: Override the client-level default timeout for this request, in seconds
163+
"""
164+
if not test_id:
165+
raise ValueError(f"Expected a non-empty value for `test_id` but received {test_id!r}")
166+
return await self._post(
167+
f"/tests/{test_id}/evaluate",
168+
body=await async_maybe_transform(
169+
{
170+
"end_timestamp": end_timestamp,
171+
"start_timestamp": start_timestamp,
172+
"inference_pipeline_id": inference_pipeline_id,
173+
"overwrite_results": overwrite_results,
174+
},
175+
test_evaluate_params.TestEvaluateParams,
176+
),
177+
options=make_request_options(
178+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
179+
),
180+
cast_to=TestEvaluateResponse,
181+
)
182+
183+
184+
class TestsResourceWithRawResponse:
185+
__test__ = False
186+
187+
def __init__(self, tests: TestsResource) -> None:
188+
self._tests = tests
189+
190+
self.evaluate = to_raw_response_wrapper(
191+
tests.evaluate,
192+
)
193+
194+
195+
class AsyncTestsResourceWithRawResponse:
196+
def __init__(self, tests: AsyncTestsResource) -> None:
197+
self._tests = tests
198+
199+
self.evaluate = async_to_raw_response_wrapper(
200+
tests.evaluate,
201+
)
202+
203+
204+
class TestsResourceWithStreamingResponse:
205+
__test__ = False
206+
207+
def __init__(self, tests: TestsResource) -> None:
208+
self._tests = tests
209+
210+
self.evaluate = to_streamed_response_wrapper(
211+
tests.evaluate,
212+
)
213+
214+
215+
class AsyncTestsResourceWithStreamingResponse:
216+
def __init__(self, tests: AsyncTestsResource) -> None:
217+
self._tests = tests
218+
219+
self.evaluate = async_to_streamed_response_wrapper(
220+
tests.evaluate,
221+
)

src/openlayer/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from __future__ import annotations
44

55
from .project_list_params import ProjectListParams as ProjectListParams
6+
from .test_evaluate_params import TestEvaluateParams as TestEvaluateParams
67
from .project_create_params import ProjectCreateParams as ProjectCreateParams
78
from .project_list_response import ProjectListResponse as ProjectListResponse
9+
from .test_evaluate_response import TestEvaluateResponse as TestEvaluateResponse
810
from .project_create_response import ProjectCreateResponse as ProjectCreateResponse
911
from .commit_retrieve_response import CommitRetrieveResponse as CommitRetrieveResponse
1012
from .inference_pipeline_update_params import InferencePipelineUpdateParams as InferencePipelineUpdateParams
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Required, Annotated, TypedDict
6+
7+
from .._utils import PropertyInfo
8+
9+
__all__ = ["TestEvaluateParams"]
10+
11+
12+
class TestEvaluateParams(TypedDict, total=False):
13+
end_timestamp: Required[Annotated[int, PropertyInfo(alias="endTimestamp")]]
14+
"""End timestamp in seconds (Unix epoch)"""
15+
16+
start_timestamp: Required[Annotated[int, PropertyInfo(alias="startTimestamp")]]
17+
"""Start timestamp in seconds (Unix epoch)"""
18+
19+
inference_pipeline_id: Annotated[str, PropertyInfo(alias="inferencePipelineId")]
20+
"""ID of the inference pipeline to evaluate.
21+
22+
If not provided, all inference pipelines the test applies to will be evaluated.
23+
"""
24+
25+
overwrite_results: Annotated[bool, PropertyInfo(alias="overwriteResults")]
26+
"""Whether to overwrite existing test results"""

0 commit comments

Comments
 (0)