UNPKG

openai

Version:

The official TypeScript library for the OpenAI API

87 lines • 4.09 kB
"use strict"; // File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details. Object.defineProperty(exports, "__esModule", { value: true }); exports.FileBatches = void 0; const resource_1 = require("../../core/resource.js"); const pagination_1 = require("../../core/pagination.js"); const headers_1 = require("../../internal/headers.js"); const vector_store_polling_1 = require("../../lib/vector-store-polling.js"); const path_1 = require("../../internal/utils/path.js"); const vector_store_upload_1 = require("../../lib/vector-store-upload.js"); function resolveResourceRequestOptions(options, buildOptions) { return Promise.resolve(options).then(buildOptions); } class FileBatches extends resource_1.APIResource { /** * Create a vector store file batch. */ create(vectorStoreID, body, options) { return this._client.post((0, path_1.path) `/vector_stores/${vectorStoreID}/file_batches`, resolveResourceRequestOptions(options, (options) => ({ body, ...options, headers: (0, headers_1.buildHeaders)([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]), __security: { bearerAuth: true }, }))); } /** * Retrieves a vector store file batch. */ retrieve(batchID, params, options) { const { vector_store_id } = params; return this._client.get((0, path_1.path) `/vector_stores/${vector_store_id}/file_batches/${batchID}`, resolveResourceRequestOptions(options, (options) => ({ ...options, headers: (0, headers_1.buildHeaders)([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]), __security: { bearerAuth: true }, }))); } /** * Cancel a vector store file batch. This attempts to cancel the processing of * files in this batch as soon as possible. */ cancel(batchID, params, options) { const { vector_store_id } = params; return this._client.post((0, path_1.path) `/vector_stores/${vector_store_id}/file_batches/${batchID}/cancel`, resolveResourceRequestOptions(options, (options) => ({ ...options, headers: (0, headers_1.buildHeaders)([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]), __security: { bearerAuth: true }, }))); } /** * Create a vector store batch and poll until all files have been processed. */ async createAndPoll(vectorStoreId, body, options) { const created = await this.create(vectorStoreId, body, options); return await this.poll(vectorStoreId, created.id, options); } /** * Returns a list of vector store files in a batch. */ listFiles(batchID, params, options) { const { vector_store_id, ...query } = params; return this._client.getAPIList((0, path_1.path) `/vector_stores/${vector_store_id}/file_batches/${batchID}/files`, (pagination_1.CursorPage), resolveResourceRequestOptions(options, (options) => ({ query, ...options, headers: (0, headers_1.buildHeaders)([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]), __security: { bearerAuth: true }, }))); } /** * Wait for the given file batch to be processed. * * Note: this will return even if one of the files failed to process, you need to * check batch.file_counts.failed_count to handle this case. */ async poll(vectorStoreID, batchID, options) { return await (0, vector_store_polling_1.pollVectorStoreFileBatch)(this, vectorStoreID, batchID, options); } /** * Uploads the given files concurrently and then creates a vector store file batch. * * The concurrency limit is configurable using the `maxConcurrency` parameter. */ async uploadAndPoll(vectorStoreId, { files, fileIds = [] }, options) { return await (0, vector_store_upload_1.uploadAndPollVectorStoreFileBatch)(this, this._client, vectorStoreId, files, fileIds, options); } } exports.FileBatches = FileBatches; //# sourceMappingURL=file-batches.js.map