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

-21
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

+3-16
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

+3-3
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

+1-1
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

+1-1
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

+1-1
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

+6-6
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

+4-4
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

+3-3
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

+1-1
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 {

src/resources/beta/chat/completions.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ export class Completions extends APIResource {
5353
): ChatCompletionRunner | ChatCompletionStreamingRunner {
5454
if (body.stream) {
5555
return ChatCompletionStreamingRunner.runFunctions(
56-
this.client.chat.completions,
56+
this._client.chat.completions,
5757
body as ChatCompletionStreamingFunctionRunnerParams<FunctionsArgs>,
5858
options,
5959
);
6060
}
6161
return ChatCompletionRunner.runFunctions(
62-
this.client.chat.completions,
62+
this._client.chat.completions,
6363
body as ChatCompletionFunctionRunnerParams<FunctionsArgs>,
6464
options,
6565
);
@@ -90,13 +90,13 @@ export class Completions extends APIResource {
9090
): ChatCompletionRunner | ChatCompletionStreamingRunner {
9191
if (body.stream) {
9292
return ChatCompletionStreamingRunner.runTools(
93-
this.client.chat.completions,
93+
this._client.chat.completions,
9494
body as ChatCompletionStreamingToolRunnerParams<FunctionsArgs>,
9595
options,
9696
);
9797
}
9898
return ChatCompletionRunner.runTools(
99-
this.client.chat.completions,
99+
this._client.chat.completions,
100100
body as ChatCompletionToolRunnerParams<FunctionsArgs>,
101101
options,
102102
);
@@ -106,6 +106,6 @@ export class Completions extends APIResource {
106106
* Creates a chat completion stream
107107
*/
108108
stream(body: ChatCompletionStreamParams, options?: Core.RequestOptions): ChatCompletionStream {
109-
return ChatCompletionStream.createChatCompletion(this.client.chat.completions, body, options);
109+
return ChatCompletionStream.createChatCompletion(this._client.chat.completions, body, options);
110110
}
111111
}

src/resources/beta/threads/messages/files.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class Files extends APIResource {
1616
fileId: string,
1717
options?: Core.RequestOptions,
1818
): Core.APIPromise<MessageFile> {
19-
return this.get(`/threads/${threadId}/messages/${messageId}/files/${fileId}`, {
19+
return this._client.get(`/threads/${threadId}/messages/${messageId}/files/${fileId}`, {
2020
...options,
2121
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
2222
});
@@ -45,7 +45,7 @@ export class Files extends APIResource {
4545
if (isRequestOptions(query)) {
4646
return this.list(threadId, messageId, {}, query);
4747
}
48-
return this.getAPIList(`/threads/${threadId}/messages/${messageId}/files`, MessageFilesPage, {
48+
return this._client.getAPIList(`/threads/${threadId}/messages/${messageId}/files`, MessageFilesPage, {
4949
query,
5050
...options,
5151
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },

src/resources/beta/threads/messages/messages.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as FilesAPI from 'openai/resources/beta/threads/messages/files';
88
import { CursorPage, type CursorPageParams } from 'openai/pagination';
99

1010
export class Messages extends APIResource {
11-
files: FilesAPI.Files = new FilesAPI.Files(this.client);
11+
files: FilesAPI.Files = new FilesAPI.Files(this._client);
1212

1313
/**
1414
* Create a message.
@@ -18,7 +18,7 @@ export class Messages extends APIResource {
1818
body: MessageCreateParams,
1919
options?: Core.RequestOptions,
2020
): Core.APIPromise<ThreadMessage> {
21-
return this.post(`/threads/${threadId}/messages`, {
21+
return this._client.post(`/threads/${threadId}/messages`, {
2222
body,
2323
...options,
2424
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
@@ -33,7 +33,7 @@ export class Messages extends APIResource {
3333
messageId: string,
3434
options?: Core.RequestOptions,
3535
): Core.APIPromise<ThreadMessage> {
36-
return this.get(`/threads/${threadId}/messages/${messageId}`, {
36+
return this._client.get(`/threads/${threadId}/messages/${messageId}`, {
3737
...options,
3838
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
3939
});
@@ -48,7 +48,7 @@ export class Messages extends APIResource {
4848
body: MessageUpdateParams,
4949
options?: Core.RequestOptions,
5050
): Core.APIPromise<ThreadMessage> {
51-
return this.post(`/threads/${threadId}/messages/${messageId}`, {
51+
return this._client.post(`/threads/${threadId}/messages/${messageId}`, {
5252
body,
5353
...options,
5454
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
@@ -72,7 +72,7 @@ export class Messages extends APIResource {
7272
if (isRequestOptions(query)) {
7373
return this.list(threadId, {}, query);
7474
}
75-
return this.getAPIList(`/threads/${threadId}/messages`, ThreadMessagesPage, {
75+
return this._client.getAPIList(`/threads/${threadId}/messages`, ThreadMessagesPage, {
7676
query,
7777
...options,
7878
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },

src/resources/beta/threads/runs/runs.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import * as StepsAPI from 'openai/resources/beta/threads/runs/steps';
99
import { CursorPage, type CursorPageParams } from 'openai/pagination';
1010

1111
export class Runs extends APIResource {
12-
steps: StepsAPI.Steps = new StepsAPI.Steps(this.client);
12+
steps: StepsAPI.Steps = new StepsAPI.Steps(this._client);
1313

1414
/**
1515
* Create a run.
1616
*/
1717
create(threadId: string, body: RunCreateParams, options?: Core.RequestOptions): Core.APIPromise<Run> {
18-
return this.post(`/threads/${threadId}/runs`, {
18+
return this._client.post(`/threads/${threadId}/runs`, {
1919
body,
2020
...options,
2121
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
@@ -26,7 +26,7 @@ export class Runs extends APIResource {
2626
* Retrieves a run.
2727
*/
2828
retrieve(threadId: string, runId: string, options?: Core.RequestOptions): Core.APIPromise<Run> {
29-
return this.get(`/threads/${threadId}/runs/${runId}`, {
29+
return this._client.get(`/threads/${threadId}/runs/${runId}`, {
3030
...options,
3131
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
3232
});
@@ -41,7 +41,7 @@ export class Runs extends APIResource {
4141
body: RunUpdateParams,
4242
options?: Core.RequestOptions,
4343
): Core.APIPromise<Run> {
44-
return this.post(`/threads/${threadId}/runs/${runId}`, {
44+
return this._client.post(`/threads/${threadId}/runs/${runId}`, {
4545
body,
4646
...options,
4747
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
@@ -65,7 +65,7 @@ export class Runs extends APIResource {
6565
if (isRequestOptions(query)) {
6666
return this.list(threadId, {}, query);
6767
}
68-
return this.getAPIList(`/threads/${threadId}/runs`, RunsPage, {
68+
return this._client.getAPIList(`/threads/${threadId}/runs`, RunsPage, {
6969
query,
7070
...options,
7171
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
@@ -76,7 +76,7 @@ export class Runs extends APIResource {
7676
* Cancels a run that is `in_progress`.
7777
*/
7878
cancel(threadId: string, runId: string, options?: Core.RequestOptions): Core.APIPromise<Run> {
79-
return this.post(`/threads/${threadId}/runs/${runId}/cancel`, {
79+
return this._client.post(`/threads/${threadId}/runs/${runId}/cancel`, {
8080
...options,
8181
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
8282
});
@@ -94,7 +94,7 @@ export class Runs extends APIResource {
9494
body: RunSubmitToolOutputsParams,
9595
options?: Core.RequestOptions,
9696
): Core.APIPromise<Run> {
97-
return this.post(`/threads/${threadId}/runs/${runId}/submit_tool_outputs`, {
97+
return this._client.post(`/threads/${threadId}/runs/${runId}/submit_tool_outputs`, {
9898
body,
9999
...options,
100100
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },

src/resources/beta/threads/runs/steps.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class Steps extends APIResource {
1616
stepId: string,
1717
options?: Core.RequestOptions,
1818
): Core.APIPromise<RunStep> {
19-
return this.get(`/threads/${threadId}/runs/${runId}/steps/${stepId}`, {
19+
return this._client.get(`/threads/${threadId}/runs/${runId}/steps/${stepId}`, {
2020
...options,
2121
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
2222
});
@@ -45,7 +45,7 @@ export class Steps extends APIResource {
4545
if (isRequestOptions(query)) {
4646
return this.list(threadId, runId, {}, query);
4747
}
48-
return this.getAPIList(`/threads/${threadId}/runs/${runId}/steps`, RunStepsPage, {
48+
return this._client.getAPIList(`/threads/${threadId}/runs/${runId}/steps`, RunStepsPage, {
4949
query,
5050
...options,
5151
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },

0 commit comments

Comments
 (0)