// This file was auto-generated by Fern from our API Definition.

import * as Cohere from "../../src/api/index";
import { CohereClient } from "../../src/Client";
import { mockServerPool } from "../mock-server/MockServerPool";

describe("Finetuning", () => {
    test("ListFinetunedModels (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = {
            finetuned_models: [
                {
                    id: "fee37446-7fc7-42f9-a026-c6ba2fcc422d",
                    name: "chat-ft",
                    creator_id: "7a317d97-4d05-427d-9396-f31b9fb92c55",
                    organization_id: "6bdca3d5-3eae-4de0-ac34-786d8063b7ee",
                    settings: {
                        base_model: {
                            name: "medium",
                            version: "14.2.0",
                            base_type: "BASE_TYPE_CHAT",
                            strategy: "STRATEGY_TFEW",
                        },
                        dataset_id: "my-dataset-d701tr",
                        hyperparameters: {
                            early_stopping_patience: 6,
                            early_stopping_threshold: 0.01,
                            train_batch_size: 16,
                            train_epochs: 1,
                            learning_rate: 0.01,
                        },
                    },
                    status: "STATUS_READY",
                    created_at: "2024-01-17T20:11:42Z",
                    updated_at: "2024-01-17T20:31:06Z",
                    completed_at: "2024-01-17T20:31:05Z",
                    last_used: "2024-01-15T09:30:00Z",
                },
                {
                    id: "9d927c5e-7598-4772-98b7-cdf2014e8874",
                    name: "rerank-ft",
                    creator_id: "7a317d97-4d05-427d-9396-f31b9fb92c55",
                    organization_id: "6bdca3d5-3eae-4de0-ac34-786d8063b7ee",
                    settings: {
                        base_model: {
                            name: "english",
                            version: "2.0.0",
                            base_type: "BASE_TYPE_RERANK",
                            strategy: "STRATEGY_VANILLA",
                        },
                        dataset_id: "rerank-dataset-d820xf",
                    },
                    status: "STATUS_READY",
                    created_at: "2024-01-17T20:17:16Z",
                    updated_at: "2024-01-17T20:50:11Z",
                    completed_at: "2024-01-17T20:42:55Z",
                    last_used: "2024-01-15T09:30:00Z",
                },
            ],
            next_page_token: "next_page_token",
            total_size: 1,
        };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.finetuning.listFinetunedModels({
            pageSize: 1,
            pageToken: "page_token",
            orderBy: "order_by",
        });
        expect(response).toEqual({
            finetunedModels: [
                {
                    id: "fee37446-7fc7-42f9-a026-c6ba2fcc422d",
                    name: "chat-ft",
                    creatorId: "7a317d97-4d05-427d-9396-f31b9fb92c55",
                    organizationId: "6bdca3d5-3eae-4de0-ac34-786d8063b7ee",
                    settings: {
                        baseModel: {
                            name: "medium",
                            version: "14.2.0",
                            baseType: "BASE_TYPE_CHAT",
                            strategy: "STRATEGY_TFEW",
                        },
                        datasetId: "my-dataset-d701tr",
                        hyperparameters: {
                            earlyStoppingPatience: 6,
                            earlyStoppingThreshold: 0.01,
                            trainBatchSize: 16,
                            trainEpochs: 1,
                            learningRate: 0.01,
                        },
                    },
                    status: "STATUS_READY",
                    createdAt: new Date("2024-01-17T20:11:42.000Z"),
                    updatedAt: new Date("2024-01-17T20:31:06.000Z"),
                    completedAt: new Date("2024-01-17T20:31:05.000Z"),
                    lastUsed: new Date("2024-01-15T09:30:00.000Z"),
                },
                {
                    id: "9d927c5e-7598-4772-98b7-cdf2014e8874",
                    name: "rerank-ft",
                    creatorId: "7a317d97-4d05-427d-9396-f31b9fb92c55",
                    organizationId: "6bdca3d5-3eae-4de0-ac34-786d8063b7ee",
                    settings: {
                        baseModel: {
                            name: "english",
                            version: "2.0.0",
                            baseType: "BASE_TYPE_RERANK",
                            strategy: "STRATEGY_VANILLA",
                        },
                        datasetId: "rerank-dataset-d820xf",
                    },
                    status: "STATUS_READY",
                    createdAt: new Date("2024-01-17T20:17:16.000Z"),
                    updatedAt: new Date("2024-01-17T20:50:11.000Z"),
                    completedAt: new Date("2024-01-17T20:42:55.000Z"),
                    lastUsed: new Date("2024-01-15T09:30:00.000Z"),
                },
            ],
            nextPageToken: "next_page_token",
            totalSize: 1,
        });
    });

    test("ListFinetunedModels (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models")
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listFinetunedModels();
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("ListFinetunedModels (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listFinetunedModels();
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("ListFinetunedModels (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models")
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listFinetunedModels();
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("ListFinetunedModels (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listFinetunedModels();
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("ListFinetunedModels (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models")
            .respondWith()
            .statusCode(500)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listFinetunedModels();
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("ListFinetunedModels (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models")
            .respondWith()
            .statusCode(503)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listFinetunedModels();
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("CreateFinetunedModel (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = {
            finetuned_model: {
                id: "id",
                name: "name",
                creator_id: "creator_id",
                organization_id: "organization_id",
                settings: {
                    base_model: { base_type: "BASE_TYPE_UNSPECIFIED" },
                    dataset_id: "dataset_id",
                    multi_label: true,
                    wandb: { project: "project", api_key: "api_key" },
                },
                status: "STATUS_UNSPECIFIED",
                created_at: "2024-01-15T09:30:00Z",
                updated_at: "2024-01-15T09:30:00Z",
                completed_at: "2024-01-15T09:30:00Z",
                last_used: "2024-01-15T09:30:00Z",
            },
        };
        server
            .mockEndpoint()
            .post("/v1/finetuning/finetuned-models")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.finetuning.createFinetunedModel({
            name: "name",
            settings: {
                baseModel: {
                    baseType: "BASE_TYPE_UNSPECIFIED",
                },
                datasetId: "dataset_id",
            },
        });
        expect(response).toEqual({
            finetunedModel: {
                id: "id",
                name: "name",
                creatorId: "creator_id",
                organizationId: "organization_id",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                    multiLabel: true,
                    wandb: {
                        project: "project",
                        apiKey: "api_key",
                    },
                },
                status: "STATUS_UNSPECIFIED",
                createdAt: new Date("2024-01-15T09:30:00.000Z"),
                updatedAt: new Date("2024-01-15T09:30:00.000Z"),
                completedAt: new Date("2024-01-15T09:30:00.000Z"),
                lastUsed: new Date("2024-01-15T09:30:00.000Z"),
            },
        });
    });

    test("CreateFinetunedModel (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/finetuning/finetuned-models")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.createFinetunedModel({
                name: "name",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                },
            });
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("CreateFinetunedModel (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/finetuning/finetuned-models")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.createFinetunedModel({
                name: "name",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                },
            });
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("CreateFinetunedModel (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/finetuning/finetuned-models")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.createFinetunedModel({
                name: "name",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                },
            });
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("CreateFinetunedModel (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/finetuning/finetuned-models")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.createFinetunedModel({
                name: "name",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                },
            });
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("CreateFinetunedModel (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/finetuning/finetuned-models")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(500)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.createFinetunedModel({
                name: "name",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                },
            });
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("CreateFinetunedModel (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v1/finetuning/finetuned-models")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(503)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.createFinetunedModel({
                name: "name",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                },
            });
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("GetFinetunedModel (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = {
            finetuned_model: {
                id: "fee37446-7fc7-42f9-a026-c6ba2fcc422d",
                name: "chat-ft",
                creator_id: "7a317d97-4d05-427d-9396-f31b9fb92c55",
                organization_id: "6bdca3d5-3eae-4de0-ac34-786d8063b7ee",
                settings: {
                    base_model: {
                        name: "medium",
                        version: "14.2.0",
                        base_type: "BASE_TYPE_CHAT",
                        strategy: "STRATEGY_TFEW",
                    },
                    dataset_id: "my-dataset-d701tr",
                    hyperparameters: {
                        early_stopping_patience: 6,
                        early_stopping_threshold: 0.01,
                        train_batch_size: 16,
                        train_epochs: 1,
                        learning_rate: 0.01,
                    },
                    multi_label: true,
                    wandb: { project: "project", api_key: "api_key" },
                },
                status: "STATUS_READY",
                created_at: "2024-01-17T20:11:42Z",
                updated_at: "2024-01-17T20:31:06Z",
                completed_at: "2024-01-17T20:31:05Z",
                last_used: "2024-01-15T09:30:00Z",
            },
        };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.finetuning.getFinetunedModel("id");
        expect(response).toEqual({
            finetunedModel: {
                id: "fee37446-7fc7-42f9-a026-c6ba2fcc422d",
                name: "chat-ft",
                creatorId: "7a317d97-4d05-427d-9396-f31b9fb92c55",
                organizationId: "6bdca3d5-3eae-4de0-ac34-786d8063b7ee",
                settings: {
                    baseModel: {
                        name: "medium",
                        version: "14.2.0",
                        baseType: "BASE_TYPE_CHAT",
                        strategy: "STRATEGY_TFEW",
                    },
                    datasetId: "my-dataset-d701tr",
                    hyperparameters: {
                        earlyStoppingPatience: 6,
                        earlyStoppingThreshold: 0.01,
                        trainBatchSize: 16,
                        trainEpochs: 1,
                        learningRate: 0.01,
                    },
                    multiLabel: true,
                    wandb: {
                        project: "project",
                        apiKey: "api_key",
                    },
                },
                status: "STATUS_READY",
                createdAt: new Date("2024-01-17T20:11:42.000Z"),
                updatedAt: new Date("2024-01-17T20:31:06.000Z"),
                completedAt: new Date("2024-01-17T20:31:05.000Z"),
                lastUsed: new Date("2024-01-15T09:30:00.000Z"),
            },
        });
    });

    test("GetFinetunedModel (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.getFinetunedModel("id");
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("GetFinetunedModel (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.getFinetunedModel("id");
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("GetFinetunedModel (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.getFinetunedModel("id");
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("GetFinetunedModel (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.getFinetunedModel("id");
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("GetFinetunedModel (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(500)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.getFinetunedModel("id");
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("GetFinetunedModel (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(503)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.getFinetunedModel("id");
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("DeleteFinetunedModel (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.finetuning.deleteFinetunedModel("id");
        expect(response).toEqual({
            key: "value",
        });
    });

    test("DeleteFinetunedModel (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.deleteFinetunedModel("id");
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("DeleteFinetunedModel (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.deleteFinetunedModel("id");
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("DeleteFinetunedModel (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.deleteFinetunedModel("id");
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("DeleteFinetunedModel (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.deleteFinetunedModel("id");
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("DeleteFinetunedModel (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(500)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.deleteFinetunedModel("id");
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("DeleteFinetunedModel (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .delete("/v1/finetuning/finetuned-models/id")
            .respondWith()
            .statusCode(503)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.deleteFinetunedModel("id");
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("UpdateFinetunedModel (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = {
            finetuned_model: {
                id: "id",
                name: "name",
                creator_id: "creator_id",
                organization_id: "organization_id",
                settings: {
                    base_model: { base_type: "BASE_TYPE_UNSPECIFIED" },
                    dataset_id: "dataset_id",
                    multi_label: true,
                    wandb: { project: "project", api_key: "api_key" },
                },
                status: "STATUS_UNSPECIFIED",
                created_at: "2024-01-15T09:30:00Z",
                updated_at: "2024-01-15T09:30:00Z",
                completed_at: "2024-01-15T09:30:00Z",
                last_used: "2024-01-15T09:30:00Z",
            },
        };
        server
            .mockEndpoint()
            .patch("/v1/finetuning/finetuned-models/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.finetuning.updateFinetunedModel("id", {
            name: "name",
            settings: {
                baseModel: {
                    baseType: "BASE_TYPE_UNSPECIFIED",
                },
                datasetId: "dataset_id",
            },
        });
        expect(response).toEqual({
            finetunedModel: {
                id: "id",
                name: "name",
                creatorId: "creator_id",
                organizationId: "organization_id",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                    multiLabel: true,
                    wandb: {
                        project: "project",
                        apiKey: "api_key",
                    },
                },
                status: "STATUS_UNSPECIFIED",
                createdAt: new Date("2024-01-15T09:30:00.000Z"),
                updatedAt: new Date("2024-01-15T09:30:00.000Z"),
                completedAt: new Date("2024-01-15T09:30:00.000Z"),
                lastUsed: new Date("2024-01-15T09:30:00.000Z"),
            },
        });
    });

    test("UpdateFinetunedModel (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/finetuning/finetuned-models/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.updateFinetunedModel("id", {
                name: "name",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                },
            });
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("UpdateFinetunedModel (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/finetuning/finetuned-models/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.updateFinetunedModel("id", {
                name: "name",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                },
            });
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("UpdateFinetunedModel (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/finetuning/finetuned-models/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.updateFinetunedModel("id", {
                name: "name",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                },
            });
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("UpdateFinetunedModel (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/finetuning/finetuned-models/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.updateFinetunedModel("id", {
                name: "name",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                },
            });
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("UpdateFinetunedModel (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/finetuning/finetuned-models/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(500)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.updateFinetunedModel("id", {
                name: "name",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                },
            });
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("UpdateFinetunedModel (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = {
            name: "name",
            settings: { base_model: { base_type: "BASE_TYPE_UNSPECIFIED" }, dataset_id: "dataset_id" },
        };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .patch("/v1/finetuning/finetuned-models/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(503)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.updateFinetunedModel("id", {
                name: "name",
                settings: {
                    baseModel: {
                        baseType: "BASE_TYPE_UNSPECIFIED",
                    },
                    datasetId: "dataset_id",
                },
            });
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("ListEvents (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = {
            events: [
                {
                    user_id: "7a317d97-4d05-427d-9396-f31b9fb92c55",
                    status: "STATUS_QUEUED",
                    created_at: "2024-01-17T20:11:45Z",
                },
                {
                    user_id: "7a317d97-4d05-427d-9396-f31b9fb92c55",
                    status: "STATUS_FINETUNING",
                    created_at: "2024-01-17T20:11:46Z",
                },
                {
                    user_id: "7a317d97-4d05-427d-9396-f31b9fb92c55",
                    status: "STATUS_DEPLOYING_API",
                    created_at: "2024-01-17T20:31:05Z",
                },
                { user_id: "user_id", status: "STATUS_READY", created_at: "2024-01-17T20:31:06Z" },
            ],
            next_page_token: "next_page_token",
            total_size: 5,
        };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/events")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.finetuning.listEvents("finetuned_model_id", {
            pageSize: 1,
            pageToken: "page_token",
            orderBy: "order_by",
        });
        expect(response).toEqual({
            events: [
                {
                    userId: "7a317d97-4d05-427d-9396-f31b9fb92c55",
                    status: "STATUS_QUEUED",
                    createdAt: new Date("2024-01-17T20:11:45.000Z"),
                },
                {
                    userId: "7a317d97-4d05-427d-9396-f31b9fb92c55",
                    status: "STATUS_FINETUNING",
                    createdAt: new Date("2024-01-17T20:11:46.000Z"),
                },
                {
                    userId: "7a317d97-4d05-427d-9396-f31b9fb92c55",
                    status: "STATUS_DEPLOYING_API",
                    createdAt: new Date("2024-01-17T20:31:05.000Z"),
                },
                {
                    userId: "user_id",
                    status: "STATUS_READY",
                    createdAt: new Date("2024-01-17T20:31:06.000Z"),
                },
            ],
            nextPageToken: "next_page_token",
            totalSize: 5,
        });
    });

    test("ListEvents (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/events")
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listEvents("finetuned_model_id");
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("ListEvents (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/events")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listEvents("finetuned_model_id");
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("ListEvents (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/events")
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listEvents("finetuned_model_id");
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("ListEvents (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/events")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listEvents("finetuned_model_id");
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("ListEvents (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/events")
            .respondWith()
            .statusCode(500)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listEvents("finetuned_model_id");
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("ListEvents (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/events")
            .respondWith()
            .statusCode(503)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listEvents("finetuned_model_id");
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("ListTrainingStepMetrics (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = {
            step_metrics: [
                {
                    created_at: "2024-01-17T20:24:26Z",
                    step_number: 1,
                    metrics: {
                        accuracy: 0.4557601809501648,
                        cross_entropy: 4.264331340789795,
                        generation_accuracy: 0.4557601809501648,
                        generation_cross_entropy: 4.264331340789795,
                        step: 0,
                    },
                },
                {
                    created_at: "2024-01-17T20:25:19Z",
                    step_number: 9,
                    metrics: {
                        accuracy: 0.7393720149993896,
                        cross_entropy: 0.7702581286430359,
                        generation_accuracy: 0.7393720149993896,
                        generation_cross_entropy: 0.7702581286430359,
                        step: 9,
                    },
                },
            ],
            next_page_token: "next_page_token",
        };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/training-step-metrics")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.finetuning.listTrainingStepMetrics("finetuned_model_id", {
            pageSize: 1,
            pageToken: "page_token",
        });
        expect(response).toEqual({
            stepMetrics: [
                {
                    createdAt: new Date("2024-01-17T20:24:26.000Z"),
                    stepNumber: 1,
                    metrics: {
                        accuracy: 0.4557601809501648,
                        cross_entropy: 4.264331340789795,
                        generation_accuracy: 0.4557601809501648,
                        generation_cross_entropy: 4.264331340789795,
                        step: 0,
                    },
                },
                {
                    createdAt: new Date("2024-01-17T20:25:19.000Z"),
                    stepNumber: 9,
                    metrics: {
                        accuracy: 0.7393720149993896,
                        cross_entropy: 0.7702581286430359,
                        generation_accuracy: 0.7393720149993896,
                        generation_cross_entropy: 0.7702581286430359,
                        step: 9,
                    },
                },
            ],
            nextPageToken: "next_page_token",
        });
    });

    test("ListTrainingStepMetrics (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/training-step-metrics")
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listTrainingStepMetrics("finetuned_model_id");
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("ListTrainingStepMetrics (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/training-step-metrics")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listTrainingStepMetrics("finetuned_model_id");
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("ListTrainingStepMetrics (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/training-step-metrics")
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listTrainingStepMetrics("finetuned_model_id");
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("ListTrainingStepMetrics (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/training-step-metrics")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listTrainingStepMetrics("finetuned_model_id");
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("ListTrainingStepMetrics (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/training-step-metrics")
            .respondWith()
            .statusCode(500)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listTrainingStepMetrics("finetuned_model_id");
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("ListTrainingStepMetrics (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/v1/finetuning/finetuned-models/finetuned_model_id/training-step-metrics")
            .respondWith()
            .statusCode(503)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.finetuning.listTrainingStepMetrics("finetuned_model_id");
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });
});
