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

import * as z from "zod/v4";
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 Metric = {
  trainLoss?: number | null | undefined;
  validLoss?: number | null | undefined;
  validMeanTokenAccuracy?: number | null | undefined;
};

/** @internal */
export const Metric$inboundSchema: z.ZodType<Metric, 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 metricFromJSON(
  jsonString: string,
): SafeParseResult<Metric, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Metric$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Metric' from JSON`,
  );
}
