# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations import httpx from ......_types import Body, Omit, Query, Headers, NotGiven, omit, not_given from ......_utils import path_template, maybe_transform, async_maybe_transform from ......_compat import cached_property from ......_resource import SyncAPIResource, AsyncAPIResource from ......_response import ( to_raw_response_wrapper, to_streamed_response_wrapper, async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) from ......_base_client import make_request_options from ......types.ai.tests.test_framework.v1 import result_list_params from ......types.ai.tests.test_framework.v1.test_run_result import TestRunResult from ......types.ai.tests.test_framework.v1.result_list_response import ResultListResponse __all__ = ["ResultsResource", "AsyncResultsResource"] class ResultsResource(SyncAPIResource): """ Test agents, evaluator scenarios, metrics, and run results for the AI test framework. """ @cached_property def with_raw_response(self) -> ResultsResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return ResultsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> ResultsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return ResultsResourceWithStreamingResponse(self) def retrieve( self, id: int, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> TestRunResult: """ Returns the specified test run batch, optionally with per-run detail. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return self._get( path_template("/ai/tests/test_framework/v1/results/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=TestRunResult, ) def list( self, *, agent_id: int | Omit = omit, page: int | Omit = omit, page_size: int | Omit = omit, scenarios: str | Omit = omit, search: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ResultListResponse: """ Returns a paginated list of test run batches in your organization, optionally filtered by test agent, search text, or scenarios. Args: agent_id: Filter results belonging to the specified test agent. page: Page number (1-based). page_size: Number of results per page. scenarios: Filter results by a comma-separated list of scenario IDs. search: Filter results by a search string. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return self._get( "/ai/tests/test_framework/v1/results", options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "agent_id": agent_id, "page": page, "page_size": page_size, "scenarios": scenarios, "search": search, }, result_list_params.ResultListParams, ), ), cast_to=ResultListResponse, ) def delete( self, id: int, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> object: """ Deletes the specified test run batch. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return self._delete( path_template("/ai/tests/test_framework/v1/results/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=object, ) def rerun( self, id: int, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> TestRunResult: """ Re-executes the scenarios of the specified test run batch and creates a new run batch. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return self._post( path_template("/ai/tests/test_framework/v1/results/{id}/rerun", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=TestRunResult, ) class AsyncResultsResource(AsyncAPIResource): """ Test agents, evaluator scenarios, metrics, and run results for the AI test framework. """ @cached_property def with_raw_response(self) -> AsyncResultsResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return AsyncResultsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncResultsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return AsyncResultsResourceWithStreamingResponse(self) async def retrieve( self, id: int, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> TestRunResult: """ Returns the specified test run batch, optionally with per-run detail. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return await self._get( path_template("/ai/tests/test_framework/v1/results/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=TestRunResult, ) async def list( self, *, agent_id: int | Omit = omit, page: int | Omit = omit, page_size: int | Omit = omit, scenarios: str | Omit = omit, search: str | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> ResultListResponse: """ Returns a paginated list of test run batches in your organization, optionally filtered by test agent, search text, or scenarios. Args: agent_id: Filter results belonging to the specified test agent. page: Page number (1-based). page_size: Number of results per page. scenarios: Filter results by a comma-separated list of scenario IDs. search: Filter results by a search string. extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return await self._get( "/ai/tests/test_framework/v1/results", options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=await async_maybe_transform( { "agent_id": agent_id, "page": page, "page_size": page_size, "scenarios": scenarios, "search": search, }, result_list_params.ResultListParams, ), ), cast_to=ResultListResponse, ) async def delete( self, id: int, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> object: """ Deletes the specified test run batch. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return await self._delete( path_template("/ai/tests/test_framework/v1/results/{id}", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=object, ) async def rerun( self, id: int, *, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> TestRunResult: """ Re-executes the scenarios of the specified test run batch and creates a new run batch. Args: extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return await self._post( path_template("/ai/tests/test_framework/v1/results/{id}/rerun", id=id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=TestRunResult, ) class ResultsResourceWithRawResponse: def __init__(self, results: ResultsResource) -> None: self._results = results self.retrieve = to_raw_response_wrapper( results.retrieve, ) self.list = to_raw_response_wrapper( results.list, ) self.delete = to_raw_response_wrapper( results.delete, ) self.rerun = to_raw_response_wrapper( results.rerun, ) class AsyncResultsResourceWithRawResponse: def __init__(self, results: AsyncResultsResource) -> None: self._results = results self.retrieve = async_to_raw_response_wrapper( results.retrieve, ) self.list = async_to_raw_response_wrapper( results.list, ) self.delete = async_to_raw_response_wrapper( results.delete, ) self.rerun = async_to_raw_response_wrapper( results.rerun, ) class ResultsResourceWithStreamingResponse: def __init__(self, results: ResultsResource) -> None: self._results = results self.retrieve = to_streamed_response_wrapper( results.retrieve, ) self.list = to_streamed_response_wrapper( results.list, ) self.delete = to_streamed_response_wrapper( results.delete, ) self.rerun = to_streamed_response_wrapper( results.rerun, ) class AsyncResultsResourceWithStreamingResponse: def __init__(self, results: AsyncResultsResource) -> None: self._results = results self.retrieve = async_to_streamed_response_wrapper( results.retrieve, ) self.list = async_to_streamed_response_wrapper( results.list, ) self.delete = async_to_streamed_response_wrapper( results.delete, ) self.rerun = async_to_streamed_response_wrapper( results.rerun, )