All files / api/src/ai-providers/openai create-finetune.ts

77.08% Statements 37/48
100% Branches 0/0
0% Functions 0/1
77.08% Lines 37/48

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57          1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x                          
import type {
  AIProviderFunctionConfig,
  ResponseTransformFunction,
} from '@shared/types/ai-providers/config';
import type { CreateFineTuningJobResponseBody } from '@shared/types/api/routes/fine-tuning-api';
import { AIProvider } from '@shared/types/constants';
import { openAIErrorResponseTransform } from './utils';
 
export const openAICreateFinetuneConfig: AIProviderFunctionConfig = {
  model: {
    param: 'model',
    required: true,
  },
  suffix: {
    param: 'suffix',
    required: true,
  },
  hyperparameters: {
    param: 'hyperparameters',
    required: false,
  },
  training_file: {
    param: 'training_file',
    required: true,
  },
  validation_file: {
    param: 'validation_file',
    required: false,
  },
  integrations: {
    param: 'integrations',
    required: false,
  },
  seed: {
    param: 'seed',
    required: false,
  },
  method: {
    param: 'method',
    required: false,
  },
};
 
export const openAIFinetuneResponseTransform: ResponseTransformFunction = (
  aiProviderResponseBody,
  aiResponseStatus,
) => {
  if (aiResponseStatus !== 200 && 'error' in aiProviderResponseBody) {
    return openAIErrorResponseTransform(
      aiProviderResponseBody,
      AIProvider.OPENAI,
    );
  }
 
  return aiProviderResponseBody as unknown as CreateFineTuningJobResponseBody;
};