diff --git a/api.md b/api.md index 24e491a6..4276bab7 100644 --- a/api.md +++ b/api.md @@ -16,11 +16,12 @@ Methods: Types: ```python -from openlayer.types.projects import CommitListResponse +from openlayer.types.projects import CommitCreateResponse, CommitListResponse ``` Methods: +- client.projects.commits.create(project_id, \*\*params) -> CommitCreateResponse - client.projects.commits.list(project_id, \*\*params) -> CommitListResponse ## InferencePipelines @@ -38,16 +39,6 @@ Methods: # Commits -Types: - -```python -from openlayer.types import CommitCreateResponse -``` - -Methods: - -- client.commits.create(project_id, \*\*params) -> CommitCreateResponse - ## TestResults Types: diff --git a/src/openlayer/resources/commits/commits.py b/src/openlayer/resources/commits/commits.py index 774ae94f..b5382274 100644 --- a/src/openlayer/resources/commits/commits.py +++ b/src/openlayer/resources/commits/commits.py @@ -2,24 +2,8 @@ from __future__ import annotations -from typing import Optional - -import httpx - -from ...types import commit_create_params -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven -from ..._utils import ( - 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 .test_results import ( TestResultsResource, AsyncTestResultsResource, @@ -28,8 +12,6 @@ TestResultsResourceWithStreamingResponse, AsyncTestResultsResourceWithStreamingResponse, ) -from ..._base_client import make_request_options -from ...types.commit_create_response import CommitCreateResponse __all__ = ["CommitsResource", "AsyncCommitsResource"] @@ -58,60 +40,6 @@ def with_streaming_response(self) -> CommitsResourceWithStreamingResponse: """ return CommitsResourceWithStreamingResponse(self) - def create( - self, - project_id: str, - *, - commit: commit_create_params.Commit, - storage_uri: str, - archived: Optional[bool] | NotGiven = NOT_GIVEN, - deployment_status: str | NotGiven = NOT_GIVEN, - # 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, - ) -> CommitCreateResponse: - """ - Create a new commit (project version) in a project. - - Args: - commit: The details of a commit (project version). - - storage_uri: The storage URI where the commit bundle is stored. - - archived: Whether the commit is archived. - - deployment_status: The deployment status associated with the commit's model. - - 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 project_id: - raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") - return self._post( - f"/projects/{project_id}/versions", - body=maybe_transform( - { - "commit": commit, - "storage_uri": storage_uri, - "archived": archived, - "deployment_status": deployment_status, - }, - commit_create_params.CommitCreateParams, - ), - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=CommitCreateResponse, - ) - class AsyncCommitsResource(AsyncAPIResource): @cached_property @@ -137,69 +65,11 @@ def with_streaming_response(self) -> AsyncCommitsResourceWithStreamingResponse: """ return AsyncCommitsResourceWithStreamingResponse(self) - async def create( - self, - project_id: str, - *, - commit: commit_create_params.Commit, - storage_uri: str, - archived: Optional[bool] | NotGiven = NOT_GIVEN, - deployment_status: str | NotGiven = NOT_GIVEN, - # 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, - ) -> CommitCreateResponse: - """ - Create a new commit (project version) in a project. - - Args: - commit: The details of a commit (project version). - - storage_uri: The storage URI where the commit bundle is stored. - - archived: Whether the commit is archived. - - deployment_status: The deployment status associated with the commit's model. - - 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 project_id: - raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") - return await self._post( - f"/projects/{project_id}/versions", - body=await async_maybe_transform( - { - "commit": commit, - "storage_uri": storage_uri, - "archived": archived, - "deployment_status": deployment_status, - }, - commit_create_params.CommitCreateParams, - ), - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=CommitCreateResponse, - ) - class CommitsResourceWithRawResponse: def __init__(self, commits: CommitsResource) -> None: self._commits = commits - self.create = to_raw_response_wrapper( - commits.create, - ) - @cached_property def test_results(self) -> TestResultsResourceWithRawResponse: return TestResultsResourceWithRawResponse(self._commits.test_results) @@ -209,10 +79,6 @@ class AsyncCommitsResourceWithRawResponse: def __init__(self, commits: AsyncCommitsResource) -> None: self._commits = commits - self.create = async_to_raw_response_wrapper( - commits.create, - ) - @cached_property def test_results(self) -> AsyncTestResultsResourceWithRawResponse: return AsyncTestResultsResourceWithRawResponse(self._commits.test_results) @@ -222,10 +88,6 @@ class CommitsResourceWithStreamingResponse: def __init__(self, commits: CommitsResource) -> None: self._commits = commits - self.create = to_streamed_response_wrapper( - commits.create, - ) - @cached_property def test_results(self) -> TestResultsResourceWithStreamingResponse: return TestResultsResourceWithStreamingResponse(self._commits.test_results) @@ -235,10 +97,6 @@ class AsyncCommitsResourceWithStreamingResponse: def __init__(self, commits: AsyncCommitsResource) -> None: self._commits = commits - self.create = async_to_streamed_response_wrapper( - commits.create, - ) - @cached_property def test_results(self) -> AsyncTestResultsResourceWithStreamingResponse: return AsyncTestResultsResourceWithStreamingResponse(self._commits.test_results) diff --git a/src/openlayer/resources/projects/commits.py b/src/openlayer/resources/projects/commits.py index fd16de8f..9bba5fb8 100644 --- a/src/openlayer/resources/projects/commits.py +++ b/src/openlayer/resources/projects/commits.py @@ -2,6 +2,8 @@ from __future__ import annotations +from typing import Optional + import httpx from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven @@ -18,8 +20,9 @@ async_to_streamed_response_wrapper, ) from ..._base_client import make_request_options -from ...types.projects import commit_list_params +from ...types.projects import commit_list_params, commit_create_params from ...types.projects.commit_list_response import CommitListResponse +from ...types.projects.commit_create_response import CommitCreateResponse __all__ = ["CommitsResource", "AsyncCommitsResource"] @@ -44,6 +47,60 @@ def with_streaming_response(self) -> CommitsResourceWithStreamingResponse: """ return CommitsResourceWithStreamingResponse(self) + def create( + self, + project_id: str, + *, + commit: commit_create_params.Commit, + storage_uri: str, + archived: Optional[bool] | NotGiven = NOT_GIVEN, + deployment_status: str | NotGiven = NOT_GIVEN, + # 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, + ) -> CommitCreateResponse: + """ + Create a new commit (project version) in a project. + + Args: + commit: The details of a commit (project version). + + storage_uri: The storage URI where the commit bundle is stored. + + archived: Whether the commit is archived. + + deployment_status: The deployment status associated with the commit's model. + + 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 project_id: + raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") + return self._post( + f"/projects/{project_id}/versions", + body=maybe_transform( + { + "commit": commit, + "storage_uri": storage_uri, + "archived": archived, + "deployment_status": deployment_status, + }, + commit_create_params.CommitCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=CommitCreateResponse, + ) + def list( self, project_id: str, @@ -114,6 +171,60 @@ def with_streaming_response(self) -> AsyncCommitsResourceWithStreamingResponse: """ return AsyncCommitsResourceWithStreamingResponse(self) + async def create( + self, + project_id: str, + *, + commit: commit_create_params.Commit, + storage_uri: str, + archived: Optional[bool] | NotGiven = NOT_GIVEN, + deployment_status: str | NotGiven = NOT_GIVEN, + # 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, + ) -> CommitCreateResponse: + """ + Create a new commit (project version) in a project. + + Args: + commit: The details of a commit (project version). + + storage_uri: The storage URI where the commit bundle is stored. + + archived: Whether the commit is archived. + + deployment_status: The deployment status associated with the commit's model. + + 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 project_id: + raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") + return await self._post( + f"/projects/{project_id}/versions", + body=await async_maybe_transform( + { + "commit": commit, + "storage_uri": storage_uri, + "archived": archived, + "deployment_status": deployment_status, + }, + commit_create_params.CommitCreateParams, + ), + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=CommitCreateResponse, + ) + async def list( self, project_id: str, @@ -168,6 +279,9 @@ class CommitsResourceWithRawResponse: def __init__(self, commits: CommitsResource) -> None: self._commits = commits + self.create = to_raw_response_wrapper( + commits.create, + ) self.list = to_raw_response_wrapper( commits.list, ) @@ -177,6 +291,9 @@ class AsyncCommitsResourceWithRawResponse: def __init__(self, commits: AsyncCommitsResource) -> None: self._commits = commits + self.create = async_to_raw_response_wrapper( + commits.create, + ) self.list = async_to_raw_response_wrapper( commits.list, ) @@ -186,6 +303,9 @@ class CommitsResourceWithStreamingResponse: def __init__(self, commits: CommitsResource) -> None: self._commits = commits + self.create = to_streamed_response_wrapper( + commits.create, + ) self.list = to_streamed_response_wrapper( commits.list, ) @@ -195,6 +315,9 @@ class AsyncCommitsResourceWithStreamingResponse: def __init__(self, commits: AsyncCommitsResource) -> None: self._commits = commits + self.create = async_to_streamed_response_wrapper( + commits.create, + ) self.list = async_to_streamed_response_wrapper( commits.list, ) diff --git a/src/openlayer/types/__init__.py b/src/openlayer/types/__init__.py index 48381166..58883aff 100644 --- a/src/openlayer/types/__init__.py +++ b/src/openlayer/types/__init__.py @@ -3,10 +3,8 @@ from __future__ import annotations from .project_list_params import ProjectListParams as ProjectListParams -from .commit_create_params import CommitCreateParams as CommitCreateParams from .project_create_params import ProjectCreateParams as ProjectCreateParams from .project_list_response import ProjectListResponse as ProjectListResponse -from .commit_create_response import CommitCreateResponse as CommitCreateResponse from .project_create_response import ProjectCreateResponse as ProjectCreateResponse from .inference_pipeline_update_params import InferencePipelineUpdateParams as InferencePipelineUpdateParams from .inference_pipeline_update_response import InferencePipelineUpdateResponse as InferencePipelineUpdateResponse diff --git a/src/openlayer/types/projects/__init__.py b/src/openlayer/types/projects/__init__.py index 269c9127..d8b9520e 100644 --- a/src/openlayer/types/projects/__init__.py +++ b/src/openlayer/types/projects/__init__.py @@ -3,7 +3,9 @@ from __future__ import annotations from .commit_list_params import CommitListParams as CommitListParams +from .commit_create_params import CommitCreateParams as CommitCreateParams from .commit_list_response import CommitListResponse as CommitListResponse +from .commit_create_response import CommitCreateResponse as CommitCreateResponse from .inference_pipeline_list_params import InferencePipelineListParams as InferencePipelineListParams from .inference_pipeline_create_params import InferencePipelineCreateParams as InferencePipelineCreateParams from .inference_pipeline_list_response import InferencePipelineListResponse as InferencePipelineListResponse diff --git a/src/openlayer/types/projects/commit_create_params.py b/src/openlayer/types/projects/commit_create_params.py new file mode 100644 index 00000000..d4430726 --- /dev/null +++ b/src/openlayer/types/projects/commit_create_params.py @@ -0,0 +1,29 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Optional +from typing_extensions import Required, Annotated, TypedDict + +from ..._utils import PropertyInfo + +__all__ = ["CommitCreateParams", "Commit"] + + +class CommitCreateParams(TypedDict, total=False): + commit: Required[Commit] + """The details of a commit (project version).""" + + storage_uri: Required[Annotated[str, PropertyInfo(alias="storageUri")]] + """The storage URI where the commit bundle is stored.""" + + archived: Optional[bool] + """Whether the commit is archived.""" + + deployment_status: Annotated[str, PropertyInfo(alias="deploymentStatus")] + """The deployment status associated with the commit's model.""" + + +class Commit(TypedDict, total=False): + message: Required[str] + """The commit message.""" diff --git a/src/openlayer/types/projects/commit_create_response.py b/src/openlayer/types/projects/commit_create_response.py new file mode 100644 index 00000000..29a19ad5 --- /dev/null +++ b/src/openlayer/types/projects/commit_create_response.py @@ -0,0 +1,106 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional +from datetime import datetime +from typing_extensions import Literal + +from pydantic import Field as FieldInfo + +from ..._models import BaseModel + +__all__ = ["CommitCreateResponse", "Commit", "Links"] + + +class Commit(BaseModel): + id: str + """The commit id.""" + + author_id: str = FieldInfo(alias="authorId") + """The author id of the commit.""" + + file_size: Optional[int] = FieldInfo(alias="fileSize", default=None) + """The size of the commit bundle in bytes.""" + + message: str + """The commit message.""" + + ml_model_id: Optional[str] = FieldInfo(alias="mlModelId", default=None) + """The model id.""" + + storage_uri: str = FieldInfo(alias="storageUri") + """The storage URI where the commit bundle is stored.""" + + training_dataset_id: Optional[str] = FieldInfo(alias="trainingDatasetId", default=None) + """The training dataset id.""" + + validation_dataset_id: Optional[str] = FieldInfo(alias="validationDatasetId", default=None) + """The validation dataset id.""" + + date_created: Optional[datetime] = FieldInfo(alias="dateCreated", default=None) + """The commit creation date.""" + + git_commit_ref: Optional[str] = FieldInfo(alias="gitCommitRef", default=None) + """The ref of the corresponding git commit.""" + + git_commit_sha: Optional[int] = FieldInfo(alias="gitCommitSha", default=None) + """The SHA of the corresponding git commit.""" + + git_commit_url: Optional[str] = FieldInfo(alias="gitCommitUrl", default=None) + """The URL of the corresponding git commit.""" + + +class Links(BaseModel): + app: str + + +class CommitCreateResponse(BaseModel): + id: str + """The project version (commit) id.""" + + commit: Commit + """The details of a commit (project version).""" + + date_archived: Optional[datetime] = FieldInfo(alias="dateArchived", default=None) + """The commit archive date.""" + + date_created: datetime = FieldInfo(alias="dateCreated") + """The project version (commit) creation date.""" + + failing_goal_count: int = FieldInfo(alias="failingGoalCount") + """The number of tests that are failing for the commit.""" + + ml_model_id: Optional[str] = FieldInfo(alias="mlModelId", default=None) + """The model id.""" + + passing_goal_count: int = FieldInfo(alias="passingGoalCount") + """The number of tests that are passing for the commit.""" + + project_id: str = FieldInfo(alias="projectId") + """The project id.""" + + status: Literal["queued", "running", "paused", "failed", "completed", "unknown"] + """The commit status. + + Initially, the commit is `queued`, then, it switches to `running`. Finally, it + can be `paused`, `failed`, or `completed`. + """ + + status_message: Optional[str] = FieldInfo(alias="statusMessage", default=None) + """The commit status message.""" + + total_goal_count: int = FieldInfo(alias="totalGoalCount") + """The total number of tests for the commit.""" + + training_dataset_id: Optional[str] = FieldInfo(alias="trainingDatasetId", default=None) + """The training dataset id.""" + + validation_dataset_id: Optional[str] = FieldInfo(alias="validationDatasetId", default=None) + """The validation dataset id.""" + + archived: Optional[bool] = None + """Whether the commit is archived.""" + + deployment_status: Optional[str] = FieldInfo(alias="deploymentStatus", default=None) + """The deployment status associated with the commit's model.""" + + links: Optional[Links] = None diff --git a/tests/api_resources/projects/test_commits.py b/tests/api_resources/projects/test_commits.py index b0883779..62fc86ca 100644 --- a/tests/api_resources/projects/test_commits.py +++ b/tests/api_resources/projects/test_commits.py @@ -9,7 +9,7 @@ from openlayer import Openlayer, AsyncOpenlayer from tests.utils import assert_matches_type -from openlayer.types.projects import CommitListResponse +from openlayer.types.projects import CommitListResponse, CommitCreateResponse base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") @@ -17,6 +17,63 @@ class TestCommits: parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + @parametrize + def test_method_create(self, client: Openlayer) -> None: + commit = client.projects.commits.create( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + commit={"message": "Updated the prompt."}, + storage_uri="s3://...", + ) + assert_matches_type(CommitCreateResponse, commit, path=["response"]) + + @parametrize + def test_method_create_with_all_params(self, client: Openlayer) -> None: + commit = client.projects.commits.create( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + commit={"message": "Updated the prompt."}, + storage_uri="s3://...", + archived=False, + deployment_status="Deployed", + ) + assert_matches_type(CommitCreateResponse, commit, path=["response"]) + + @parametrize + def test_raw_response_create(self, client: Openlayer) -> None: + response = client.projects.commits.with_raw_response.create( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + commit={"message": "Updated the prompt."}, + storage_uri="s3://...", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + commit = response.parse() + assert_matches_type(CommitCreateResponse, commit, path=["response"]) + + @parametrize + def test_streaming_response_create(self, client: Openlayer) -> None: + with client.projects.commits.with_streaming_response.create( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + commit={"message": "Updated the prompt."}, + storage_uri="s3://...", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + commit = response.parse() + assert_matches_type(CommitCreateResponse, commit, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_path_params_create(self, client: Openlayer) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): + client.projects.commits.with_raw_response.create( + project_id="", + commit={"message": "Updated the prompt."}, + storage_uri="s3://...", + ) + @parametrize def test_method_list(self, client: Openlayer) -> None: commit = client.projects.commits.list( @@ -68,6 +125,63 @@ def test_path_params_list(self, client: Openlayer) -> None: class TestAsyncCommits: parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + @parametrize + async def test_method_create(self, async_client: AsyncOpenlayer) -> None: + commit = await async_client.projects.commits.create( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + commit={"message": "Updated the prompt."}, + storage_uri="s3://...", + ) + assert_matches_type(CommitCreateResponse, commit, path=["response"]) + + @parametrize + async def test_method_create_with_all_params(self, async_client: AsyncOpenlayer) -> None: + commit = await async_client.projects.commits.create( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + commit={"message": "Updated the prompt."}, + storage_uri="s3://...", + archived=False, + deployment_status="Deployed", + ) + assert_matches_type(CommitCreateResponse, commit, path=["response"]) + + @parametrize + async def test_raw_response_create(self, async_client: AsyncOpenlayer) -> None: + response = await async_client.projects.commits.with_raw_response.create( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + commit={"message": "Updated the prompt."}, + storage_uri="s3://...", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + commit = await response.parse() + assert_matches_type(CommitCreateResponse, commit, path=["response"]) + + @parametrize + async def test_streaming_response_create(self, async_client: AsyncOpenlayer) -> None: + async with async_client.projects.commits.with_streaming_response.create( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + commit={"message": "Updated the prompt."}, + storage_uri="s3://...", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + commit = await response.parse() + assert_matches_type(CommitCreateResponse, commit, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_path_params_create(self, async_client: AsyncOpenlayer) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): + await async_client.projects.commits.with_raw_response.create( + project_id="", + commit={"message": "Updated the prompt."}, + storage_uri="s3://...", + ) + @parametrize async def test_method_list(self, async_client: AsyncOpenlayer) -> None: commit = await async_client.projects.commits.list(