/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: 13621d169943
 */

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { smartUnion } from "../../types/smartUnion.js";
import {
  ClassifierTarget,
  ClassifierTarget$Outbound,
  ClassifierTarget$outboundSchema,
} from "./classifiertarget.js";
import {
  ClassifierTrainingParameters,
  ClassifierTrainingParameters$Outbound,
  ClassifierTrainingParameters$outboundSchema,
} from "./classifiertrainingparameters.js";
import {
  CompletionTrainingParameters,
  CompletionTrainingParameters$Outbound,
  CompletionTrainingParameters$outboundSchema,
} from "./completiontrainingparameters.js";
import {
  CreateGithubRepositoryRequest,
  CreateGithubRepositoryRequest$Outbound,
  CreateGithubRepositoryRequest$outboundSchema,
} from "./creategithubrepositoryrequest.js";
import {
  FineTuneableModelType,
  FineTuneableModelType$outboundSchema,
} from "./finetuneablemodeltype.js";
import {
  TrainingFile,
  TrainingFile$Outbound,
  TrainingFile$outboundSchema,
} from "./trainingfile.js";
import {
  WandbIntegration,
  WandbIntegration$Outbound,
  WandbIntegration$outboundSchema,
} from "./wandbintegration.js";

export type CreateFineTuningJobRequestIntegration = WandbIntegration;

export type Hyperparameters =
  | CompletionTrainingParameters
  | ClassifierTrainingParameters;

export type CreateFineTuningJobRequestRepository =
  CreateGithubRepositoryRequest;

export type CreateFineTuningJobRequest = {
  model: string;
  trainingFiles?: Array<TrainingFile> | undefined;
  /**
   * A list containing the IDs of uploaded files that contain validation data. If you provide these files, the data is used to generate validation metrics periodically during fine-tuning. These metrics can be viewed in `checkpoints` when getting the status of a running fine-tuning job. The same data should not be present in both train and validation files.
   */
  validationFiles?: Array<string> | null | undefined;
  /**
   * A string that will be added to your fine-tuning model name. For example, a suffix of "my-great-model" would produce a model name like `ft:open-mistral-7b:my-great-model:xxx...`
   */
  suffix?: string | null | undefined;
  /**
   * A list of integrations to enable for your fine-tuning job.
   */
  integrations?: Array<WandbIntegration> | null | undefined;
  /**
   * This field will be required in a future release.
   */
  autoStart?: boolean | undefined;
  invalidSampleSkipPercentage?: number | undefined;
  jobType?: FineTuneableModelType | null | undefined;
  hyperparameters: CompletionTrainingParameters | ClassifierTrainingParameters;
  repositories?: Array<CreateGithubRepositoryRequest> | null | undefined;
  classifierTargets?: Array<ClassifierTarget> | null | undefined;
};

/** @internal */
export type CreateFineTuningJobRequestIntegration$Outbound =
  WandbIntegration$Outbound;

/** @internal */
export const CreateFineTuningJobRequestIntegration$outboundSchema: z.ZodType<
  CreateFineTuningJobRequestIntegration$Outbound,
  CreateFineTuningJobRequestIntegration
> = WandbIntegration$outboundSchema;

export function createFineTuningJobRequestIntegrationToJSON(
  createFineTuningJobRequestIntegration: CreateFineTuningJobRequestIntegration,
): string {
  return JSON.stringify(
    CreateFineTuningJobRequestIntegration$outboundSchema.parse(
      createFineTuningJobRequestIntegration,
    ),
  );
}

/** @internal */
export type Hyperparameters$Outbound =
  | CompletionTrainingParameters$Outbound
  | ClassifierTrainingParameters$Outbound;

/** @internal */
export const Hyperparameters$outboundSchema: z.ZodType<
  Hyperparameters$Outbound,
  Hyperparameters
> = smartUnion([
  CompletionTrainingParameters$outboundSchema,
  ClassifierTrainingParameters$outboundSchema,
]);

export function hyperparametersToJSON(
  hyperparameters: Hyperparameters,
): string {
  return JSON.stringify(Hyperparameters$outboundSchema.parse(hyperparameters));
}

/** @internal */
export type CreateFineTuningJobRequestRepository$Outbound =
  CreateGithubRepositoryRequest$Outbound;

/** @internal */
export const CreateFineTuningJobRequestRepository$outboundSchema: z.ZodType<
  CreateFineTuningJobRequestRepository$Outbound,
  CreateFineTuningJobRequestRepository
> = CreateGithubRepositoryRequest$outboundSchema;

export function createFineTuningJobRequestRepositoryToJSON(
  createFineTuningJobRequestRepository: CreateFineTuningJobRequestRepository,
): string {
  return JSON.stringify(
    CreateFineTuningJobRequestRepository$outboundSchema.parse(
      createFineTuningJobRequestRepository,
    ),
  );
}

/** @internal */
export type CreateFineTuningJobRequest$Outbound = {
  model: string;
  training_files?: Array<TrainingFile$Outbound> | undefined;
  validation_files?: Array<string> | null | undefined;
  suffix?: string | null | undefined;
  integrations?: Array<WandbIntegration$Outbound> | null | undefined;
  auto_start?: boolean | undefined;
  invalid_sample_skip_percentage: number;
  job_type?: string | null | undefined;
  hyperparameters:
    | CompletionTrainingParameters$Outbound
    | ClassifierTrainingParameters$Outbound;
  repositories?:
    | Array<CreateGithubRepositoryRequest$Outbound>
    | null
    | undefined;
  classifier_targets?: Array<ClassifierTarget$Outbound> | null | undefined;
};

/** @internal */
export const CreateFineTuningJobRequest$outboundSchema: z.ZodType<
  CreateFineTuningJobRequest$Outbound,
  CreateFineTuningJobRequest
> = z.object({
  model: z.string(),
  trainingFiles: z.array(TrainingFile$outboundSchema).optional(),
  validationFiles: z.nullable(z.array(z.string())).optional(),
  suffix: z.nullable(z.string()).optional(),
  integrations: z.nullable(z.array(WandbIntegration$outboundSchema)).optional(),
  autoStart: z.boolean().optional(),
  invalidSampleSkipPercentage: z.number().default(0),
  jobType: z.nullable(FineTuneableModelType$outboundSchema).optional(),
  hyperparameters: smartUnion([
    CompletionTrainingParameters$outboundSchema,
    ClassifierTrainingParameters$outboundSchema,
  ]),
  repositories: z.nullable(
    z.array(CreateGithubRepositoryRequest$outboundSchema),
  ).optional(),
  classifierTargets: z.nullable(z.array(ClassifierTarget$outboundSchema))
    .optional(),
}).transform((v) => {
  return remap$(v, {
    trainingFiles: "training_files",
    validationFiles: "validation_files",
    autoStart: "auto_start",
    invalidSampleSkipPercentage: "invalid_sample_skip_percentage",
    jobType: "job_type",
    classifierTargets: "classifier_targets",
  });
});

export function createFineTuningJobRequestToJSON(
  createFineTuningJobRequest: CreateFineTuningJobRequest,
): string {
  return JSON.stringify(
    CreateFineTuningJobRequest$outboundSchema.parse(createFineTuningJobRequest),
  );
}
