Skip to content

Latest commit

 

History

History
412 lines (283 loc) · 29.7 KB

README.md

File metadata and controls

412 lines (283 loc) · 29.7 KB

Files

(files)

Overview

Files are used to upload documents that can be used with features like Assistants and Fine-tuning.

Available Operations

  • listFiles - Returns a list of files that belong to the user's organization.
  • createFile - Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB.

The Assistants API supports files up to 2 million tokens and of specific file types. See the Assistants Tools guide for details.

The Fine-tuning API only supports .jsonl files. The input also has certain required formats for fine-tuning chat or completions models.

The Batch API only supports .jsonl files up to 100 MB in size. The input also has a specific required format.

Please contact us if you need to increase these storage limits.

listFiles

Returns a list of files that belong to the user's organization.

Example Usage

import { ArgotOpenAi } from "argot-open-ai";

const argotOpenAi = new ArgotOpenAi({
  apiKeyAuth: process.env["ARGOTOPENAI_API_KEY_AUTH"] ?? "",
});

async function run() {
  const result = await argotOpenAi.files.listFiles({});

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { ArgotOpenAiCore } from "argot-open-ai/core.js";
import { filesListFiles } from "argot-open-ai/funcs/filesListFiles.js";

// Use `ArgotOpenAiCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const argotOpenAi = new ArgotOpenAiCore({
  apiKeyAuth: process.env["ARGOTOPENAI_API_KEY_AUTH"] ?? "",
});

async function run() {
  const res = await filesListFiles(argotOpenAi, {});

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
request operations.ListFilesRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.ListFilesResponse>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

createFile

Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB.

The Assistants API supports files up to 2 million tokens and of specific file types. See the Assistants Tools guide for details.

The Fine-tuning API only supports .jsonl files. The input also has certain required formats for fine-tuning chat or completions models.

The Batch API only supports .jsonl files up to 100 MB in size. The input also has a specific required format.

Please contact us if you need to increase these storage limits.

Example Usage

import { ArgotOpenAi } from "argot-open-ai";
import { openAsBlob } from "node:fs";

const argotOpenAi = new ArgotOpenAi({
  apiKeyAuth: process.env["ARGOTOPENAI_API_KEY_AUTH"] ?? "",
});

async function run() {
  const result = await argotOpenAi.files.createFile({
    file: await openAsBlob("example.file"),
    purpose: "fine-tune",
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { ArgotOpenAiCore } from "argot-open-ai/core.js";
import { filesCreateFile } from "argot-open-ai/funcs/filesCreateFile.js";
import { openAsBlob } from "node:fs";

// Use `ArgotOpenAiCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const argotOpenAi = new ArgotOpenAiCore({
  apiKeyAuth: process.env["ARGOTOPENAI_API_KEY_AUTH"] ?? "",
});

async function run() {
  const res = await filesCreateFile(argotOpenAi, {
    file: await openAsBlob("example.file"),
    purpose: "fine-tune",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
request components.CreateFileRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.OpenAIFile>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

deleteFile

Delete a file.

Example Usage

import { ArgotOpenAi } from "argot-open-ai";

const argotOpenAi = new ArgotOpenAi({
  apiKeyAuth: process.env["ARGOTOPENAI_API_KEY_AUTH"] ?? "",
});

async function run() {
  const result = await argotOpenAi.files.deleteFile({
    fileId: "<id>",
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { ArgotOpenAiCore } from "argot-open-ai/core.js";
import { filesDeleteFile } from "argot-open-ai/funcs/filesDeleteFile.js";

// Use `ArgotOpenAiCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const argotOpenAi = new ArgotOpenAiCore({
  apiKeyAuth: process.env["ARGOTOPENAI_API_KEY_AUTH"] ?? "",
});

async function run() {
  const res = await filesDeleteFile(argotOpenAi, {
    fileId: "<id>",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
request operations.DeleteFileRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.DeleteFileResponse>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

retrieveFile

Returns information about a specific file.

Example Usage

import { ArgotOpenAi } from "argot-open-ai";

const argotOpenAi = new ArgotOpenAi({
  apiKeyAuth: process.env["ARGOTOPENAI_API_KEY_AUTH"] ?? "",
});

async function run() {
  const result = await argotOpenAi.files.retrieveFile({
    fileId: "<id>",
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { ArgotOpenAiCore } from "argot-open-ai/core.js";
import { filesRetrieveFile } from "argot-open-ai/funcs/filesRetrieveFile.js";

// Use `ArgotOpenAiCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const argotOpenAi = new ArgotOpenAiCore({
  apiKeyAuth: process.env["ARGOTOPENAI_API_KEY_AUTH"] ?? "",
});

async function run() {
  const res = await filesRetrieveFile(argotOpenAi, {
    fileId: "<id>",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
request operations.RetrieveFileRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.OpenAIFile>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

downloadFile

Returns the contents of the specified file.

Example Usage

import { ArgotOpenAi } from "argot-open-ai";

const argotOpenAi = new ArgotOpenAi({
  apiKeyAuth: process.env["ARGOTOPENAI_API_KEY_AUTH"] ?? "",
});

async function run() {
  const result = await argotOpenAi.files.downloadFile({
    fileId: "<id>",
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { ArgotOpenAiCore } from "argot-open-ai/core.js";
import { filesDownloadFile } from "argot-open-ai/funcs/filesDownloadFile.js";

// Use `ArgotOpenAiCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const argotOpenAi = new ArgotOpenAiCore({
  apiKeyAuth: process.env["ARGOTOPENAI_API_KEY_AUTH"] ?? "",
});

async function run() {
  const res = await filesDownloadFile(argotOpenAi, {
    fileId: "<id>",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
request operations.DownloadFileRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<string>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*