From ddd328b8a809171d21fe46decd6f62e01992b55a Mon Sep 17 00:00:00 2001 From: Ayush Agrawal Date: Sat, 22 Nov 2025 11:15:50 -0800 Subject: [PATCH] feat: Support the cancel method in the C# SDK Tunings module PiperOrigin-RevId: 835639467 --- api-report/genai-node.api.md | 5 ++ api-report/genai-web.api.md | 5 ++ api-report/genai.api.md | 5 ++ src/converters/_tunings_converters.ts | 32 +++++++++++++ src/tunings.ts | 68 +++++++++++++++++++++------ src/types.ts | 6 +++ 6 files changed, 106 insertions(+), 15 deletions(-) diff --git a/api-report/genai-node.api.md b/api-report/genai-node.api.md index df5632065..e9d034d83 100644 --- a/api-report/genai-node.api.md +++ b/api-report/genai-node.api.md @@ -307,6 +307,11 @@ export interface CancelTuningJobParameters { name: string; } +// @public +export class CancelTuningJobResponse { + sdkHttpResponse?: HttpResponse; +} + // @public export interface Candidate { avgLogprobs?: number; diff --git a/api-report/genai-web.api.md b/api-report/genai-web.api.md index df5632065..e9d034d83 100644 --- a/api-report/genai-web.api.md +++ b/api-report/genai-web.api.md @@ -307,6 +307,11 @@ export interface CancelTuningJobParameters { name: string; } +// @public +export class CancelTuningJobResponse { + sdkHttpResponse?: HttpResponse; +} + // @public export interface Candidate { avgLogprobs?: number; diff --git a/api-report/genai.api.md b/api-report/genai.api.md index df5632065..e9d034d83 100644 --- a/api-report/genai.api.md +++ b/api-report/genai.api.md @@ -307,6 +307,11 @@ export interface CancelTuningJobParameters { name: string; } +// @public +export class CancelTuningJobResponse { + sdkHttpResponse?: HttpResponse; +} + // @public export interface Candidate { avgLogprobs?: number; diff --git a/src/converters/_tunings_converters.ts b/src/converters/_tunings_converters.ts index c446108a9..7a92b8215 100644 --- a/src/converters/_tunings_converters.ts +++ b/src/converters/_tunings_converters.ts @@ -38,6 +38,38 @@ export function cancelTuningJobParametersToVertex( return toObject; } +export function cancelTuningJobResponseFromMldev( + fromObject: types.CancelTuningJobResponse, + _rootObject?: unknown, +): Record { + const toObject: Record = {}; + + const fromSdkHttpResponse = common.getValueByPath(fromObject, [ + 'sdkHttpResponse', + ]); + if (fromSdkHttpResponse != null) { + common.setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse); + } + + return toObject; +} + +export function cancelTuningJobResponseFromVertex( + fromObject: types.CancelTuningJobResponse, + _rootObject?: unknown, +): Record { + const toObject: Record = {}; + + const fromSdkHttpResponse = common.getValueByPath(fromObject, [ + 'sdkHttpResponse', + ]); + if (fromSdkHttpResponse != null) { + common.setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse); + } + + return toObject; +} + export function createTuningJobConfigToMldev( fromObject: types.CreateTuningJobConfig, parentObject: Record, diff --git a/src/tunings.ts b/src/tunings.ts index 62df03722..9481c8254 100644 --- a/src/tunings.ts +++ b/src/tunings.ts @@ -280,7 +280,11 @@ export class Tunings extends BaseModule { * await ai.tunings.cancel({name: '...'}); // The server-generated resource name. * ``` */ - async cancel(params: types.CancelTuningJobParameters): Promise { + async cancel( + params: types.CancelTuningJobParameters, + ): Promise { + let response: Promise; + let path: string = ''; let queryParams: Record = {}; if (this.apiClient.isVertexAI()) { @@ -293,13 +297,30 @@ export class Tunings extends BaseModule { delete body['_url']; delete body['_query']; - await this.apiClient.request({ - path: path, - queryParams: queryParams, - body: JSON.stringify(body), - httpMethod: 'POST', - httpOptions: params.config?.httpOptions, - abortSignal: params.config?.abortSignal, + response = this.apiClient + .request({ + path: path, + queryParams: queryParams, + body: JSON.stringify(body), + httpMethod: 'POST', + httpOptions: params.config?.httpOptions, + abortSignal: params.config?.abortSignal, + }) + .then((httpResponse) => { + return httpResponse.json().then((jsonResponse) => { + const response = jsonResponse as types.CancelTuningJobResponse; + response.sdkHttpResponse = { + headers: httpResponse.headers, + } as types.HttpResponse; + return response; + }); + }) as Promise; + + return response.then((apiResponse) => { + const resp = converters.cancelTuningJobResponseFromVertex(apiResponse); + const typedResp = new types.CancelTuningJobResponse(); + Object.assign(typedResp, resp); + return typedResp; }); } else { const body = converters.cancelTuningJobParametersToMldev(params, params); @@ -311,13 +332,30 @@ export class Tunings extends BaseModule { delete body['_url']; delete body['_query']; - await this.apiClient.request({ - path: path, - queryParams: queryParams, - body: JSON.stringify(body), - httpMethod: 'POST', - httpOptions: params.config?.httpOptions, - abortSignal: params.config?.abortSignal, + response = this.apiClient + .request({ + path: path, + queryParams: queryParams, + body: JSON.stringify(body), + httpMethod: 'POST', + httpOptions: params.config?.httpOptions, + abortSignal: params.config?.abortSignal, + }) + .then((httpResponse) => { + return httpResponse.json().then((jsonResponse) => { + const response = jsonResponse as types.CancelTuningJobResponse; + response.sdkHttpResponse = { + headers: httpResponse.headers, + } as types.HttpResponse; + return response; + }); + }) as Promise; + + return response.then((apiResponse) => { + const resp = converters.cancelTuningJobResponseFromMldev(apiResponse); + const typedResp = new types.CancelTuningJobResponse(); + Object.assign(typedResp, resp); + return typedResp; }); } } diff --git a/src/types.ts b/src/types.ts index c69c2d200..3f48de4b3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4392,6 +4392,12 @@ export declare interface CancelTuningJobParameters { config?: CancelTuningJobConfig; } +/** Empty response for tunings.cancel method. */ +export class CancelTuningJobResponse { + /** Used to retain the full HTTP response. */ + sdkHttpResponse?: HttpResponse; +} + /** A single example for tuning. This data type is not supported in Vertex AI. */ export declare interface TuningExample { /** Required. The expected model output. */