createFileWithHttpInfo method

Future<Response> createFileWithHttpInfo(
  1. MultipartFile file,
  2. String purpose
)

Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact us if you need to increase the storage limit.

Note: This method returns the HTTP Response.

Parameters:

  • MultipartFile file (required): Name of the JSON Lines file to be uploaded. If the purpose is set to \"fine-tune\", each line is a JSON record with \"prompt\" and \"completion\" fields representing your training examples.

  • String purpose (required): The intended purpose of the uploaded documents. Use \"fine-tune\" for Fine-tuning. This allows us to validate the format of the uploaded file.

Implementation

Future<Response> createFileWithHttpInfo(MultipartFile file, String purpose,) async {
  // ignore: prefer_const_declarations
  final path = r'/files';

  // ignore: prefer_final_locals
  Object? postBody;

  final queryParams = <QueryParam>[];
  final headerParams = <String, String>{};
  final formParams = <String, String>{};

  const contentTypes = <String>['multipart/form-data'];

  bool hasFields = false;
  final mp = MultipartRequest('POST', Uri.parse(path));
  if (file != null) {
    hasFields = true;
    mp.fields[r'file'] = file.field;
    mp.files.add(file);
  }
  if (purpose != null) {
    hasFields = true;
    mp.fields[r'purpose'] = parameterToString(purpose);
  }
  if (hasFields) {
    postBody = mp;
  }

  return apiClient.invokeAPI(
    path,
    'POST',
    queryParams,
    postBody,
    headerParams,
    formParams,
    contentTypes.isEmpty ? null : contentTypes.first,
  );
}