Skip to content

feat(api): add endpoint to retrieve commit by id #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions .github/workflows/create-releases.yml

This file was deleted.

8 changes: 6 additions & 2 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# workflow for re-running publishing to PyPI in case it fails for some reason
# you can run this workflow by navigating to https://www.github.com/openlayer-ai/openlayer-python/actions/workflows/publish-pypi.yml
# This workflow is triggered when a GitHub release is created.
# It can also be run manually to re-publish to PyPI in case it failed for some reason.
# You can run this workflow by navigating to https://www.github.com/openlayer-ai/openlayer-python/actions/workflows/publish-pypi.yml
name: Publish PyPI
on:
workflow_dispatch:

release:
types: [published]

jobs:
publish:
name: publish
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ jobs:
run: |
bash ./bin/check-release-environment
env:
STAINLESS_API_KEY: ${{ secrets.STAINLESS_API_KEY }}
PYPI_TOKEN: ${{ secrets.OPENLAYER_PYPI_TOKEN || secrets.PYPI_TOKEN }}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 14
configured_endpoints: 15
10 changes: 10 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ Methods:

# Commits

Types:

```python
from openlayer.types import CommitRetrieveResponse
```

Methods:

- <code title="get /versions/{projectVersionId}">client.commits.<a href="./src/openlayer/resources/commits/commits.py">retrieve</a>(project_version_id) -> <a href="./src/openlayer/types/commit_retrieve_response.py">CommitRetrieveResponse</a></code>

## TestResults

Types:
Expand Down
4 changes: 0 additions & 4 deletions bin/check-release-environment
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

errors=()

if [ -z "${STAINLESS_API_KEY}" ]; then
errors+=("The STAINLESS_API_KEY secret has not been set. Please contact Stainless for an API key & set it in your organization secrets on GitHub.")
fi

if [ -z "${PYPI_TOKEN}" ]; then
errors+=("The OPENLAYER_PYPI_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets.")
fi
Expand Down
93 changes: 93 additions & 0 deletions src/openlayer/resources/commits/commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

from __future__ import annotations

import httpx

from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
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,
Expand All @@ -12,6 +21,8 @@
TestResultsResourceWithStreamingResponse,
AsyncTestResultsResourceWithStreamingResponse,
)
from ..._base_client import make_request_options
from ...types.commit_retrieve_response import CommitRetrieveResponse

__all__ = ["CommitsResource", "AsyncCommitsResource"]

Expand Down Expand Up @@ -40,6 +51,39 @@ def with_streaming_response(self) -> CommitsResourceWithStreamingResponse:
"""
return CommitsResourceWithStreamingResponse(self)

def retrieve(
self,
project_version_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,
) -> CommitRetrieveResponse:
"""
Retrieve a project version (commit) by its id.

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 project_version_id:
raise ValueError(f"Expected a non-empty value for `project_version_id` but received {project_version_id!r}")
return self._get(
f"/versions/{project_version_id}",
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=CommitRetrieveResponse,
)


class AsyncCommitsResource(AsyncAPIResource):
@cached_property
Expand All @@ -65,11 +109,48 @@ def with_streaming_response(self) -> AsyncCommitsResourceWithStreamingResponse:
"""
return AsyncCommitsResourceWithStreamingResponse(self)

async def retrieve(
self,
project_version_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,
) -> CommitRetrieveResponse:
"""
Retrieve a project version (commit) by its id.

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 project_version_id:
raise ValueError(f"Expected a non-empty value for `project_version_id` but received {project_version_id!r}")
return await self._get(
f"/versions/{project_version_id}",
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=CommitRetrieveResponse,
)


class CommitsResourceWithRawResponse:
def __init__(self, commits: CommitsResource) -> None:
self._commits = commits

self.retrieve = to_raw_response_wrapper(
commits.retrieve,
)

@cached_property
def test_results(self) -> TestResultsResourceWithRawResponse:
return TestResultsResourceWithRawResponse(self._commits.test_results)
Expand All @@ -79,6 +160,10 @@ class AsyncCommitsResourceWithRawResponse:
def __init__(self, commits: AsyncCommitsResource) -> None:
self._commits = commits

self.retrieve = async_to_raw_response_wrapper(
commits.retrieve,
)

@cached_property
def test_results(self) -> AsyncTestResultsResourceWithRawResponse:
return AsyncTestResultsResourceWithRawResponse(self._commits.test_results)
Expand All @@ -88,6 +173,10 @@ class CommitsResourceWithStreamingResponse:
def __init__(self, commits: CommitsResource) -> None:
self._commits = commits

self.retrieve = to_streamed_response_wrapper(
commits.retrieve,
)

@cached_property
def test_results(self) -> TestResultsResourceWithStreamingResponse:
return TestResultsResourceWithStreamingResponse(self._commits.test_results)
Expand All @@ -97,6 +186,10 @@ class AsyncCommitsResourceWithStreamingResponse:
def __init__(self, commits: AsyncCommitsResource) -> None:
self._commits = commits

self.retrieve = async_to_streamed_response_wrapper(
commits.retrieve,
)

@cached_property
def test_results(self) -> AsyncTestResultsResourceWithStreamingResponse:
return AsyncTestResultsResourceWithStreamingResponse(self._commits.test_results)
1 change: 1 addition & 0 deletions src/openlayer/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .project_create_params import ProjectCreateParams as ProjectCreateParams
from .project_list_response import ProjectListResponse as ProjectListResponse
from .project_create_response import ProjectCreateResponse as ProjectCreateResponse
from .commit_retrieve_response import CommitRetrieveResponse as CommitRetrieveResponse
from .inference_pipeline_update_params import InferencePipelineUpdateParams as InferencePipelineUpdateParams
from .inference_pipeline_retrieve_params import InferencePipelineRetrieveParams as InferencePipelineRetrieveParams
from .inference_pipeline_update_response import InferencePipelineUpdateResponse as InferencePipelineUpdateResponse
Expand Down
106 changes: 106 additions & 0 deletions src/openlayer/types/commit_retrieve_response.py
Original file line number Diff line number Diff line change
@@ -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__ = ["CommitRetrieveResponse", "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 CommitRetrieveResponse(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
Loading