import { ActionFunction, json } from "@remix-run/node";
import { withAuth } from "~/auth/withAuth";
import { StartCohereFineTuneBody, StartFineTuneAction } from "~/types/StartFineTuneAction.types";

export const action: ActionFunction = withAuth(async ({ api, params, request }) => {
  if (request.method === "POST") {
    const datasetId = params.datasetId!;
    const body = (await request.json()) as StartCohereFineTuneBody;
    const finetuneJob = await api.fineTuning.finetuneControllerCreateCohereFineTune({
      datasetId,
      fineTuneCohereInput: body,
    });
    return json<StartFineTuneAction>({ finetune: finetuneJob });
  }

  return json({});
});
