From 7c7bfc2fad5a786c9172110e90c9566a943e49f9 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Thu, 9 Nov 2023 16:12:26 +0000 Subject: [PATCH] refactor(client): deprecate files.retrieveContent in favour of files.content (#474) The latter supports binary response types more elegantly. --- api.md | 1 + build-deno | 2 +- src/resources/files.ts | 10 ++++++++++ tests/api-resources/files.test.ts | 7 +++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/api.md b/api.md index 67ff66dec..b8da4cf0c 100644 --- a/api.md +++ b/api.md @@ -82,6 +82,7 @@ Methods: - client.files.retrieve(fileId) -> FileObject - client.files.list({ ...params }) -> FileObjectsPage - client.files.del(fileId) -> FileDeleted +- client.files.content(fileId) -> Response - client.files.retrieveContent(fileId) -> string - client.files.waitForProcessing(id, { pollInterval = 5000, maxWait = 30 _ 60 _ 1000 }) -> Promise<FileObject> diff --git a/build-deno b/build-deno index c6c34389e..e179de38e 100755 --- a/build-deno +++ b/build-deno @@ -15,7 +15,7 @@ This is a build produced from https://github.com/openai/openai-node – please g Usage: \`\`\`ts -import OpenAI from "$(echo 'https://deno.land/x/openai@v4.16.2/mod.ts' | sed -E s/@\.+\\//@"$PACKAGE_VERSION"\\//)"; +import OpenAI from "$(echo 'https://deno.land/x/openai@v4.17.0/mod.ts' | sed -E s/@\.+\\//@"$PACKAGE_VERSION"\\//)"; const client = new OpenAI(); \`\`\` diff --git a/src/resources/files.ts b/src/resources/files.ts index 78acc40ed..4dda2f7ba 100644 --- a/src/resources/files.ts +++ b/src/resources/files.ts @@ -3,6 +3,7 @@ import * as Core from 'openai/core'; import { APIResource } from 'openai/resource'; import { isRequestOptions } from 'openai/core'; +import { type Response } from 'openai/_shims/index'; import { sleep } from 'openai/core'; import { APIConnectionTimeoutError } from 'openai/error'; import * as FilesAPI from 'openai/resources/files'; @@ -58,6 +59,15 @@ export class Files extends APIResource { /** * Returns the contents of the specified file. */ + content(fileId: string, options?: Core.RequestOptions): Core.APIPromise { + return this.get(`/files/${fileId}/content`, { ...options, __binaryResponse: true }); + } + + /** + * Returns the contents of the specified file. + * + * @deprecated The `.content()` method should be used instead + */ retrieveContent(fileId: string, options?: Core.RequestOptions): Core.APIPromise { return this.get(`/files/${fileId}/content`, { ...options, diff --git a/tests/api-resources/files.test.ts b/tests/api-resources/files.test.ts index a84a2aba7..9e6373aba 100644 --- a/tests/api-resources/files.test.ts +++ b/tests/api-resources/files.test.ts @@ -91,6 +91,13 @@ describe('resource files', () => { ); }); + test('content: request options instead of params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect(openai.files.content('string', { path: '/_stainless_unknown_path' })).rejects.toThrow( + OpenAI.NotFoundError, + ); + }); + test('retrieveContent', async () => { const responsePromise = openai.files.retrieveContent('string'); const rawResponse = await responsePromise.asResponse();