/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v3";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

/**
 * Metrics at the step number during the fine-tuning job. Use these metrics to assess if the training is going smoothly (loss should decrease, token accuracy should increase).
 */
export type MetricOut = {
  trainLoss?: number | null | undefined;
  validLoss?: number | null | undefined;
  validMeanTokenAccuracy?: number | null | undefined;
};

/** @internal */
export const MetricOut$inboundSchema: z.ZodType<
  MetricOut,
  z.ZodTypeDef,
  unknown
> = z.object({
  train_loss: z.nullable(z.number()).optional(),
  valid_loss: z.nullable(z.number()).optional(),
  valid_mean_token_accuracy: z.nullable(z.number()).optional(),
}).transform((v) => {
  return remap$(v, {
    "train_loss": "trainLoss",
    "valid_loss": "validLoss",
    "valid_mean_token_accuracy": "validMeanTokenAccuracy",
  });
});

export function metricOutFromJSON(
  jsonString: string,
): SafeParseResult<MetricOut, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => MetricOut$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'MetricOut' from JSON`,
  );
}
