file-batches.d.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import { APIResource } from "../../core/resource.js";
  2. import * as FilesAPI from "./files.js";
  3. import { VectorStoreFilesPage } from "./files.js";
  4. import * as VectorStoresAPI from "./vector-stores.js";
  5. import { APIPromise } from "../../core/api-promise.js";
  6. import { type CursorPageParams, PagePromise } from "../../core/pagination.js";
  7. import { RequestOptions } from "../../internal/request-options.js";
  8. import { type Uploadable } from "../../uploads.js";
  9. export declare class FileBatches extends APIResource {
  10. /**
  11. * Create a vector store file batch.
  12. */
  13. create(vectorStoreID: string, body: FileBatchCreateParams, options?: RequestOptions): APIPromise<VectorStoreFileBatch>;
  14. /**
  15. * Retrieves a vector store file batch.
  16. */
  17. retrieve(batchID: string, params: FileBatchRetrieveParams, options?: RequestOptions): APIPromise<VectorStoreFileBatch>;
  18. /**
  19. * Cancel a vector store file batch. This attempts to cancel the processing of
  20. * files in this batch as soon as possible.
  21. */
  22. cancel(batchID: string, params: FileBatchCancelParams, options?: RequestOptions): APIPromise<VectorStoreFileBatch>;
  23. /**
  24. * Create a vector store batch and poll until all files have been processed.
  25. */
  26. createAndPoll(vectorStoreId: string, body: FileBatchCreateParams, options?: RequestOptions & {
  27. pollIntervalMs?: number;
  28. }): Promise<VectorStoreFileBatch>;
  29. /**
  30. * Returns a list of vector store files in a batch.
  31. */
  32. listFiles(batchID: string, params: FileBatchListFilesParams, options?: RequestOptions): PagePromise<VectorStoreFilesPage, FilesAPI.VectorStoreFile>;
  33. /**
  34. * Wait for the given file batch to be processed.
  35. *
  36. * Note: this will return even if one of the files failed to process, you need to
  37. * check batch.file_counts.failed_count to handle this case.
  38. */
  39. poll(vectorStoreID: string, batchID: string, options?: RequestOptions & {
  40. pollIntervalMs?: number;
  41. }): Promise<VectorStoreFileBatch>;
  42. /**
  43. * Uploads the given files concurrently and then creates a vector store file batch.
  44. *
  45. * The concurrency limit is configurable using the `maxConcurrency` parameter.
  46. */
  47. uploadAndPoll(vectorStoreId: string, { files, fileIds }: {
  48. files: Uploadable[];
  49. fileIds?: string[];
  50. }, options?: RequestOptions & {
  51. pollIntervalMs?: number;
  52. maxConcurrency?: number;
  53. }): Promise<VectorStoreFileBatch>;
  54. }
  55. /**
  56. * A batch of files attached to a vector store.
  57. */
  58. export interface VectorStoreFileBatch {
  59. /**
  60. * The identifier, which can be referenced in API endpoints.
  61. */
  62. id: string;
  63. /**
  64. * The Unix timestamp (in seconds) for when the vector store files batch was
  65. * created.
  66. */
  67. created_at: number;
  68. file_counts: VectorStoreFileBatch.FileCounts;
  69. /**
  70. * The object type, which is always `vector_store.file_batch`.
  71. */
  72. object: 'vector_store.files_batch';
  73. /**
  74. * The status of the vector store files batch, which can be either `in_progress`,
  75. * `completed`, `cancelled` or `failed`.
  76. */
  77. status: 'in_progress' | 'completed' | 'cancelled' | 'failed';
  78. /**
  79. * The ID of the
  80. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  81. * that the [File](https://platform.openai.com/docs/api-reference/files) is
  82. * attached to.
  83. */
  84. vector_store_id: string;
  85. }
  86. export declare namespace VectorStoreFileBatch {
  87. interface FileCounts {
  88. /**
  89. * The number of files that where cancelled.
  90. */
  91. cancelled: number;
  92. /**
  93. * The number of files that have been processed.
  94. */
  95. completed: number;
  96. /**
  97. * The number of files that have failed to process.
  98. */
  99. failed: number;
  100. /**
  101. * The number of files that are currently being processed.
  102. */
  103. in_progress: number;
  104. /**
  105. * The total number of files.
  106. */
  107. total: number;
  108. }
  109. }
  110. export interface FileBatchCreateParams {
  111. /**
  112. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  113. * for storing additional information about the object in a structured format, and
  114. * querying for objects via API or the dashboard. Keys are strings with a maximum
  115. * length of 64 characters. Values are strings with a maximum length of 512
  116. * characters, booleans, or numbers.
  117. */
  118. attributes?: {
  119. [key: string]: string | number | boolean;
  120. } | null;
  121. /**
  122. * The chunking strategy used to chunk the file(s). If not set, will use the `auto`
  123. * strategy. Only applicable if `file_ids` is non-empty.
  124. */
  125. chunking_strategy?: VectorStoresAPI.FileChunkingStrategyParam;
  126. /**
  127. * A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that
  128. * the vector store should use. Useful for tools like `file_search` that can access
  129. * files. If `attributes` or `chunking_strategy` are provided, they will be applied
  130. * to all files in the batch. Mutually exclusive with `files`.
  131. */
  132. file_ids?: Array<string>;
  133. /**
  134. * A list of objects that each include a `file_id` plus optional `attributes` or
  135. * `chunking_strategy`. Use this when you need to override metadata for specific
  136. * files. The global `attributes` or `chunking_strategy` will be ignored and must
  137. * be specified for each file. Mutually exclusive with `file_ids`.
  138. */
  139. files?: Array<FileBatchCreateParams.File>;
  140. }
  141. export declare namespace FileBatchCreateParams {
  142. interface File {
  143. /**
  144. * A [File](https://platform.openai.com/docs/api-reference/files) ID that the
  145. * vector store should use. Useful for tools like `file_search` that can access
  146. * files.
  147. */
  148. file_id: string;
  149. /**
  150. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  151. * for storing additional information about the object in a structured format, and
  152. * querying for objects via API or the dashboard. Keys are strings with a maximum
  153. * length of 64 characters. Values are strings with a maximum length of 512
  154. * characters, booleans, or numbers.
  155. */
  156. attributes?: {
  157. [key: string]: string | number | boolean;
  158. } | null;
  159. /**
  160. * The chunking strategy used to chunk the file(s). If not set, will use the `auto`
  161. * strategy. Only applicable if `file_ids` is non-empty.
  162. */
  163. chunking_strategy?: VectorStoresAPI.FileChunkingStrategyParam;
  164. }
  165. }
  166. export interface FileBatchRetrieveParams {
  167. /**
  168. * The ID of the vector store that the file batch belongs to.
  169. */
  170. vector_store_id: string;
  171. }
  172. export interface FileBatchCancelParams {
  173. /**
  174. * The ID of the vector store that the file batch belongs to.
  175. */
  176. vector_store_id: string;
  177. }
  178. export interface FileBatchListFilesParams extends CursorPageParams {
  179. /**
  180. * Path param: The ID of the vector store that the files belong to.
  181. */
  182. vector_store_id: string;
  183. /**
  184. * Query param: A cursor for use in pagination. `before` is an object ID that
  185. * defines your place in the list. For instance, if you make a list request and
  186. * receive 100 objects, starting with obj_foo, your subsequent call can include
  187. * before=obj_foo in order to fetch the previous page of the list.
  188. */
  189. before?: string;
  190. /**
  191. * Query param: Filter by file status. One of `in_progress`, `completed`, `failed`,
  192. * `cancelled`.
  193. */
  194. filter?: 'in_progress' | 'completed' | 'failed' | 'cancelled';
  195. /**
  196. * Query param: Sort order by the `created_at` timestamp of the objects. `asc` for
  197. * ascending order and `desc` for descending order.
  198. */
  199. order?: 'asc' | 'desc';
  200. }
  201. export declare namespace FileBatches {
  202. export { type VectorStoreFileBatch as VectorStoreFileBatch, type FileBatchCreateParams as FileBatchCreateParams, type FileBatchRetrieveParams as FileBatchRetrieveParams, type FileBatchCancelParams as FileBatchCancelParams, type FileBatchListFilesParams as FileBatchListFilesParams, };
  203. }
  204. export { type VectorStoreFilesPage };
  205. //# sourceMappingURL=file-batches.d.ts.map