Skip to content

Commit 7c7bfc2

Browse files
refactor(client): deprecate files.retrieveContent in favour of files.content (#474)
The latter supports binary response types more elegantly.
1 parent 96b037a commit 7c7bfc2

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

api.md

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Methods:
8282
- <code title="get /files/{file_id}">client.files.<a href="./src/resources/files.ts">retrieve</a>(fileId) -> FileObject</code>
8383
- <code title="get /files">client.files.<a href="./src/resources/files.ts">list</a>({ ...params }) -> FileObjectsPage</code>
8484
- <code title="delete /files/{file_id}">client.files.<a href="./src/resources/files.ts">del</a>(fileId) -> FileDeleted</code>
85+
- <code title="get /files/{file_id}/content">client.files.<a href="./src/resources/files.ts">content</a>(fileId) -> Response</code>
8586
- <code title="get /files/{file_id}/content">client.files.<a href="./src/resources/files.ts">retrieveContent</a>(fileId) -> string</code>
8687
- <code>client.files.<a href="./src/resources/files.ts">waitForProcessing</a>(id, { pollInterval = 5000, maxWait = 30 _ 60 _ 1000 }) -> Promise&lt;FileObject&gt;</code>
8788

build-deno

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This is a build produced from https://github.com/openai/openai-node – please g
1515
Usage:
1616
1717
\`\`\`ts
18-
import OpenAI from "$(echo 'https://deno.land/x/openai@v4.16.2/mod.ts' | sed -E s/@\.+\\//@"$PACKAGE_VERSION"\\//)";
18+
import OpenAI from "$(echo 'https://deno.land/x/openai@v4.17.0/mod.ts' | sed -E s/@\.+\\//@"$PACKAGE_VERSION"\\//)";
1919
2020
const client = new OpenAI();
2121
\`\`\`

src/resources/files.ts

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import * as Core from 'openai/core';
44
import { APIResource } from 'openai/resource';
55
import { isRequestOptions } from 'openai/core';
6+
import { type Response } from 'openai/_shims/index';
67
import { sleep } from 'openai/core';
78
import { APIConnectionTimeoutError } from 'openai/error';
89
import * as FilesAPI from 'openai/resources/files';
@@ -58,6 +59,15 @@ export class Files extends APIResource {
5859
/**
5960
* Returns the contents of the specified file.
6061
*/
62+
content(fileId: string, options?: Core.RequestOptions): Core.APIPromise<Response> {
63+
return this.get(`/files/${fileId}/content`, { ...options, __binaryResponse: true });
64+
}
65+
66+
/**
67+
* Returns the contents of the specified file.
68+
*
69+
* @deprecated The `.content()` method should be used instead
70+
*/
6171
retrieveContent(fileId: string, options?: Core.RequestOptions): Core.APIPromise<string> {
6272
return this.get(`/files/${fileId}/content`, {
6373
...options,

tests/api-resources/files.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ describe('resource files', () => {
9191
);
9292
});
9393

94+
test('content: request options instead of params are passed correctly', async () => {
95+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
96+
await expect(openai.files.content('string', { path: '/_stainless_unknown_path' })).rejects.toThrow(
97+
OpenAI.NotFoundError,
98+
);
99+
});
100+
94101
test('retrieveContent', async () => {
95102
const responsePromise = openai.files.retrieveContent('string');
96103
const rawResponse = await responsePromise.asResponse();

0 commit comments

Comments
 (0)