Skip to content

Commit

Permalink
feat(api): add types for application jobs (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Jan 29, 2025
1 parent 49e58c8 commit e73ec53
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 72 deletions.
8 changes: 4 additions & 4 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ Types:

```python
from writerai.types.applications import (
ApplicationGenerateAsyncResponse,
ApplicationJobsListResponse,
JobCreateResponse,
JobRetrieveResponse,
JobListResponse,
JobRetryResponse,
)
```

Methods:

- <code title="post /v1/applications/{application_id}/jobs">client.applications.jobs.<a href="./src/writerai/resources/applications/jobs.py">create</a>(application_id, \*\*<a href="src/writerai/types/applications/job_create_params.py">params</a>) -> <a href="./src/writerai/types/applications/job_create_response.py">JobCreateResponse</a></code>
- <code title="get /v1/applications/jobs/{job_id}">client.applications.jobs.<a href="./src/writerai/resources/applications/jobs.py">retrieve</a>(job_id) -> <a href="./src/writerai/types/applications/job_retrieve_response.py">JobRetrieveResponse</a></code>
- <code title="get /v1/applications/{application_id}/jobs">client.applications.jobs.<a href="./src/writerai/resources/applications/jobs.py">list</a>(application_id, \*\*<a href="src/writerai/types/applications/job_list_params.py">params</a>) -> <a href="./src/writerai/types/applications/job_list_response.py">SyncApplicationJobsOffset[JobListResponse]</a></code>
- <code title="get /v1/applications/jobs/{job_id}">client.applications.jobs.<a href="./src/writerai/resources/applications/jobs.py">retrieve</a>(job_id) -> <a href="./src/writerai/types/applications/application_generate_async_response.py">ApplicationGenerateAsyncResponse</a></code>
- <code title="get /v1/applications/{application_id}/jobs">client.applications.jobs.<a href="./src/writerai/resources/applications/jobs.py">list</a>(application_id, \*\*<a href="src/writerai/types/applications/job_list_params.py">params</a>) -> <a href="./src/writerai/types/applications/application_generate_async_response.py">SyncApplicationJobsOffset[ApplicationGenerateAsyncResponse]</a></code>
- <code title="post /v1/applications/jobs/{job_id}/retry">client.applications.jobs.<a href="./src/writerai/resources/applications/jobs.py">retry</a>(job_id) -> <a href="./src/writerai/types/applications/job_retry_response.py">JobRetryResponse</a></code>

## Graphs
Expand Down
23 changes: 11 additions & 12 deletions src/writerai/resources/applications/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
from ...pagination import SyncApplicationJobsOffset, AsyncApplicationJobsOffset
from ..._base_client import AsyncPaginator, make_request_options
from ...types.applications import job_list_params, job_create_params
from ...types.applications.job_list_response import JobListResponse
from ...types.applications.job_retry_response import JobRetryResponse
from ...types.applications.job_create_response import JobCreateResponse
from ...types.applications.job_retrieve_response import JobRetrieveResponse
from ...types.applications.application_generate_async_response import ApplicationGenerateAsyncResponse

__all__ = ["JobsResource", "AsyncJobsResource"]

Expand Down Expand Up @@ -98,7 +97,7 @@ def retrieve(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> JobRetrieveResponse:
) -> ApplicationGenerateAsyncResponse:
"""
Retrieves a single job created via the Async API.
Expand All @@ -118,7 +117,7 @@ def retrieve(
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=JobRetrieveResponse,
cast_to=ApplicationGenerateAsyncResponse,
)

def list(
Expand All @@ -134,7 +133,7 @@ def list(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> SyncApplicationJobsOffset[JobListResponse]:
) -> SyncApplicationJobsOffset[ApplicationGenerateAsyncResponse]:
"""
Retrieve all jobs created via the async API, linked to the provided application
ID (or alias).
Expand All @@ -158,7 +157,7 @@ def list(
raise ValueError(f"Expected a non-empty value for `application_id` but received {application_id!r}")
return self._get_api_list(
f"/v1/applications/{application_id}/jobs",
page=SyncApplicationJobsOffset[JobListResponse],
page=SyncApplicationJobsOffset[ApplicationGenerateAsyncResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
Expand All @@ -173,7 +172,7 @@ def list(
job_list_params.JobListParams,
),
),
model=JobListResponse,
model=ApplicationGenerateAsyncResponse,
)

def retry(
Expand Down Expand Up @@ -278,7 +277,7 @@ async def retrieve(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> JobRetrieveResponse:
) -> ApplicationGenerateAsyncResponse:
"""
Retrieves a single job created via the Async API.
Expand All @@ -298,7 +297,7 @@ async def retrieve(
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=JobRetrieveResponse,
cast_to=ApplicationGenerateAsyncResponse,
)

def list(
Expand All @@ -314,7 +313,7 @@ def list(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> AsyncPaginator[JobListResponse, AsyncApplicationJobsOffset[JobListResponse]]:
) -> AsyncPaginator[ApplicationGenerateAsyncResponse, AsyncApplicationJobsOffset[ApplicationGenerateAsyncResponse]]:
"""
Retrieve all jobs created via the async API, linked to the provided application
ID (or alias).
Expand All @@ -338,7 +337,7 @@ def list(
raise ValueError(f"Expected a non-empty value for `application_id` but received {application_id!r}")
return self._get_api_list(
f"/v1/applications/{application_id}/jobs",
page=AsyncApplicationJobsOffset[JobListResponse],
page=AsyncApplicationJobsOffset[ApplicationGenerateAsyncResponse],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
Expand All @@ -353,7 +352,7 @@ def list(
job_list_params.JobListParams,
),
),
model=JobListResponse,
model=ApplicationGenerateAsyncResponse,
)

async def retry(
Expand Down
4 changes: 2 additions & 2 deletions src/writerai/types/applications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

from .job_list_params import JobListParams as JobListParams
from .job_create_params import JobCreateParams as JobCreateParams
from .job_list_response import JobListResponse as JobListResponse
from .job_retry_response import JobRetryResponse as JobRetryResponse
from .graph_update_params import GraphUpdateParams as GraphUpdateParams
from .job_create_response import JobCreateResponse as JobCreateResponse
from .job_retrieve_response import JobRetrieveResponse as JobRetrieveResponse
from .application_graphs_response import ApplicationGraphsResponse as ApplicationGraphsResponse
from .application_jobs_list_response import ApplicationJobsListResponse as ApplicationJobsListResponse
from .application_generate_async_response import ApplicationGenerateAsyncResponse as ApplicationGenerateAsyncResponse
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from ..._models import BaseModel
from ..application_generate_content_response import ApplicationGenerateContentResponse

__all__ = ["JobListResponse"]
__all__ = ["ApplicationGenerateAsyncResponse"]


class JobListResponse(BaseModel):
class ApplicationGenerateAsyncResponse(BaseModel):
id: str
"""The unique identifier for the job."""

Expand Down
27 changes: 27 additions & 0 deletions src/writerai/types/applications/application_jobs_list_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import List, Optional

from pydantic import Field as FieldInfo

from ..._models import BaseModel
from .application_generate_async_response import ApplicationGenerateAsyncResponse

__all__ = ["ApplicationJobsListResponse", "Pagination"]


class Pagination(BaseModel):
limit: Optional[int] = None
"""The pagination limit for retrieving the jobs."""

offset: Optional[int] = None
"""The pagination offset for retrieving the jobs."""


class ApplicationJobsListResponse(BaseModel):
result: List[ApplicationGenerateAsyncResponse]

pagination: Optional[Pagination] = None

total_count: Optional[int] = FieldInfo(alias="totalCount", default=None)
"""The total number of jobs associated with the application."""
36 changes: 0 additions & 36 deletions src/writerai/types/applications/job_retrieve_response.py

This file was deleted.

31 changes: 15 additions & 16 deletions tests/api_resources/applications/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
from tests.utils import assert_matches_type
from writerai.pagination import SyncApplicationJobsOffset, AsyncApplicationJobsOffset
from writerai.types.applications import (
JobListResponse,
JobRetryResponse,
JobCreateResponse,
JobRetrieveResponse,
ApplicationGenerateAsyncResponse,
)

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
Expand Down Expand Up @@ -90,7 +89,7 @@ def test_method_retrieve(self, client: Writer) -> None:
job = client.applications.jobs.retrieve(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
assert_matches_type(JobRetrieveResponse, job, path=["response"])
assert_matches_type(ApplicationGenerateAsyncResponse, job, path=["response"])

@parametrize
def test_raw_response_retrieve(self, client: Writer) -> None:
Expand All @@ -101,7 +100,7 @@ def test_raw_response_retrieve(self, client: Writer) -> None:
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
job = response.parse()
assert_matches_type(JobRetrieveResponse, job, path=["response"])
assert_matches_type(ApplicationGenerateAsyncResponse, job, path=["response"])

@parametrize
def test_streaming_response_retrieve(self, client: Writer) -> None:
Expand All @@ -112,7 +111,7 @@ def test_streaming_response_retrieve(self, client: Writer) -> None:
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

job = response.parse()
assert_matches_type(JobRetrieveResponse, job, path=["response"])
assert_matches_type(ApplicationGenerateAsyncResponse, job, path=["response"])

assert cast(Any, response.is_closed) is True

Expand All @@ -128,7 +127,7 @@ def test_method_list(self, client: Writer) -> None:
job = client.applications.jobs.list(
application_id="application_id",
)
assert_matches_type(SyncApplicationJobsOffset[JobListResponse], job, path=["response"])
assert_matches_type(SyncApplicationJobsOffset[ApplicationGenerateAsyncResponse], job, path=["response"])

@parametrize
def test_method_list_with_all_params(self, client: Writer) -> None:
Expand All @@ -138,7 +137,7 @@ def test_method_list_with_all_params(self, client: Writer) -> None:
offset=0,
status="in_progress",
)
assert_matches_type(SyncApplicationJobsOffset[JobListResponse], job, path=["response"])
assert_matches_type(SyncApplicationJobsOffset[ApplicationGenerateAsyncResponse], job, path=["response"])

@parametrize
def test_raw_response_list(self, client: Writer) -> None:
Expand All @@ -149,7 +148,7 @@ def test_raw_response_list(self, client: Writer) -> None:
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
job = response.parse()
assert_matches_type(SyncApplicationJobsOffset[JobListResponse], job, path=["response"])
assert_matches_type(SyncApplicationJobsOffset[ApplicationGenerateAsyncResponse], job, path=["response"])

@parametrize
def test_streaming_response_list(self, client: Writer) -> None:
Expand All @@ -160,7 +159,7 @@ def test_streaming_response_list(self, client: Writer) -> None:
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

job = response.parse()
assert_matches_type(SyncApplicationJobsOffset[JobListResponse], job, path=["response"])
assert_matches_type(SyncApplicationJobsOffset[ApplicationGenerateAsyncResponse], job, path=["response"])

assert cast(Any, response.is_closed) is True

Expand Down Expand Up @@ -280,7 +279,7 @@ async def test_method_retrieve(self, async_client: AsyncWriter) -> None:
job = await async_client.applications.jobs.retrieve(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
assert_matches_type(JobRetrieveResponse, job, path=["response"])
assert_matches_type(ApplicationGenerateAsyncResponse, job, path=["response"])

@parametrize
async def test_raw_response_retrieve(self, async_client: AsyncWriter) -> None:
Expand All @@ -291,7 +290,7 @@ async def test_raw_response_retrieve(self, async_client: AsyncWriter) -> None:
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
job = await response.parse()
assert_matches_type(JobRetrieveResponse, job, path=["response"])
assert_matches_type(ApplicationGenerateAsyncResponse, job, path=["response"])

@parametrize
async def test_streaming_response_retrieve(self, async_client: AsyncWriter) -> None:
Expand All @@ -302,7 +301,7 @@ async def test_streaming_response_retrieve(self, async_client: AsyncWriter) -> N
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

job = await response.parse()
assert_matches_type(JobRetrieveResponse, job, path=["response"])
assert_matches_type(ApplicationGenerateAsyncResponse, job, path=["response"])

assert cast(Any, response.is_closed) is True

Expand All @@ -318,7 +317,7 @@ async def test_method_list(self, async_client: AsyncWriter) -> None:
job = await async_client.applications.jobs.list(
application_id="application_id",
)
assert_matches_type(AsyncApplicationJobsOffset[JobListResponse], job, path=["response"])
assert_matches_type(AsyncApplicationJobsOffset[ApplicationGenerateAsyncResponse], job, path=["response"])

@parametrize
async def test_method_list_with_all_params(self, async_client: AsyncWriter) -> None:
Expand All @@ -328,7 +327,7 @@ async def test_method_list_with_all_params(self, async_client: AsyncWriter) -> N
offset=0,
status="in_progress",
)
assert_matches_type(AsyncApplicationJobsOffset[JobListResponse], job, path=["response"])
assert_matches_type(AsyncApplicationJobsOffset[ApplicationGenerateAsyncResponse], job, path=["response"])

@parametrize
async def test_raw_response_list(self, async_client: AsyncWriter) -> None:
Expand All @@ -339,7 +338,7 @@ async def test_raw_response_list(self, async_client: AsyncWriter) -> None:
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
job = await response.parse()
assert_matches_type(AsyncApplicationJobsOffset[JobListResponse], job, path=["response"])
assert_matches_type(AsyncApplicationJobsOffset[ApplicationGenerateAsyncResponse], job, path=["response"])

@parametrize
async def test_streaming_response_list(self, async_client: AsyncWriter) -> None:
Expand All @@ -350,7 +349,7 @@ async def test_streaming_response_list(self, async_client: AsyncWriter) -> None:
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

job = await response.parse()
assert_matches_type(AsyncApplicationJobsOffset[JobListResponse], job, path=["response"])
assert_matches_type(AsyncApplicationJobsOffset[ApplicationGenerateAsyncResponse], job, path=["response"])

assert cast(Any, response.is_closed) is True

Expand Down

0 comments on commit e73ec53

Please sign in to comment.