|
| 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 | + ) |
0 commit comments