files.d.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import { APIResource } from "../../resource.js";
  2. import { Uploadable } from "../../core.js";
  3. import * as Core from "../../core.js";
  4. import * as VectorStoresAPI from "./vector-stores.js";
  5. import { CursorPage, type CursorPageParams, Page } from "../../pagination.js";
  6. export declare class Files extends APIResource {
  7. /**
  8. * Create a vector store file by attaching a
  9. * [File](https://platform.openai.com/docs/api-reference/files) to a
  10. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object).
  11. */
  12. create(vectorStoreId: string, body: FileCreateParams, options?: Core.RequestOptions): Core.APIPromise<VectorStoreFile>;
  13. /**
  14. * Retrieves a vector store file.
  15. */
  16. retrieve(vectorStoreId: string, fileId: string, options?: Core.RequestOptions): Core.APIPromise<VectorStoreFile>;
  17. /**
  18. * Update attributes on a vector store file.
  19. */
  20. update(vectorStoreId: string, fileId: string, body: FileUpdateParams, options?: Core.RequestOptions): Core.APIPromise<VectorStoreFile>;
  21. /**
  22. * Returns a list of vector store files.
  23. */
  24. list(vectorStoreId: string, query?: FileListParams, options?: Core.RequestOptions): Core.PagePromise<VectorStoreFilesPage, VectorStoreFile>;
  25. list(vectorStoreId: string, options?: Core.RequestOptions): Core.PagePromise<VectorStoreFilesPage, VectorStoreFile>;
  26. /**
  27. * Delete a vector store file. This will remove the file from the vector store but
  28. * the file itself will not be deleted. To delete the file, use the
  29. * [delete file](https://platform.openai.com/docs/api-reference/files/delete)
  30. * endpoint.
  31. */
  32. del(vectorStoreId: string, fileId: string, options?: Core.RequestOptions): Core.APIPromise<VectorStoreFileDeleted>;
  33. /**
  34. * Attach a file to the given vector store and wait for it to be processed.
  35. */
  36. createAndPoll(vectorStoreId: string, body: FileCreateParams, options?: Core.RequestOptions & {
  37. pollIntervalMs?: number;
  38. }): Promise<VectorStoreFile>;
  39. /**
  40. * Wait for the vector store file to finish processing.
  41. *
  42. * Note: this will return even if the file failed to process, you need to check
  43. * file.last_error and file.status to handle these cases
  44. */
  45. poll(vectorStoreId: string, fileId: string, options?: Core.RequestOptions & {
  46. pollIntervalMs?: number;
  47. }): Promise<VectorStoreFile>;
  48. /**
  49. * Upload a file to the `files` API and then attach it to the given vector store.
  50. *
  51. * Note the file will be asynchronously processed (you can use the alternative
  52. * polling helper method to wait for processing to complete).
  53. */
  54. upload(vectorStoreId: string, file: Uploadable, options?: Core.RequestOptions): Promise<VectorStoreFile>;
  55. /**
  56. * Add a file to a vector store and poll until processing is complete.
  57. */
  58. uploadAndPoll(vectorStoreId: string, file: Uploadable, options?: Core.RequestOptions & {
  59. pollIntervalMs?: number;
  60. }): Promise<VectorStoreFile>;
  61. /**
  62. * Retrieve the parsed contents of a vector store file.
  63. */
  64. content(vectorStoreId: string, fileId: string, options?: Core.RequestOptions): Core.PagePromise<FileContentResponsesPage, FileContentResponse>;
  65. }
  66. export declare class VectorStoreFilesPage extends CursorPage<VectorStoreFile> {
  67. }
  68. /**
  69. * Note: no pagination actually occurs yet, this is for forwards-compatibility.
  70. */
  71. export declare class FileContentResponsesPage extends Page<FileContentResponse> {
  72. }
  73. /**
  74. * A list of files attached to a vector store.
  75. */
  76. export interface VectorStoreFile {
  77. /**
  78. * The identifier, which can be referenced in API endpoints.
  79. */
  80. id: string;
  81. /**
  82. * The Unix timestamp (in seconds) for when the vector store file was created.
  83. */
  84. created_at: number;
  85. /**
  86. * The last error associated with this vector store file. Will be `null` if there
  87. * are no errors.
  88. */
  89. last_error: VectorStoreFile.LastError | null;
  90. /**
  91. * The object type, which is always `vector_store.file`.
  92. */
  93. object: 'vector_store.file';
  94. /**
  95. * The status of the vector store file, which can be either `in_progress`,
  96. * `completed`, `cancelled`, or `failed`. The status `completed` indicates that the
  97. * vector store file is ready for use.
  98. */
  99. status: 'in_progress' | 'completed' | 'cancelled' | 'failed';
  100. /**
  101. * The total vector store usage in bytes. Note that this may be different from the
  102. * original file size.
  103. */
  104. usage_bytes: number;
  105. /**
  106. * The ID of the
  107. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  108. * that the [File](https://platform.openai.com/docs/api-reference/files) is
  109. * attached to.
  110. */
  111. vector_store_id: string;
  112. /**
  113. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  114. * for storing additional information about the object in a structured format, and
  115. * querying for objects via API or the dashboard. Keys are strings with a maximum
  116. * length of 64 characters. Values are strings with a maximum length of 512
  117. * characters, booleans, or numbers.
  118. */
  119. attributes?: Record<string, string | number | boolean> | null;
  120. /**
  121. * The strategy used to chunk the file.
  122. */
  123. chunking_strategy?: VectorStoresAPI.FileChunkingStrategy;
  124. }
  125. export declare namespace VectorStoreFile {
  126. /**
  127. * The last error associated with this vector store file. Will be `null` if there
  128. * are no errors.
  129. */
  130. interface LastError {
  131. /**
  132. * One of `server_error` or `rate_limit_exceeded`.
  133. */
  134. code: 'server_error' | 'unsupported_file' | 'invalid_file';
  135. /**
  136. * A human-readable description of the error.
  137. */
  138. message: string;
  139. }
  140. }
  141. export interface VectorStoreFileDeleted {
  142. id: string;
  143. deleted: boolean;
  144. object: 'vector_store.file.deleted';
  145. }
  146. export interface FileContentResponse {
  147. /**
  148. * The text content
  149. */
  150. text?: string;
  151. /**
  152. * The content type (currently only `"text"`)
  153. */
  154. type?: string;
  155. }
  156. export interface FileCreateParams {
  157. /**
  158. * A [File](https://platform.openai.com/docs/api-reference/files) ID that the
  159. * vector store should use. Useful for tools like `file_search` that can access
  160. * files.
  161. */
  162. file_id: string;
  163. /**
  164. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  165. * for storing additional information about the object in a structured format, and
  166. * querying for objects via API or the dashboard. Keys are strings with a maximum
  167. * length of 64 characters. Values are strings with a maximum length of 512
  168. * characters, booleans, or numbers.
  169. */
  170. attributes?: Record<string, string | number | boolean> | null;
  171. /**
  172. * The chunking strategy used to chunk the file(s). If not set, will use the `auto`
  173. * strategy. Only applicable if `file_ids` is non-empty.
  174. */
  175. chunking_strategy?: VectorStoresAPI.FileChunkingStrategyParam;
  176. }
  177. export interface FileUpdateParams {
  178. /**
  179. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  180. * for storing additional information about the object in a structured format, and
  181. * querying for objects via API or the dashboard. Keys are strings with a maximum
  182. * length of 64 characters. Values are strings with a maximum length of 512
  183. * characters, booleans, or numbers.
  184. */
  185. attributes: Record<string, string | number | boolean> | null;
  186. }
  187. export interface FileListParams extends CursorPageParams {
  188. /**
  189. * A cursor for use in pagination. `before` is an object ID that defines your place
  190. * in the list. For instance, if you make a list request and receive 100 objects,
  191. * starting with obj_foo, your subsequent call can include before=obj_foo in order
  192. * to fetch the previous page of the list.
  193. */
  194. before?: string;
  195. /**
  196. * Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled`.
  197. */
  198. filter?: 'in_progress' | 'completed' | 'failed' | 'cancelled';
  199. /**
  200. * Sort order by the `created_at` timestamp of the objects. `asc` for ascending
  201. * order and `desc` for descending order.
  202. */
  203. order?: 'asc' | 'desc';
  204. }
  205. export declare namespace Files {
  206. export { type VectorStoreFile as VectorStoreFile, type VectorStoreFileDeleted as VectorStoreFileDeleted, type FileContentResponse as FileContentResponse, VectorStoreFilesPage as VectorStoreFilesPage, FileContentResponsesPage as FileContentResponsesPage, type FileCreateParams as FileCreateParams, type FileUpdateParams as FileUpdateParams, type FileListParams as FileListParams, };
  207. }
  208. //# sourceMappingURL=files.d.ts.map