Skip to content

Commit bdb79f9

Browse files
committed
feat(api): updates (#501)
1 parent 09127e8 commit bdb79f9

28 files changed

+80
-114
lines changed

src/core.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -564,27 +564,6 @@ export abstract class APIClient {
564564
}
565565
}
566566

567-
export class APIResource {
568-
protected client: APIClient;
569-
constructor(client: APIClient) {
570-
this.client = client;
571-
572-
this.get = client.get.bind(client);
573-
this.post = client.post.bind(client);
574-
this.patch = client.patch.bind(client);
575-
this.put = client.put.bind(client);
576-
this.delete = client.delete.bind(client);
577-
this.getAPIList = client.getAPIList.bind(client);
578-
}
579-
580-
protected get: APIClient['get'];
581-
protected post: APIClient['post'];
582-
protected patch: APIClient['patch'];
583-
protected put: APIClient['put'];
584-
protected delete: APIClient['delete'];
585-
protected getAPIList: APIClient['getAPIList'];
586-
}
587-
588567
export type PageInfo = { url: URL } | { params: Record<string, unknown> | null };
589568

590569
export abstract class AbstractPage<Item> implements AsyncIterable<Item> {

src/resource.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,9 @@
33
import type { OpenAI } from './index';
44

55
export class APIResource {
6-
protected client: OpenAI;
7-
constructor(client: OpenAI) {
8-
this.client = client;
6+
protected _client: OpenAI;
97

10-
this.get = client.get.bind(client);
11-
this.post = client.post.bind(client);
12-
this.patch = client.patch.bind(client);
13-
this.put = client.put.bind(client);
14-
this.delete = client.delete.bind(client);
15-
this.getAPIList = client.getAPIList.bind(client);
8+
constructor(client: OpenAI) {
9+
this._client = client;
1610
}
17-
18-
protected get: OpenAI['get'];
19-
protected post: OpenAI['post'];
20-
protected patch: OpenAI['patch'];
21-
protected put: OpenAI['put'];
22-
protected delete: OpenAI['delete'];
23-
protected getAPIList: OpenAI['getAPIList'];
2411
}

src/resources/audio/audio.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import * as TranscriptionsAPI from 'openai/resources/audio/transcriptions';
66
import * as TranslationsAPI from 'openai/resources/audio/translations';
77

88
export class Audio extends APIResource {
9-
transcriptions: TranscriptionsAPI.Transcriptions = new TranscriptionsAPI.Transcriptions(this.client);
10-
translations: TranslationsAPI.Translations = new TranslationsAPI.Translations(this.client);
11-
speech: SpeechAPI.Speech = new SpeechAPI.Speech(this.client);
9+
transcriptions: TranscriptionsAPI.Transcriptions = new TranscriptionsAPI.Transcriptions(this._client);
10+
translations: TranslationsAPI.Translations = new TranslationsAPI.Translations(this._client);
11+
speech: SpeechAPI.Speech = new SpeechAPI.Speech(this._client);
1212
}
1313

1414
export namespace Audio {

src/resources/audio/speech.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class Speech extends APIResource {
1010
* Generates audio from the input text.
1111
*/
1212
create(body: SpeechCreateParams, options?: Core.RequestOptions): Core.APIPromise<Response> {
13-
return this.post('/audio/speech', { body, ...options, __binaryResponse: true });
13+
return this._client.post('/audio/speech', { body, ...options, __binaryResponse: true });
1414
}
1515
}
1616

src/resources/audio/transcriptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class Transcriptions extends APIResource {
1010
* Transcribes audio into the input language.
1111
*/
1212
create(body: TranscriptionCreateParams, options?: Core.RequestOptions): Core.APIPromise<Transcription> {
13-
return this.post('/audio/transcriptions', multipartFormRequestOptions({ body, ...options }));
13+
return this._client.post('/audio/transcriptions', multipartFormRequestOptions({ body, ...options }));
1414
}
1515
}
1616

src/resources/audio/translations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class Translations extends APIResource {
1010
* Translates audio into English.
1111
*/
1212
create(body: TranslationCreateParams, options?: Core.RequestOptions): Core.APIPromise<Translation> {
13-
return this.post('/audio/translations', multipartFormRequestOptions({ body, ...options }));
13+
return this._client.post('/audio/translations', multipartFormRequestOptions({ body, ...options }));
1414
}
1515
}
1616

src/resources/beta/assistants/assistants.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import * as FilesAPI from 'openai/resources/beta/assistants/files';
99
import { CursorPage, type CursorPageParams } from 'openai/pagination';
1010

1111
export class Assistants extends APIResource {
12-
files: FilesAPI.Files = new FilesAPI.Files(this.client);
12+
files: FilesAPI.Files = new FilesAPI.Files(this._client);
1313

1414
/**
1515
* Create an assistant with a model and instructions.
1616
*/
1717
create(body: AssistantCreateParams, options?: Core.RequestOptions): Core.APIPromise<Assistant> {
18-
return this.post('/assistants', {
18+
return this._client.post('/assistants', {
1919
body,
2020
...options,
2121
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
@@ -26,7 +26,7 @@ export class Assistants extends APIResource {
2626
* Retrieves an assistant.
2727
*/
2828
retrieve(assistantId: string, options?: Core.RequestOptions): Core.APIPromise<Assistant> {
29-
return this.get(`/assistants/${assistantId}`, {
29+
return this._client.get(`/assistants/${assistantId}`, {
3030
...options,
3131
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
3232
});
@@ -40,7 +40,7 @@ export class Assistants extends APIResource {
4040
body: AssistantUpdateParams,
4141
options?: Core.RequestOptions,
4242
): Core.APIPromise<Assistant> {
43-
return this.post(`/assistants/${assistantId}`, {
43+
return this._client.post(`/assistants/${assistantId}`, {
4444
body,
4545
...options,
4646
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
@@ -62,7 +62,7 @@ export class Assistants extends APIResource {
6262
if (isRequestOptions(query)) {
6363
return this.list({}, query);
6464
}
65-
return this.getAPIList('/assistants', AssistantsPage, {
65+
return this._client.getAPIList('/assistants', AssistantsPage, {
6666
query,
6767
...options,
6868
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
@@ -73,7 +73,7 @@ export class Assistants extends APIResource {
7373
* Delete an assistant.
7474
*/
7575
del(assistantId: string, options?: Core.RequestOptions): Core.APIPromise<AssistantDeleted> {
76-
return this.delete(`/assistants/${assistantId}`, {
76+
return this._client.delete(`/assistants/${assistantId}`, {
7777
...options,
7878
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
7979
});

src/resources/beta/assistants/files.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class Files extends APIResource {
1717
body: FileCreateParams,
1818
options?: Core.RequestOptions,
1919
): Core.APIPromise<AssistantFile> {
20-
return this.post(`/assistants/${assistantId}/files`, {
20+
return this._client.post(`/assistants/${assistantId}/files`, {
2121
body,
2222
...options,
2323
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
@@ -32,7 +32,7 @@ export class Files extends APIResource {
3232
fileId: string,
3333
options?: Core.RequestOptions,
3434
): Core.APIPromise<AssistantFile> {
35-
return this.get(`/assistants/${assistantId}/files/${fileId}`, {
35+
return this._client.get(`/assistants/${assistantId}/files/${fileId}`, {
3636
...options,
3737
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
3838
});
@@ -58,7 +58,7 @@ export class Files extends APIResource {
5858
if (isRequestOptions(query)) {
5959
return this.list(assistantId, {}, query);
6060
}
61-
return this.getAPIList(`/assistants/${assistantId}/files`, AssistantFilesPage, {
61+
return this._client.getAPIList(`/assistants/${assistantId}/files`, AssistantFilesPage, {
6262
query,
6363
...options,
6464
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
@@ -73,7 +73,7 @@ export class Files extends APIResource {
7373
fileId: string,
7474
options?: Core.RequestOptions,
7575
): Core.APIPromise<FileDeleteResponse> {
76-
return this.delete(`/assistants/${assistantId}/files/${fileId}`, {
76+
return this._client.delete(`/assistants/${assistantId}/files/${fileId}`, {
7777
...options,
7878
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
7979
});

src/resources/beta/beta.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import * as ChatAPI from 'openai/resources/beta/chat/chat';
66
import * as ThreadsAPI from 'openai/resources/beta/threads/threads';
77

88
export class Beta extends APIResource {
9-
chat: ChatAPI.Chat = new ChatAPI.Chat(this.client);
10-
assistants: AssistantsAPI.Assistants = new AssistantsAPI.Assistants(this.client);
11-
threads: ThreadsAPI.Threads = new ThreadsAPI.Threads(this.client);
9+
chat: ChatAPI.Chat = new ChatAPI.Chat(this._client);
10+
assistants: AssistantsAPI.Assistants = new AssistantsAPI.Assistants(this._client);
11+
threads: ThreadsAPI.Threads = new ThreadsAPI.Threads(this._client);
1212
}
1313

1414
export namespace Beta {

src/resources/beta/chat/chat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { APIResource } from 'openai/resource';
44
import * as CompletionsAPI from 'openai/resources/beta/chat/completions';
55

66
export class Chat extends APIResource {
7-
completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this.client);
7+
completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this._client);
88
}
99

1010
export namespace Chat {

0 commit comments

Comments
 (0)