files.d.mts 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import { APIResource } from "../../core/resource.mjs";
  2. import * as VectorStoresAPI from "./vector-stores.mjs";
  3. import { APIPromise } from "../../core/api-promise.mjs";
  4. import { CursorPage, type CursorPageParams, PagePromise, Page } from "../../core/pagination.mjs";
  5. import { RequestOptions } from "../../internal/request-options.mjs";
  6. import { Uploadable } from "../../uploads.mjs";
  7. export declare class Files extends APIResource {
  8. /**
  9. * Create a vector store file by attaching a
  10. * [File](https://platform.openai.com/docs/api-reference/files) to a
  11. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object).
  12. */
  13. create(vectorStoreID: string, body: FileCreateParams, options?: RequestOptions): APIPromise<VectorStoreFile>;
  14. /**
  15. * Retrieves a vector store file.
  16. */
  17. retrieve(fileID: string, params: FileRetrieveParams, options?: RequestOptions): APIPromise<VectorStoreFile>;
  18. /**
  19. * Update attributes on a vector store file.
  20. */
  21. update(fileID: string, params: FileUpdateParams, options?: RequestOptions): APIPromise<VectorStoreFile>;
  22. /**
  23. * Returns a list of vector store files.
  24. */
  25. list(vectorStoreID: string, query?: FileListParams | null | undefined, options?: RequestOptions): 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. delete(fileID: string, params: FileDeleteParams, options?: RequestOptions): 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?: 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?: 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?: 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?: RequestOptions & {
  59. pollIntervalMs?: number;
  60. }): Promise<VectorStoreFile>;
  61. /**
  62. * Retrieve the parsed contents of a vector store file.
  63. */
  64. content(fileID: string, params: FileContentParams, options?: RequestOptions): PagePromise<FileContentResponsesPage, FileContentResponse>;
  65. }
  66. export type VectorStoreFilesPage = CursorPage<VectorStoreFile>;
  67. export type FileContentResponsesPage = Page<FileContentResponse>;
  68. /**
  69. * A list of files attached to a vector store.
  70. */
  71. export interface VectorStoreFile {
  72. /**
  73. * The identifier, which can be referenced in API endpoints.
  74. */
  75. id: string;
  76. /**
  77. * The Unix timestamp (in seconds) for when the vector store file was created.
  78. */
  79. created_at: number;
  80. /**
  81. * The last error associated with this vector store file. Will be `null` if there
  82. * are no errors.
  83. */
  84. last_error: VectorStoreFile.LastError | null;
  85. /**
  86. * The object type, which is always `vector_store.file`.
  87. */
  88. object: 'vector_store.file';
  89. /**
  90. * The status of the vector store file, which can be either `in_progress`,
  91. * `completed`, `cancelled`, or `failed`. The status `completed` indicates that the
  92. * vector store file is ready for use.
  93. */
  94. status: 'in_progress' | 'completed' | 'cancelled' | 'failed';
  95. /**
  96. * The total vector store usage in bytes. Note that this may be different from the
  97. * original file size.
  98. */
  99. usage_bytes: number;
  100. /**
  101. * The ID of the
  102. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  103. * that the [File](https://platform.openai.com/docs/api-reference/files) is
  104. * attached to.
  105. */
  106. vector_store_id: string;
  107. /**
  108. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  109. * for storing additional information about the object in a structured format, and
  110. * querying for objects via API or the dashboard. Keys are strings with a maximum
  111. * length of 64 characters. Values are strings with a maximum length of 512
  112. * characters, booleans, or numbers.
  113. */
  114. attributes?: {
  115. [key: string]: string | number | boolean;
  116. } | null;
  117. /**
  118. * The strategy used to chunk the file.
  119. */
  120. chunking_strategy?: VectorStoresAPI.FileChunkingStrategy;
  121. }
  122. export declare namespace VectorStoreFile {
  123. /**
  124. * The last error associated with this vector store file. Will be `null` if there
  125. * are no errors.
  126. */
  127. interface LastError {
  128. /**
  129. * One of `server_error`, `unsupported_file`, or `invalid_file`.
  130. */
  131. code: 'server_error' | 'unsupported_file' | 'invalid_file';
  132. /**
  133. * A human-readable description of the error.
  134. */
  135. message: string;
  136. }
  137. }
  138. export interface VectorStoreFileDeleted {
  139. id: string;
  140. deleted: boolean;
  141. object: 'vector_store.file.deleted';
  142. }
  143. export interface FileContentResponse {
  144. /**
  145. * The text content
  146. */
  147. text?: string;
  148. /**
  149. * The content type (currently only `"text"`)
  150. */
  151. type?: string;
  152. }
  153. export interface FileCreateParams {
  154. /**
  155. * A [File](https://platform.openai.com/docs/api-reference/files) ID that the
  156. * vector store should use. Useful for tools like `file_search` that can access
  157. * files.
  158. */
  159. file_id: string;
  160. /**
  161. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  162. * for storing additional information about the object in a structured format, and
  163. * querying for objects via API or the dashboard. Keys are strings with a maximum
  164. * length of 64 characters. Values are strings with a maximum length of 512
  165. * characters, booleans, or numbers.
  166. */
  167. attributes?: {
  168. [key: string]: string | number | boolean;
  169. } | null;
  170. /**
  171. * The chunking strategy used to chunk the file(s). If not set, will use the `auto`
  172. * strategy. Only applicable if `file_ids` is non-empty.
  173. */
  174. chunking_strategy?: VectorStoresAPI.FileChunkingStrategyParam;
  175. }
  176. export interface FileRetrieveParams {
  177. /**
  178. * The ID of the vector store that the file belongs to.
  179. */
  180. vector_store_id: string;
  181. }
  182. export interface FileUpdateParams {
  183. /**
  184. * Path param: The ID of the vector store the file belongs to.
  185. */
  186. vector_store_id: string;
  187. /**
  188. * Body param: Set of 16 key-value pairs that can be attached to an object. This
  189. * can be useful for storing additional information about the object in a
  190. * structured format, and querying for objects via API or the dashboard. Keys are
  191. * strings with a maximum length of 64 characters. Values are strings with a
  192. * maximum length of 512 characters, booleans, or numbers.
  193. */
  194. attributes: {
  195. [key: string]: string | number | boolean;
  196. } | null;
  197. }
  198. export interface FileListParams extends CursorPageParams {
  199. /**
  200. * A cursor for use in pagination. `before` is an object ID that defines your place
  201. * in the list. For instance, if you make a list request and receive 100 objects,
  202. * starting with obj_foo, your subsequent call can include before=obj_foo in order
  203. * to fetch the previous page of the list.
  204. */
  205. before?: string;
  206. /**
  207. * Filter by file status. One of `in_progress`, `completed`, `failed`, `cancelled`.
  208. */
  209. filter?: 'in_progress' | 'completed' | 'failed' | 'cancelled';
  210. /**
  211. * Sort order by the `created_at` timestamp of the objects. `asc` for ascending
  212. * order and `desc` for descending order.
  213. */
  214. order?: 'asc' | 'desc';
  215. }
  216. export interface FileDeleteParams {
  217. /**
  218. * The ID of the vector store that the file belongs to.
  219. */
  220. vector_store_id: string;
  221. }
  222. export interface FileContentParams {
  223. /**
  224. * The ID of the vector store.
  225. */
  226. vector_store_id: string;
  227. }
  228. export declare namespace Files {
  229. export { type VectorStoreFile as VectorStoreFile, type VectorStoreFileDeleted as VectorStoreFileDeleted, type FileContentResponse as FileContentResponse, type VectorStoreFilesPage as VectorStoreFilesPage, type FileContentResponsesPage as FileContentResponsesPage, type FileCreateParams as FileCreateParams, type FileRetrieveParams as FileRetrieveParams, type FileUpdateParams as FileUpdateParams, type FileListParams as FileListParams, type FileDeleteParams as FileDeleteParams, type FileContentParams as FileContentParams, };
  230. }
  231. //# sourceMappingURL=files.d.mts.map