Skip to content

Commit

Permalink
feat(api): update application jobs pagination response (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Jan 29, 2025
1 parent 66b6319 commit cb30cef
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 27
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-6930d4b5bd70658f2379d331f27ccc5ce8898c05abf4dc7bd36ebb2ada18dc7f.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-95e5c41bc4917566fc6ee1f849795bac2e34e5609afd25bb927252ac7e33e2f0.yml
16 changes: 8 additions & 8 deletions src/writerai/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ def next_page_info(self) -> Optional[PageInfo]:


class SyncApplicationJobsOffset(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
jobs: List[_T]
result: List[_T]

@override
def _get_page_items(self) -> List[_T]:
jobs = self.jobs
if not jobs:
result = self.result
if not result:
return []
return jobs
return result

@override
def next_page_info(self) -> Optional[PageInfo]:
Expand All @@ -108,14 +108,14 @@ def next_page_info(self) -> Optional[PageInfo]:


class AsyncApplicationJobsOffset(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
jobs: List[_T]
result: List[_T]

@override
def _get_page_items(self) -> List[_T]:
jobs = self.jobs
if not jobs:
result = self.result
if not result:
return []
return jobs
return result

@override
def next_page_info(self) -> Optional[PageInfo]:
Expand Down
14 changes: 4 additions & 10 deletions src/writerai/resources/applications/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ def update(
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> ApplicationGraphsResponse:
"""
Updates the graphs listed and associates them with the no-code chat app to be
used.
Associate graphs with a no-code chat application via API.
Args:
graph_ids: A list of graph IDs to associate with the application. Note that this will
replace the existing list of graphs associated with the application, not add to
it.
graph_ids: A list of graph IDs to associate with the application.
extra_headers: Send extra headers
Expand Down Expand Up @@ -153,13 +150,10 @@ async def update(
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> ApplicationGraphsResponse:
"""
Updates the graphs listed and associates them with the no-code chat app to be
used.
Associate graphs with a no-code chat application via API.
Args:
graph_ids: A list of graph IDs to associate with the application. Note that this will
replace the existing list of graphs associated with the application, not add to
it.
graph_ids: A list of graph IDs to associate with the application.
extra_headers: Send extra headers
Expand Down
41 changes: 23 additions & 18 deletions src/writerai/resources/applications/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from __future__ import annotations

from typing import Iterable
from typing_extensions import Literal
from typing import Dict, Iterable

import httpx

Expand Down Expand Up @@ -55,6 +54,7 @@ def create(
application_id: str,
*,
inputs: Iterable[job_create_params.Input],
metadata: Dict[str, 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,
Expand All @@ -68,6 +68,8 @@ def create(
Args:
inputs: A list of input objects to generate content for.
metadata: Optional metadata for the generation request.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
Expand All @@ -80,7 +82,13 @@ def create(
raise ValueError(f"Expected a non-empty value for `application_id` but received {application_id!r}")
return self._post(
f"/v1/applications/{application_id}/jobs",
body=maybe_transform({"inputs": inputs}, job_create_params.JobCreateParams),
body=maybe_transform(
{
"inputs": inputs,
"metadata": metadata,
},
job_create_params.JobCreateParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
Expand Down Expand Up @@ -126,7 +134,7 @@ def list(
*,
limit: int | NotGiven = NOT_GIVEN,
offset: int | NotGiven = NOT_GIVEN,
status: Literal["in_progress", "failed", "completed"] | NotGiven = NOT_GIVEN,
status: job_list_params.Status | 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,
Expand All @@ -139,12 +147,6 @@ def list(
ID (or alias).
Args:
limit: The pagination limit for retrieving the jobs.
offset: The pagination offset for retrieving the jobs.
status: The status of the job.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
Expand Down Expand Up @@ -234,6 +236,7 @@ async def create(
application_id: str,
*,
inputs: Iterable[job_create_params.Input],
metadata: Dict[str, 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,
Expand All @@ -247,6 +250,8 @@ async def create(
Args:
inputs: A list of input objects to generate content for.
metadata: Optional metadata for the generation request.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
Expand All @@ -259,7 +264,13 @@ async def create(
raise ValueError(f"Expected a non-empty value for `application_id` but received {application_id!r}")
return await self._post(
f"/v1/applications/{application_id}/jobs",
body=await async_maybe_transform({"inputs": inputs}, job_create_params.JobCreateParams),
body=await async_maybe_transform(
{
"inputs": inputs,
"metadata": metadata,
},
job_create_params.JobCreateParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
Expand Down Expand Up @@ -305,7 +316,7 @@ async def list(
*,
limit: int | NotGiven = NOT_GIVEN,
offset: int | NotGiven = NOT_GIVEN,
status: Literal["in_progress", "failed", "completed"] | NotGiven = NOT_GIVEN,
status: job_list_params.Status | 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,
Expand All @@ -318,12 +329,6 @@ async def list(
ID (or alias).
Args:
limit: The pagination limit for retrieving the jobs.
offset: The pagination offset for retrieving the jobs.
status: The status of the job.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
Expand Down
6 changes: 1 addition & 5 deletions src/writerai/types/applications/graph_update_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@

class GraphUpdateParams(TypedDict, total=False):
graph_ids: Required[List[str]]
"""A list of graph IDs to associate with the application.
Note that this will replace the existing list of graphs associated with the
application, not add to it.
"""
"""A list of graph IDs to associate with the application."""
23 changes: 8 additions & 15 deletions src/writerai/types/applications/job_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import List, Iterable
from typing import Dict, Iterable
from typing_extensions import Required, TypedDict

__all__ = ["JobCreateParams", "Input"]
Expand All @@ -12,20 +12,13 @@ class JobCreateParams(TypedDict, total=False):
inputs: Required[Iterable[Input]]
"""A list of input objects to generate content for."""

metadata: Dict[str, str]
"""Optional metadata for the generation request."""

class Input(TypedDict, total=False):
id: Required[str]
"""The unique identifier for the input field from the application.
All input types from the No-code application are supported (i.e. Text input,
Dropdown, File upload, Image input). The identifier should be the name of the
input type.
"""

value: Required[List[str]]
"""The value for the input field.
class Input(TypedDict, total=False):
content: str
"""The input content to be processed."""

If file is required you will need to pass a `file_id`. See
[here](https://dev.writer.com/api-guides/api-reference/file-api/upload-files)
for the Files API.
"""
input_id: str
"""A unique identifier for the input object."""
13 changes: 8 additions & 5 deletions src/writerai/types/applications/job_create_response.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# 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 ..._models import BaseModel

__all__ = ["JobCreateResponse"]


class JobCreateResponse(BaseModel):
id: str
job_id: str
"""The unique identifier for the async job created."""

created_at: datetime
application_id: Optional[str] = None
"""The ID of the application associated with this job."""

created_at: Optional[datetime] = None
"""The timestamp when the job was created."""

status: Literal["in_progress", "failed", "completed"]
"""The status of the job."""
status: Optional[str] = None
"""The initial status of the job (e.g., 'queued')."""
35 changes: 29 additions & 6 deletions src/writerai/types/applications/job_list_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,40 @@

from __future__ import annotations

from typing_extensions import Literal, TypedDict
from typing import Union, Iterable
from datetime import datetime
from typing_extensions import Required, Annotated, TypedDict

__all__ = ["JobListParams"]
from ..._utils import PropertyInfo

__all__ = ["JobListParams", "Status", "StatusJob"]


class JobListParams(TypedDict, total=False):
limit: int
"""The pagination limit for retrieving the jobs."""

offset: int
"""The pagination offset for retrieving the jobs."""

status: Literal["in_progress", "failed", "completed"]
"""The status of the job."""
status: Status


class StatusJob(TypedDict, total=False):
created_at: Annotated[Union[str, datetime], PropertyInfo(format="iso8601")]
"""The timestamp when the job was created."""

job_id: str
"""The unique identifier for the job."""

result: str
"""The result of the completed job, if applicable."""

status: str
"""The current status of the job."""

updated_at: Annotated[Union[str, datetime], PropertyInfo(format="iso8601")]
"""The timestamp when the job was last updated."""


class Status(TypedDict, total=False):
jobs: Required[Iterable[StatusJob]]
"""A list of jobs associated with the application."""
30 changes: 10 additions & 20 deletions src/writerai/types/applications/job_list_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,29 @@

from typing import List, Optional
from datetime import datetime
from typing_extensions import Literal

from ..._models import BaseModel
from ..application_generate_content_response import ApplicationGenerateContentResponse

__all__ = ["JobListResponse", "Result"]
__all__ = ["JobListResponse", "Job"]


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

application_id: str
"""The ID of the application associated with this job."""

created_at: datetime
class Job(BaseModel):
created_at: Optional[datetime] = None
"""The timestamp when the job was created."""

status: Literal["in_progress", "failed", "completed"]
"""The status of the job."""

completed_at: Optional[datetime] = None
"""The timestamp when the job was completed."""
job_id: Optional[str] = None
"""The unique identifier for the job."""

data: Optional[ApplicationGenerateContentResponse] = None
result: Optional[str] = None
"""The result of the completed job, if applicable."""

error: Optional[str] = None
"""The error message if the job failed."""
status: Optional[str] = None
"""The current status of the job."""

updated_at: Optional[datetime] = None
"""The timestamp when the job was last updated."""


class JobListResponse(BaseModel):
result: Optional[List[Result]] = None
jobs: List[Job]
"""A list of jobs associated with the application."""
Loading

0 comments on commit cb30cef

Please sign in to comment.