# 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.fine_tuning import job_create_params from ....types.ai.fine_tuning.fine_tuning_job import FineTuningJob from ....types.ai.fine_tuning.job_list_response import JobListResponse __all__ = ["JobsResource", "AsyncJobsResource"] class JobsResource(SyncAPIResource): """Customize LLMs for your unique needs""" @cached_property def with_raw_response(self) -> JobsResourceWithRawResponse: """ 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 JobsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> JobsResourceWithStreamingResponse: """ 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 JobsResourceWithStreamingResponse(self) def create( self, *, model: str, training_file: str, hyperparameters: job_create_params.Hyperparameters | Omit = omit, suffix: 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, ) -> FineTuningJob: """ Creates a new fine-tuning job that trains a model on the provided dataset, and returns the created job. Args: model: The base model that is being fine-tuned. training_file: The storage bucket or object used for training. hyperparameters: The hyperparameters used for the fine-tuning job. suffix: Optional suffix to append to the fine tuned model's name. 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( "/ai/fine_tuning/jobs", body=maybe_transform( { "model": model, "training_file": training_file, "hyperparameters": hyperparameters, "suffix": suffix, }, job_create_params.JobCreateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=FineTuningJob, ) def retrieve( self, job_id: str, *, # 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, ) -> FineTuningJob: """ Returns the details of a single fine-tuning job by its job_id, including its current status. 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 """ if not job_id: raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}") return self._get( path_template("/ai/fine_tuning/jobs/{job_id}", job_id=job_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=FineTuningJob, ) def list( self, *, # 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, ) -> JobListResponse: """Retrieve a list of all fine tuning jobs created by the user.""" return self._get( "/ai/fine_tuning/jobs", options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=JobListResponse, ) def cancel( self, job_id: str, *, # 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, ) -> FineTuningJob: """ Cancels the specified in-progress fine-tuning job and returns the updated job. 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 """ if not job_id: raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}") return self._post( path_template("/ai/fine_tuning/jobs/{job_id}/cancel", job_id=job_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=FineTuningJob, ) class AsyncJobsResource(AsyncAPIResource): """Customize LLMs for your unique needs""" @cached_property def with_raw_response(self) -> AsyncJobsResourceWithRawResponse: """ 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 AsyncJobsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncJobsResourceWithStreamingResponse: """ 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 AsyncJobsResourceWithStreamingResponse(self) async def create( self, *, model: str, training_file: str, hyperparameters: job_create_params.Hyperparameters | Omit = omit, suffix: 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, ) -> FineTuningJob: """ Creates a new fine-tuning job that trains a model on the provided dataset, and returns the created job. Args: model: The base model that is being fine-tuned. training_file: The storage bucket or object used for training. hyperparameters: The hyperparameters used for the fine-tuning job. suffix: Optional suffix to append to the fine tuned model's name. 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( "/ai/fine_tuning/jobs", body=await async_maybe_transform( { "model": model, "training_file": training_file, "hyperparameters": hyperparameters, "suffix": suffix, }, job_create_params.JobCreateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=FineTuningJob, ) async def retrieve( self, job_id: str, *, # 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, ) -> FineTuningJob: """ Returns the details of a single fine-tuning job by its job_id, including its current status. 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 """ if not job_id: raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}") return await self._get( path_template("/ai/fine_tuning/jobs/{job_id}", job_id=job_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=FineTuningJob, ) async def list( self, *, # 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, ) -> JobListResponse: """Retrieve a list of all fine tuning jobs created by the user.""" return await self._get( "/ai/fine_tuning/jobs", options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=JobListResponse, ) async def cancel( self, job_id: str, *, # 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, ) -> FineTuningJob: """ Cancels the specified in-progress fine-tuning job and returns the updated job. 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 """ if not job_id: raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}") return await self._post( path_template("/ai/fine_tuning/jobs/{job_id}/cancel", job_id=job_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=FineTuningJob, ) class JobsResourceWithRawResponse: def __init__(self, jobs: JobsResource) -> None: self._jobs = jobs self.create = to_raw_response_wrapper( jobs.create, ) self.retrieve = to_raw_response_wrapper( jobs.retrieve, ) self.list = to_raw_response_wrapper( jobs.list, ) self.cancel = to_raw_response_wrapper( jobs.cancel, ) class AsyncJobsResourceWithRawResponse: def __init__(self, jobs: AsyncJobsResource) -> None: self._jobs = jobs self.create = async_to_raw_response_wrapper( jobs.create, ) self.retrieve = async_to_raw_response_wrapper( jobs.retrieve, ) self.list = async_to_raw_response_wrapper( jobs.list, ) self.cancel = async_to_raw_response_wrapper( jobs.cancel, ) class JobsResourceWithStreamingResponse: def __init__(self, jobs: JobsResource) -> None: self._jobs = jobs self.create = to_streamed_response_wrapper( jobs.create, ) self.retrieve = to_streamed_response_wrapper( jobs.retrieve, ) self.list = to_streamed_response_wrapper( jobs.list, ) self.cancel = to_streamed_response_wrapper( jobs.cancel, ) class AsyncJobsResourceWithStreamingResponse: def __init__(self, jobs: AsyncJobsResource) -> None: self._jobs = jobs self.create = async_to_streamed_response_wrapper( jobs.create, ) self.retrieve = async_to_streamed_response_wrapper( jobs.retrieve, ) self.list = async_to_streamed_response_wrapper( jobs.list, ) self.cancel = async_to_streamed_response_wrapper( jobs.cancel, )