Skip to content

Commit c03603e

Browse files
authored
Add API to cancel a batch (#355)
* Add API to cancel a batch * Address comments
1 parent 6e92279 commit c03603e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/together/resources/batch.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ def list_batches(self) -> List[BatchJob]:
7272
jobs = response.data or []
7373
return [BatchJob(**job) for job in jobs]
7474

75+
def cancel_batch(self, batch_job_id: str) -> BatchJob:
76+
requestor = api_requestor.APIRequestor(
77+
client=self._client,
78+
)
79+
80+
response, _, _ = requestor.request(
81+
options=TogetherRequest(
82+
method="POST",
83+
url=f"batches/{batch_job_id}/cancel",
84+
),
85+
stream=False,
86+
)
87+
88+
return BatchJob(**response.data)
89+
7590

7691
class AsyncBatches:
7792
def __init__(self, client: TogetherClient) -> None:
@@ -133,3 +148,18 @@ async def list_batches(self) -> List[BatchJob]:
133148
assert isinstance(response, TogetherResponse)
134149
jobs = response.data or []
135150
return [BatchJob(**job) for job in jobs]
151+
152+
async def cancel_batch(self, batch_job_id: str) -> BatchJob:
153+
requestor = api_requestor.APIRequestor(
154+
client=self._client,
155+
)
156+
157+
response, _, _ = await requestor.arequest(
158+
options=TogetherRequest(
159+
method="POST",
160+
url=f"batches/{batch_job_id}/cancel",
161+
),
162+
stream=False,
163+
)
164+
165+
return BatchJob(**response.data)

src/together/types/batch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class BatchJobStatus(str, Enum):
2020
FAILED = "FAILED"
2121
EXPIRED = "EXPIRED"
2222
CANCELLED = "CANCELLED"
23+
CANCELING = "CANCELING"
2324

2425

2526
class BatchEndpoint(str, Enum):

0 commit comments

Comments
 (0)