openai
Version:
The official TypeScript library for the OpenAI API
83 lines • 3.79 kB
JavaScript
// File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
import { APIResource } from "../../core/resource.mjs";
import { CursorPage } from "../../core/pagination.mjs";
import { buildHeaders } from "../../internal/headers.mjs";
import { pollVectorStoreFileBatch } from "../../lib/vector-store-polling.mjs";
import { path } from "../../internal/utils/path.mjs";
import { uploadAndPollVectorStoreFileBatch } from "../../lib/vector-store-upload.mjs";
function resolveResourceRequestOptions(options, buildOptions) {
return Promise.resolve(options).then(buildOptions);
}
export class FileBatches extends APIResource {
/**
* Create a vector store file batch.
*/
create(vectorStoreID, body, options) {
return this._client.post(path `/vector_stores/${vectorStoreID}/file_batches`, resolveResourceRequestOptions(options, (options) => ({
body,
...options,
headers: 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(path `/vector_stores/${vector_store_id}/file_batches/${batchID}`, resolveResourceRequestOptions(options, (options) => ({
...options,
headers: 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(path `/vector_stores/${vector_store_id}/file_batches/${batchID}/cancel`, resolveResourceRequestOptions(options, (options) => ({
...options,
headers: 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(path `/vector_stores/${vector_store_id}/file_batches/${batchID}/files`, (CursorPage), resolveResourceRequestOptions(options, (options) => ({
query,
...options,
headers: 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 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 uploadAndPollVectorStoreFileBatch(this, this._client, vectorStoreId, files, fileIds, options);
}
}
//# sourceMappingURL=file-batches.mjs.map