Skip to content

Commit df5c849

Browse files
speedstorm1copybara-github
authored andcommitted
feat: Add empty response for tunings.cancel()
FUTURE_COPYBARA_INTEGRATE_REVIEW=#1090 from googleapis:release-please--branches--main--components--genai bbf62d2 PiperOrigin-RevId: 834522267
1 parent 38cac5b commit df5c849

File tree

3 files changed

+91
-15
lines changed

3 files changed

+91
-15
lines changed

src/converters/_tunings_converters.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,38 @@ export function cancelTuningJobParametersToVertex(
3838
return toObject;
3939
}
4040

41+
export function cancelTuningJobResponseFromMldev(
42+
fromObject: types.CancelTuningJobResponse,
43+
_rootObject?: unknown,
44+
): Record<string, unknown> {
45+
const toObject: Record<string, unknown> = {};
46+
47+
const fromSdkHttpResponse = common.getValueByPath(fromObject, [
48+
'sdkHttpResponse',
49+
]);
50+
if (fromSdkHttpResponse != null) {
51+
common.setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
52+
}
53+
54+
return toObject;
55+
}
56+
57+
export function cancelTuningJobResponseFromVertex(
58+
fromObject: types.CancelTuningJobResponse,
59+
_rootObject?: unknown,
60+
): Record<string, unknown> {
61+
const toObject: Record<string, unknown> = {};
62+
63+
const fromSdkHttpResponse = common.getValueByPath(fromObject, [
64+
'sdkHttpResponse',
65+
]);
66+
if (fromSdkHttpResponse != null) {
67+
common.setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
68+
}
69+
70+
return toObject;
71+
}
72+
4173
export function createTuningJobConfigToMldev(
4274
fromObject: types.CreateTuningJobConfig,
4375
parentObject: Record<string, unknown>,

src/tunings.ts

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,11 @@ export class Tunings extends BaseModule {
280280
* await ai.tunings.cancel({name: '...'}); // The server-generated resource name.
281281
* ```
282282
*/
283-
async cancel(params: types.CancelTuningJobParameters): Promise<void> {
283+
async cancel(
284+
params: types.CancelTuningJobParameters,
285+
): Promise<types.CancelTuningJobResponse> {
286+
let response: Promise<types.CancelTuningJobResponse>;
287+
284288
let path: string = '';
285289
let queryParams: Record<string, string> = {};
286290
if (this.apiClient.isVertexAI()) {
@@ -293,13 +297,30 @@ export class Tunings extends BaseModule {
293297
delete body['_url'];
294298
delete body['_query'];
295299

296-
await this.apiClient.request({
297-
path: path,
298-
queryParams: queryParams,
299-
body: JSON.stringify(body),
300-
httpMethod: 'POST',
301-
httpOptions: params.config?.httpOptions,
302-
abortSignal: params.config?.abortSignal,
300+
response = this.apiClient
301+
.request({
302+
path: path,
303+
queryParams: queryParams,
304+
body: JSON.stringify(body),
305+
httpMethod: 'POST',
306+
httpOptions: params.config?.httpOptions,
307+
abortSignal: params.config?.abortSignal,
308+
})
309+
.then((httpResponse) => {
310+
return httpResponse.json().then((jsonResponse) => {
311+
const response = jsonResponse as types.CancelTuningJobResponse;
312+
response.sdkHttpResponse = {
313+
headers: httpResponse.headers,
314+
} as types.HttpResponse;
315+
return response;
316+
});
317+
}) as Promise<types.CancelTuningJobResponse>;
318+
319+
return response.then((apiResponse) => {
320+
const resp = converters.cancelTuningJobResponseFromVertex(apiResponse);
321+
const typedResp = new types.CancelTuningJobResponse();
322+
Object.assign(typedResp, resp);
323+
return typedResp;
303324
});
304325
} else {
305326
const body = converters.cancelTuningJobParametersToMldev(params, params);
@@ -311,13 +332,30 @@ export class Tunings extends BaseModule {
311332
delete body['_url'];
312333
delete body['_query'];
313334

314-
await this.apiClient.request({
315-
path: path,
316-
queryParams: queryParams,
317-
body: JSON.stringify(body),
318-
httpMethod: 'POST',
319-
httpOptions: params.config?.httpOptions,
320-
abortSignal: params.config?.abortSignal,
335+
response = this.apiClient
336+
.request({
337+
path: path,
338+
queryParams: queryParams,
339+
body: JSON.stringify(body),
340+
httpMethod: 'POST',
341+
httpOptions: params.config?.httpOptions,
342+
abortSignal: params.config?.abortSignal,
343+
})
344+
.then((httpResponse) => {
345+
return httpResponse.json().then((jsonResponse) => {
346+
const response = jsonResponse as types.CancelTuningJobResponse;
347+
response.sdkHttpResponse = {
348+
headers: httpResponse.headers,
349+
} as types.HttpResponse;
350+
return response;
351+
});
352+
}) as Promise<types.CancelTuningJobResponse>;
353+
354+
return response.then((apiResponse) => {
355+
const resp = converters.cancelTuningJobResponseFromMldev(apiResponse);
356+
const typedResp = new types.CancelTuningJobResponse();
357+
Object.assign(typedResp, resp);
358+
return typedResp;
321359
});
322360
}
323361
}

src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4389,6 +4389,12 @@ export declare interface CancelTuningJobParameters {
43894389
config?: CancelTuningJobConfig;
43904390
}
43914391

4392+
/** Empty response for tunings.cancel method. */
4393+
export class CancelTuningJobResponse {
4394+
/** Used to retain the full HTTP response. */
4395+
sdkHttpResponse?: HttpResponse;
4396+
}
4397+
43924398
/** A single example for tuning. This data type is not supported in Vertex AI. */
43934399
export declare interface TuningExample {
43944400
/** Required. The expected model output. */

0 commit comments

Comments
 (0)