Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
Kedar Vijay Kulkarni edited this page Dec 21, 2021 · 1 revision

Files

List Files

Get the list of files currently loaded at OpenAI

Requirements:

QUERY PARAMS

file_type (string) 'FILES_ONLY' or 'ALL' or 'FINETUNE_ONLY'

Document link

const mantiumAi = require('@mantium/mantiumapi');

(async () => {
  await mantiumAi
    .Auth()
    .accessTokenLogin({
      username: '[email protected]',
      password: 'p@ssWord!'
    })
    .then((response) => {
      // get bearer_id and set to default
      mantiumAi.api_key = response.data.attributes.bearer_id;
    });

  /*
   * API Key is set on above
   * mantiumAi.api_key=`key`
   * so we can call these method directly now
   */

  await mantiumAi
    .Files()
    .list({ file_type: 'FILES_ONLY' })
    .then((response) => {
      console.log('*********** File list *********');
      console.log(response);
    });
})();

Example of a successful API response

{
  data: {
    id: 'user-fakpcmfytnzhd7s7uwvzrbms',
    type: 'openai_file',
    attributes: {
      organization: 'user-fakpcmfytnzhd7s7uwvzrbms',
      files: [
        {
          id: 'file-lD7g3egNlil5yyg1RaAkQlmW',
          object: 'file',
          bytes: 1129,
          created_at: 1623106510,
          filename: 'sam2.json',
          purpose: 'answers',
          status: 'processed',
          status_details: null
        },
        {
          id: 'file-MiwAljthEIAh0WnqVKyNm2HU',
          object: 'file',
          bytes: 1128,
          created_at: 1624554610,
          filename: 'blob',
          purpose: 'answers',
          status: 'processed',
          status_details: null
        },
        {
          id: 'file-nkuxoRXPWw6Tl12C0xkheNpb',
          object: 'file',
          bytes: 1131,
          created_at: 1624580768,
          filename: 'blob',
          purpose: 'answers',
          status: 'error',
          status_details: 'Something went wrong while processing. Please contact [email protected] with the file ID file-nkuxoRXPWw6Tl12C0xkheNpb'
        }
      ],
      size: 3
    },
    relationships: {}
  },
  included: [],
  meta: {},
  links: {}
}

Go to Table of Contents

upload a File

Upload a file to AWS

key (string) The AWS key name (or filename)

purpose (string) OpenAI file purpose, it could be one of the following answers, classifications or search

upload_source* (string)* required parameter - The upload source, which could be one of OPENAI-FILE-UPLOAD or OPENAI-FINETUNING-UPLOAD

fine_tune_file_type (string) - Could be either VALIDATION_FILE or TRAINING_FILE

Document link

const mantiumAi = require('@mantium/mantiumapi');
const fs = require('fs');

(async () => {
  await mantiumAi
    .Auth()
    .accessTokenLogin({
      username: '[email protected]',
      password: 'p@ssWord!'
    })
    .then((response) => {
      // get bearer_id and set to default
      mantiumAi.api_key = response.data.attributes.bearer_id;
    });

  /*
   * API Key is set on above
   * mantiumAi.api_key=`key`
   * so we can call these method directly now
   */

  await mantiumAi
    .Files()
    .upload({
      purpose: 'Classifications',
      key: fs.createReadStream('./files/classifications_test_file.json'),
      upload_source: 'OPENAI-FILE-UPLOAD',
      fine_tune_file_type: '',
    })
    .then((response) => {
      console.log('*********** Upload response *********');
      console.log(response);
    });
})();

Example of a successful API response

{
  success: true,
  status: 200,
  error: '',
  warning_message: '',
  upload_source: 'OPENAI-FILE-UPLOAD',
  fine_tune_file_type: '',
  path: './files/classifications_test_file.json',
  purpose: 'Classifications'
}

Go to Table of Contents

Delete File

file_id* (string)* required parameter - file id to delete

Document link

const mantiumAi = require('@mantium/mantiumapi');

(async () => {
  await mantiumAi
    .Auth()
    .accessTokenLogin({
      username: '[email protected]',
      password: 'p@ssWord!'
    })
    .then((response) => {
      // get bearer_id and set to default
      mantiumAi.api_key = response.data.attributes.bearer_id;
    });

  /*
   * API Key is set on above
   * mantiumAi.api_key=`key`
   * so we can call these method directly now
   */

  await mantiumAi
    .Files()
    .remove('file-lD7g3egNlil5yyg1RaAkQlmW')
    .then((response) => {
      console.log('*********** Remove response *********');
      console.log(response);
    });
})();

Example of a successful API response

{
  data: {
    id: 'file-lD7g3egNlil5yyg1RaAkQlmW',
    type: 'openai_file',
    attributes: {
      deleted: true,
      file_id: 'file-lD7g3egNlil5yyg1RaAkQlmW',
      object: 'file'
    },
    relationships: {}
  },
  included: [],
  meta: {},
  links: {}
}

Go to Table of Contents