| 32 | ) {} |
| 33 | |
| 34 | create( |
| 35 | key: IntegrationTaskKey, |
| 36 | params: CreateFileRequest, |
| 37 | options: OpenAIRequestOptions = {} |
| 38 | ): Promise<OpenAI.Files.FileObject> { |
| 39 | return this.runTask( |
| 40 | key, |
| 41 | async (client, task) => { |
| 42 | let file: Uploadable; |
| 43 | |
| 44 | if (typeof params.file === "string") { |
| 45 | file = await toFile(Buffer.from(params.file), params.fileName ?? "file.txt"); |
| 46 | } else { |
| 47 | file = params.file; |
| 48 | } |
| 49 | |
| 50 | return client.files.create( |
| 51 | { file, purpose: params.purpose }, |
| 52 | { idempotencyKey: task.idempotencyKey, ...options } |
| 53 | ); |
| 54 | }, |
| 55 | { |
| 56 | name: "Create file", |
| 57 | params, |
| 58 | properties: [ |
| 59 | { |
| 60 | label: "Purpose", |
| 61 | text: params.purpose, |
| 62 | }, |
| 63 | { |
| 64 | label: "Input type", |
| 65 | text: typeof params.file === "string" ? "string" : "File", |
| 66 | }, |
| 67 | ], |
| 68 | }, |
| 69 | handleOpenAIError |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | async createAndWaitForProcessing( |
| 74 | key: IntegrationTaskKey, |