Skip to content

Commit

Permalink
refactor(client): deprecate files.retrieveContent in favour of files.…
Browse files Browse the repository at this point in the history
…content (#474)

The latter supports binary response types more elegantly.
  • Loading branch information
stainless-bot authored Nov 9, 2023
1 parent 96b037a commit 7c7bfc2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Methods:
- <code title="get /files/{file_id}">client.files.<a href="./src/resources/files.ts">retrieve</a>(fileId) -> FileObject</code>
- <code title="get /files">client.files.<a href="./src/resources/files.ts">list</a>({ ...params }) -> FileObjectsPage</code>
- <code title="delete /files/{file_id}">client.files.<a href="./src/resources/files.ts">del</a>(fileId) -> FileDeleted</code>
- <code title="get /files/{file_id}/content">client.files.<a href="./src/resources/files.ts">content</a>(fileId) -> Response</code>
- <code title="get /files/{file_id}/content">client.files.<a href="./src/resources/files.ts">retrieveContent</a>(fileId) -> string</code>
- <code>client.files.<a href="./src/resources/files.ts">waitForProcessing</a>(id, { pollInterval = 5000, maxWait = 30 _ 60 _ 1000 }) -> Promise&lt;FileObject&gt;</code>

Expand Down
2 changes: 1 addition & 1 deletion build-deno
Original file line number Diff line number Diff line change
Expand Up @@ -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();
\`\`\`
Expand Down
10 changes: 10 additions & 0 deletions src/resources/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -58,6 +59,15 @@ export class Files extends APIResource {
/**
* Returns the contents of the specified file.
*/
content(fileId: string, options?: Core.RequestOptions): Core.APIPromise<Response> {
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<string> {
return this.get(`/files/${fileId}/content`, {
...options,
Expand Down
7 changes: 7 additions & 0 deletions tests/api-resources/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

1 comment on commit 7c7bfc2

@rattrayalex
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples of how to use this are available here: https://github.com/openai/openai-node/blob/master/examples/audio.ts

Please sign in to comment.