"use strict";
// This file was auto-generated by Fern from our API Definition.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Finetuning = void 0;
const core = __importStar(require("../../../../core"));
const headers_1 = require("../../../../core/headers");
const environments = __importStar(require("../../../../environments"));
const errors = __importStar(require("../../../../errors/index"));
const serializers = __importStar(require("../../../../serialization/index"));
const Cohere = __importStar(require("../../../index"));
/**
 * Finetuning API (Beta)
 */
class Finetuning {
    constructor(_options = {}) {
        this._options = _options;
    }
    /**
     * Returns a list of fine-tuned models that the user has access to.
     *
     * @param {Cohere.FinetuningListFinetunedModelsRequest} request
     * @param {Finetuning.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.ServiceUnavailableError}
     *
     * @example
     *     await client.finetuning.listFinetunedModels({
     *         pageSize: 1,
     *         pageToken: "page_token",
     *         orderBy: "order_by"
     *     })
     */
    listFinetunedModels(request = {}, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__listFinetunedModels(request, requestOptions));
    }
    __listFinetunedModels() {
        return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const { pageSize, pageToken, orderBy } = request;
            const _queryParams = {};
            if (pageSize != null) {
                _queryParams.page_size = pageSize.toString();
            }
            if (pageToken != null) {
                _queryParams.page_token = pageToken;
            }
            if (orderBy != null) {
                _queryParams.order_by = orderBy;
            }
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, "v1/finetuning/finetuned-models"),
                method: "GET",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.finetuning.ListFinetunedModelsResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling GET /v1/finetuning/finetuned-models.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Creates a new fine-tuned model. The model will be trained on the dataset specified in the request body. The training process may take some time, and the model will be available once the training is complete.
     *
     * @param {Cohere.finetuning.FinetunedModel} request
     * @param {Finetuning.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.ServiceUnavailableError}
     *
     * @example
     *     await client.finetuning.createFinetunedModel({
     *         name: "name",
     *         settings: {
     *             baseModel: {
     *                 baseType: "BASE_TYPE_UNSPECIFIED"
     *             },
     *             datasetId: "dataset_id"
     *         }
     *     })
     */
    createFinetunedModel(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__createFinetunedModel(request, requestOptions));
    }
    __createFinetunedModel(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, "v1/finetuning/finetuned-models"),
                method: "POST",
                headers: _headers,
                contentType: "application/json",
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                requestType: "json",
                body: serializers.finetuning.FinetunedModel.jsonOrThrow(request, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                }),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.finetuning.CreateFinetunedModelResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling POST /v1/finetuning/finetuned-models.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Retrieve a fine-tuned model by its ID.
     *
     * @param {string} id - The fine-tuned model ID.
     * @param {Finetuning.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.ServiceUnavailableError}
     *
     * @example
     *     await client.finetuning.getFinetunedModel("id")
     */
    getFinetunedModel(id, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__getFinetunedModel(id, requestOptions));
    }
    __getFinetunedModel(id, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, `v1/finetuning/finetuned-models/${core.url.encodePathParam(id)}`),
                method: "GET",
                headers: _headers,
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.finetuning.GetFinetunedModelResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling GET /v1/finetuning/finetuned-models/{id}.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Deletes a fine-tuned model. The model will be removed from the system and will no longer be available for use.
     * This operation is irreversible.
     *
     * @param {string} id - The fine-tuned model ID.
     * @param {Finetuning.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.ServiceUnavailableError}
     *
     * @example
     *     await client.finetuning.deleteFinetunedModel("id")
     */
    deleteFinetunedModel(id, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__deleteFinetunedModel(id, requestOptions));
    }
    __deleteFinetunedModel(id, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, `v1/finetuning/finetuned-models/${core.url.encodePathParam(id)}`),
                method: "DELETE",
                headers: _headers,
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.finetuning.DeleteFinetunedModelResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling DELETE /v1/finetuning/finetuned-models/{id}.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Updates the fine-tuned model with the given ID. The model will be updated with the new settings and name provided in the request body.
     *
     * @param {string} id - FinetunedModel ID.
     * @param {Cohere.FinetuningUpdateFinetunedModelRequest} request
     * @param {Finetuning.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.ServiceUnavailableError}
     *
     * @example
     *     await client.finetuning.updateFinetunedModel("id", {
     *         name: "name",
     *         settings: {
     *             baseModel: {
     *                 baseType: "BASE_TYPE_UNSPECIFIED"
     *             },
     *             datasetId: "dataset_id"
     *         }
     *     })
     */
    updateFinetunedModel(id, request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__updateFinetunedModel(id, request, requestOptions));
    }
    __updateFinetunedModel(id, request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, `v1/finetuning/finetuned-models/${core.url.encodePathParam(id)}`),
                method: "PATCH",
                headers: _headers,
                contentType: "application/json",
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                requestType: "json",
                body: serializers.FinetuningUpdateFinetunedModelRequest.jsonOrThrow(request, {
                    unrecognizedObjectKeys: "passthrough",
                    allowUnrecognizedUnionMembers: true,
                    allowUnrecognizedEnumValues: true,
                }),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.finetuning.UpdateFinetunedModelResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling PATCH /v1/finetuning/finetuned-models/{id}.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Returns a list of events that occurred during the life-cycle of the fine-tuned model.
     * The events are ordered by creation time, with the most recent event first.
     * The list can be paginated using `page_size` and `page_token` parameters.
     *
     * @param {string} finetunedModelId - The parent fine-tuned model ID.
     * @param {Cohere.FinetuningListEventsRequest} request
     * @param {Finetuning.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.ServiceUnavailableError}
     *
     * @example
     *     await client.finetuning.listEvents("finetuned_model_id", {
     *         pageSize: 1,
     *         pageToken: "page_token",
     *         orderBy: "order_by"
     *     })
     */
    listEvents(finetunedModelId, request = {}, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__listEvents(finetunedModelId, request, requestOptions));
    }
    __listEvents(finetunedModelId_1) {
        return __awaiter(this, arguments, void 0, function* (finetunedModelId, request = {}, requestOptions) {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const { pageSize, pageToken, orderBy } = request;
            const _queryParams = {};
            if (pageSize != null) {
                _queryParams.page_size = pageSize.toString();
            }
            if (pageToken != null) {
                _queryParams.page_token = pageToken;
            }
            if (orderBy != null) {
                _queryParams.order_by = orderBy;
            }
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, `v1/finetuning/finetuned-models/${core.url.encodePathParam(finetunedModelId)}/events`),
                method: "GET",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.finetuning.ListEventsResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling GET /v1/finetuning/finetuned-models/{finetuned_model_id}/events.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    /**
     * Returns a list of metrics measured during the training of a fine-tuned model.
     * The metrics are ordered by step number, with the most recent step first.
     * The list can be paginated using `page_size` and `page_token` parameters.
     *
     * @param {string} finetunedModelId - The parent fine-tuned model ID.
     * @param {Cohere.FinetuningListTrainingStepMetricsRequest} request
     * @param {Finetuning.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link Cohere.BadRequestError}
     * @throws {@link Cohere.UnauthorizedError}
     * @throws {@link Cohere.ForbiddenError}
     * @throws {@link Cohere.NotFoundError}
     * @throws {@link Cohere.InternalServerError}
     * @throws {@link Cohere.ServiceUnavailableError}
     *
     * @example
     *     await client.finetuning.listTrainingStepMetrics("finetuned_model_id", {
     *         pageSize: 1,
     *         pageToken: "page_token"
     *     })
     */
    listTrainingStepMetrics(finetunedModelId, request = {}, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__listTrainingStepMetrics(finetunedModelId, request, requestOptions));
    }
    __listTrainingStepMetrics(finetunedModelId_1) {
        return __awaiter(this, arguments, void 0, function* (finetunedModelId, request = {}, requestOptions) {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const { pageSize, pageToken } = request;
            const _queryParams = {};
            if (pageSize != null) {
                _queryParams.page_size = pageSize.toString();
            }
            if (pageToken != null) {
                _queryParams.page_token = pageToken;
            }
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({
                Authorization: yield this._getAuthorizationHeader(),
                "X-Client-Name": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.clientName) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.clientName,
            }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.CohereEnvironment.Production, `v1/finetuning/finetuned-models/${core.url.encodePathParam(finetunedModelId)}/training-step-metrics`),
                method: "GET",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 300) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.finetuning.ListTrainingStepMetricsResponse.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        skipValidation: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 400:
                        throw new Cohere.BadRequestError(_response.error.body, _response.rawResponse);
                    case 401:
                        throw new Cohere.UnauthorizedError(_response.error.body, _response.rawResponse);
                    case 403:
                        throw new Cohere.ForbiddenError(_response.error.body, _response.rawResponse);
                    case 404:
                        throw new Cohere.NotFoundError(_response.error.body, _response.rawResponse);
                    case 500:
                        throw new Cohere.InternalServerError(_response.error.body, _response.rawResponse);
                    case 503:
                        throw new Cohere.ServiceUnavailableError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.CohereError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            switch (_response.error.reason) {
                case "non-json":
                    throw new errors.CohereError({
                        statusCode: _response.error.statusCode,
                        body: _response.error.rawBody,
                        rawResponse: _response.rawResponse,
                    });
                case "timeout":
                    throw new errors.CohereTimeoutError("Timeout exceeded when calling GET /v1/finetuning/finetuned-models/{finetuned_model_id}/training-step-metrics.");
                case "unknown":
                    throw new errors.CohereError({
                        message: _response.error.errorMessage,
                        rawResponse: _response.rawResponse,
                    });
            }
        });
    }
    _getAuthorizationHeader() {
        return __awaiter(this, void 0, void 0, function* () {
            var _a;
            const bearer = (_a = (yield core.Supplier.get(this._options.token))) !== null && _a !== void 0 ? _a : process === null || process === void 0 ? void 0 : process.env.CO_API_KEY;
            if (bearer != null) {
                return `Bearer ${bearer}`;
            }
            return undefined;
        });
    }
}
exports.Finetuning = Finetuning;
