Skip to content

Commit 97cc7e4

Browse files
speedstorm1copybara-github
authored andcommitted
feat: Add empty response for tunings.cancel()
PiperOrigin-RevId: 839451352
1 parent 060f015 commit 97cc7e4

File tree

3 files changed

+85
-3
lines changed

3 files changed

+85
-3
lines changed

google/genai/tests/tunings/test_cancel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
pytest_helper.TestTableItem(
2424
name="test_cancel_vertex",
2525
parameters=genai_types._CancelTuningJobParameters(
26-
name="projects/801452371447/locations/us-central1/tuningJobs/6871785856412155904"
26+
name="projects/801452371447/locations/us-central1/tuningJobs/2470687341547618304"
2727
),
2828
exception_if_mldev="Not Found",
2929
),

google/genai/tunings.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,34 @@ def _CancelTuningJobParameters_to_vertex(
110110
return to_object
111111

112112

113+
def _CancelTuningJobResponse_from_mldev(
114+
from_object: Union[dict[str, Any], object],
115+
parent_object: Optional[dict[str, Any]] = None,
116+
root_object: Optional[Union[dict[str, Any], object]] = None,
117+
) -> dict[str, Any]:
118+
to_object: dict[str, Any] = {}
119+
if getv(from_object, ['sdkHttpResponse']) is not None:
120+
setv(
121+
to_object, ['sdk_http_response'], getv(from_object, ['sdkHttpResponse'])
122+
)
123+
124+
return to_object
125+
126+
127+
def _CancelTuningJobResponse_from_vertex(
128+
from_object: Union[dict[str, Any], object],
129+
parent_object: Optional[dict[str, Any]] = None,
130+
root_object: Optional[Union[dict[str, Any], object]] = None,
131+
) -> dict[str, Any]:
132+
to_object: dict[str, Any] = {}
133+
if getv(from_object, ['sdkHttpResponse']) is not None:
134+
setv(
135+
to_object, ['sdk_http_response'], getv(from_object, ['sdkHttpResponse'])
136+
)
137+
138+
return to_object
139+
140+
113141
def _CreateTuningJobConfig_to_mldev(
114142
from_object: Union[dict[str, Any], object],
115143
parent_object: Optional[dict[str, Any]] = None,
@@ -1310,7 +1338,7 @@ def cancel(
13101338
*,
13111339
name: str,
13121340
config: Optional[types.CancelTuningJobConfigOrDict] = None,
1313-
) -> None:
1341+
) -> types.CancelTuningJobResponse:
13141342
"""Cancels a tuning job.
13151343
13161344
Args:
@@ -1362,6 +1390,23 @@ def cancel(
13621390
'post', path, request_dict, http_options
13631391
)
13641392

1393+
response_dict = {} if not response.body else json.loads(response.body)
1394+
1395+
if self._api_client.vertexai:
1396+
response_dict = _CancelTuningJobResponse_from_vertex(response_dict)
1397+
1398+
if not self._api_client.vertexai:
1399+
response_dict = _CancelTuningJobResponse_from_mldev(response_dict)
1400+
1401+
return_value = types.CancelTuningJobResponse._from_response(
1402+
response=response_dict, kwargs=parameter_model.model_dump()
1403+
)
1404+
return_value.sdk_http_response = types.HttpResponse(
1405+
headers=response.headers
1406+
)
1407+
self._api_client._verify_response(return_value)
1408+
return return_value
1409+
13651410
def _tune(
13661411
self,
13671412
*,
@@ -1787,7 +1832,7 @@ async def cancel(
17871832
*,
17881833
name: str,
17891834
config: Optional[types.CancelTuningJobConfigOrDict] = None,
1790-
) -> None:
1835+
) -> types.CancelTuningJobResponse:
17911836
"""Cancels a tuning job asynchronously.
17921837
17931838
Args:
@@ -1839,6 +1884,23 @@ async def cancel(
18391884
'post', path, request_dict, http_options
18401885
)
18411886

1887+
response_dict = {} if not response.body else json.loads(response.body)
1888+
1889+
if self._api_client.vertexai:
1890+
response_dict = _CancelTuningJobResponse_from_vertex(response_dict)
1891+
1892+
if not self._api_client.vertexai:
1893+
response_dict = _CancelTuningJobResponse_from_mldev(response_dict)
1894+
1895+
return_value = types.CancelTuningJobResponse._from_response(
1896+
response=response_dict, kwargs=parameter_model.model_dump()
1897+
)
1898+
return_value.sdk_http_response = types.HttpResponse(
1899+
headers=response.headers
1900+
)
1901+
self._api_client._verify_response(return_value)
1902+
return return_value
1903+
18421904
async def _tune(
18431905
self,
18441906
*,

google/genai/types.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11869,6 +11869,26 @@ class _CancelTuningJobParametersDict(TypedDict, total=False):
1186911869
]
1187011870

1187111871

11872+
class CancelTuningJobResponse(_common.BaseModel):
11873+
"""Empty response for tunings.cancel method."""
11874+
11875+
sdk_http_response: Optional[HttpResponse] = Field(
11876+
default=None, description="""Used to retain the full HTTP response."""
11877+
)
11878+
11879+
11880+
class CancelTuningJobResponseDict(TypedDict, total=False):
11881+
"""Empty response for tunings.cancel method."""
11882+
11883+
sdk_http_response: Optional[HttpResponseDict]
11884+
"""Used to retain the full HTTP response."""
11885+
11886+
11887+
CancelTuningJobResponseOrDict = Union[
11888+
CancelTuningJobResponse, CancelTuningJobResponseDict
11889+
]
11890+
11891+
1187211892
class TuningExample(_common.BaseModel):
1187311893
"""A single example for tuning.
1187411894

0 commit comments

Comments
 (0)