From bdb79f9ed2ad4fdebae3c42cdad97f2ffa109589 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:59:47 +0000 Subject: [PATCH] feat(api): updates (#501) --- src/core.ts | 21 ------------------- src/resource.ts | 19 +++-------------- src/resources/audio/audio.ts | 6 +++--- src/resources/audio/speech.ts | 2 +- src/resources/audio/transcriptions.ts | 2 +- src/resources/audio/translations.ts | 2 +- src/resources/beta/assistants/assistants.ts | 12 +++++------ src/resources/beta/assistants/files.ts | 8 +++---- src/resources/beta/beta.ts | 6 +++--- src/resources/beta/chat/chat.ts | 2 +- src/resources/beta/chat/completions.ts | 10 ++++----- src/resources/beta/threads/messages/files.ts | 4 ++-- .../beta/threads/messages/messages.ts | 10 ++++----- src/resources/beta/threads/runs/runs.ts | 14 ++++++------- src/resources/beta/threads/runs/steps.ts | 4 ++-- src/resources/beta/threads/threads.ts | 14 ++++++------- src/resources/chat/chat.ts | 2 +- src/resources/chat/completions.ts | 2 +- src/resources/completions.ts | 2 +- src/resources/edits.ts | 2 +- src/resources/embeddings.ts | 2 +- src/resources/files.ts | 12 +++++------ src/resources/fine-tunes.ts | 10 ++++----- src/resources/fine-tuning/fine-tuning.ts | 2 +- src/resources/fine-tuning/jobs.ts | 10 ++++----- src/resources/images.ts | 6 +++--- src/resources/models.ts | 6 +++--- src/resources/moderations.ts | 2 +- 28 files changed, 80 insertions(+), 114 deletions(-) diff --git a/src/core.ts b/src/core.ts index 5ff672620..70b8e679c 100644 --- a/src/core.ts +++ b/src/core.ts @@ -564,27 +564,6 @@ export abstract class APIClient { } } -export class APIResource { - protected client: APIClient; - constructor(client: APIClient) { - this.client = client; - - this.get = client.get.bind(client); - this.post = client.post.bind(client); - this.patch = client.patch.bind(client); - this.put = client.put.bind(client); - this.delete = client.delete.bind(client); - this.getAPIList = client.getAPIList.bind(client); - } - - protected get: APIClient['get']; - protected post: APIClient['post']; - protected patch: APIClient['patch']; - protected put: APIClient['put']; - protected delete: APIClient['delete']; - protected getAPIList: APIClient['getAPIList']; -} - export type PageInfo = { url: URL } | { params: Record | null }; export abstract class AbstractPage implements AsyncIterable { diff --git a/src/resource.ts b/src/resource.ts index 9c58ae78b..0bf87cf33 100644 --- a/src/resource.ts +++ b/src/resource.ts @@ -3,22 +3,9 @@ import type { OpenAI } from './index'; export class APIResource { - protected client: OpenAI; - constructor(client: OpenAI) { - this.client = client; + protected _client: OpenAI; - this.get = client.get.bind(client); - this.post = client.post.bind(client); - this.patch = client.patch.bind(client); - this.put = client.put.bind(client); - this.delete = client.delete.bind(client); - this.getAPIList = client.getAPIList.bind(client); + constructor(client: OpenAI) { + this._client = client; } - - protected get: OpenAI['get']; - protected post: OpenAI['post']; - protected patch: OpenAI['patch']; - protected put: OpenAI['put']; - protected delete: OpenAI['delete']; - protected getAPIList: OpenAI['getAPIList']; } diff --git a/src/resources/audio/audio.ts b/src/resources/audio/audio.ts index ee8c28c6b..960577b0d 100644 --- a/src/resources/audio/audio.ts +++ b/src/resources/audio/audio.ts @@ -6,9 +6,9 @@ import * as TranscriptionsAPI from 'openai/resources/audio/transcriptions'; import * as TranslationsAPI from 'openai/resources/audio/translations'; export class Audio extends APIResource { - transcriptions: TranscriptionsAPI.Transcriptions = new TranscriptionsAPI.Transcriptions(this.client); - translations: TranslationsAPI.Translations = new TranslationsAPI.Translations(this.client); - speech: SpeechAPI.Speech = new SpeechAPI.Speech(this.client); + transcriptions: TranscriptionsAPI.Transcriptions = new TranscriptionsAPI.Transcriptions(this._client); + translations: TranslationsAPI.Translations = new TranslationsAPI.Translations(this._client); + speech: SpeechAPI.Speech = new SpeechAPI.Speech(this._client); } export namespace Audio { diff --git a/src/resources/audio/speech.ts b/src/resources/audio/speech.ts index c8199e746..89e426847 100644 --- a/src/resources/audio/speech.ts +++ b/src/resources/audio/speech.ts @@ -10,7 +10,7 @@ export class Speech extends APIResource { * Generates audio from the input text. */ create(body: SpeechCreateParams, options?: Core.RequestOptions): Core.APIPromise { - return this.post('/audio/speech', { body, ...options, __binaryResponse: true }); + return this._client.post('/audio/speech', { body, ...options, __binaryResponse: true }); } } diff --git a/src/resources/audio/transcriptions.ts b/src/resources/audio/transcriptions.ts index feb37df09..aaf62bd29 100644 --- a/src/resources/audio/transcriptions.ts +++ b/src/resources/audio/transcriptions.ts @@ -10,7 +10,7 @@ export class Transcriptions extends APIResource { * Transcribes audio into the input language. */ create(body: TranscriptionCreateParams, options?: Core.RequestOptions): Core.APIPromise { - return this.post('/audio/transcriptions', multipartFormRequestOptions({ body, ...options })); + return this._client.post('/audio/transcriptions', multipartFormRequestOptions({ body, ...options })); } } diff --git a/src/resources/audio/translations.ts b/src/resources/audio/translations.ts index 58e3ab7e7..54583ce1f 100644 --- a/src/resources/audio/translations.ts +++ b/src/resources/audio/translations.ts @@ -10,7 +10,7 @@ export class Translations extends APIResource { * Translates audio into English. */ create(body: TranslationCreateParams, options?: Core.RequestOptions): Core.APIPromise { - return this.post('/audio/translations', multipartFormRequestOptions({ body, ...options })); + return this._client.post('/audio/translations', multipartFormRequestOptions({ body, ...options })); } } diff --git a/src/resources/beta/assistants/assistants.ts b/src/resources/beta/assistants/assistants.ts index 052a3d666..3b13a84bb 100644 --- a/src/resources/beta/assistants/assistants.ts +++ b/src/resources/beta/assistants/assistants.ts @@ -9,13 +9,13 @@ import * as FilesAPI from 'openai/resources/beta/assistants/files'; import { CursorPage, type CursorPageParams } from 'openai/pagination'; export class Assistants extends APIResource { - files: FilesAPI.Files = new FilesAPI.Files(this.client); + files: FilesAPI.Files = new FilesAPI.Files(this._client); /** * Create an assistant with a model and instructions. */ create(body: AssistantCreateParams, options?: Core.RequestOptions): Core.APIPromise { - return this.post('/assistants', { + return this._client.post('/assistants', { body, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, @@ -26,7 +26,7 @@ export class Assistants extends APIResource { * Retrieves an assistant. */ retrieve(assistantId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.get(`/assistants/${assistantId}`, { + return this._client.get(`/assistants/${assistantId}`, { ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, }); @@ -40,7 +40,7 @@ export class Assistants extends APIResource { body: AssistantUpdateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this.post(`/assistants/${assistantId}`, { + return this._client.post(`/assistants/${assistantId}`, { body, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, @@ -62,7 +62,7 @@ export class Assistants extends APIResource { if (isRequestOptions(query)) { return this.list({}, query); } - return this.getAPIList('/assistants', AssistantsPage, { + return this._client.getAPIList('/assistants', AssistantsPage, { query, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, @@ -73,7 +73,7 @@ export class Assistants extends APIResource { * Delete an assistant. */ del(assistantId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.delete(`/assistants/${assistantId}`, { + return this._client.delete(`/assistants/${assistantId}`, { ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, }); diff --git a/src/resources/beta/assistants/files.ts b/src/resources/beta/assistants/files.ts index 7733cff9a..7de700e50 100644 --- a/src/resources/beta/assistants/files.ts +++ b/src/resources/beta/assistants/files.ts @@ -17,7 +17,7 @@ export class Files extends APIResource { body: FileCreateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this.post(`/assistants/${assistantId}/files`, { + return this._client.post(`/assistants/${assistantId}/files`, { body, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, @@ -32,7 +32,7 @@ export class Files extends APIResource { fileId: string, options?: Core.RequestOptions, ): Core.APIPromise { - return this.get(`/assistants/${assistantId}/files/${fileId}`, { + return this._client.get(`/assistants/${assistantId}/files/${fileId}`, { ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, }); @@ -58,7 +58,7 @@ export class Files extends APIResource { if (isRequestOptions(query)) { return this.list(assistantId, {}, query); } - return this.getAPIList(`/assistants/${assistantId}/files`, AssistantFilesPage, { + return this._client.getAPIList(`/assistants/${assistantId}/files`, AssistantFilesPage, { query, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, @@ -73,7 +73,7 @@ export class Files extends APIResource { fileId: string, options?: Core.RequestOptions, ): Core.APIPromise { - return this.delete(`/assistants/${assistantId}/files/${fileId}`, { + return this._client.delete(`/assistants/${assistantId}/files/${fileId}`, { ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, }); diff --git a/src/resources/beta/beta.ts b/src/resources/beta/beta.ts index ed721d8f8..5fd99990d 100644 --- a/src/resources/beta/beta.ts +++ b/src/resources/beta/beta.ts @@ -6,9 +6,9 @@ import * as ChatAPI from 'openai/resources/beta/chat/chat'; import * as ThreadsAPI from 'openai/resources/beta/threads/threads'; export class Beta extends APIResource { - chat: ChatAPI.Chat = new ChatAPI.Chat(this.client); - assistants: AssistantsAPI.Assistants = new AssistantsAPI.Assistants(this.client); - threads: ThreadsAPI.Threads = new ThreadsAPI.Threads(this.client); + chat: ChatAPI.Chat = new ChatAPI.Chat(this._client); + assistants: AssistantsAPI.Assistants = new AssistantsAPI.Assistants(this._client); + threads: ThreadsAPI.Threads = new ThreadsAPI.Threads(this._client); } export namespace Beta { diff --git a/src/resources/beta/chat/chat.ts b/src/resources/beta/chat/chat.ts index c871fab2f..a9cadc681 100644 --- a/src/resources/beta/chat/chat.ts +++ b/src/resources/beta/chat/chat.ts @@ -4,7 +4,7 @@ import { APIResource } from 'openai/resource'; import * as CompletionsAPI from 'openai/resources/beta/chat/completions'; export class Chat extends APIResource { - completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this.client); + completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this._client); } export namespace Chat { diff --git a/src/resources/beta/chat/completions.ts b/src/resources/beta/chat/completions.ts index 1164b787f..f4904acb7 100644 --- a/src/resources/beta/chat/completions.ts +++ b/src/resources/beta/chat/completions.ts @@ -53,13 +53,13 @@ export class Completions extends APIResource { ): ChatCompletionRunner | ChatCompletionStreamingRunner { if (body.stream) { return ChatCompletionStreamingRunner.runFunctions( - this.client.chat.completions, + this._client.chat.completions, body as ChatCompletionStreamingFunctionRunnerParams, options, ); } return ChatCompletionRunner.runFunctions( - this.client.chat.completions, + this._client.chat.completions, body as ChatCompletionFunctionRunnerParams, options, ); @@ -90,13 +90,13 @@ export class Completions extends APIResource { ): ChatCompletionRunner | ChatCompletionStreamingRunner { if (body.stream) { return ChatCompletionStreamingRunner.runTools( - this.client.chat.completions, + this._client.chat.completions, body as ChatCompletionStreamingToolRunnerParams, options, ); } return ChatCompletionRunner.runTools( - this.client.chat.completions, + this._client.chat.completions, body as ChatCompletionToolRunnerParams, options, ); @@ -106,6 +106,6 @@ export class Completions extends APIResource { * Creates a chat completion stream */ stream(body: ChatCompletionStreamParams, options?: Core.RequestOptions): ChatCompletionStream { - return ChatCompletionStream.createChatCompletion(this.client.chat.completions, body, options); + return ChatCompletionStream.createChatCompletion(this._client.chat.completions, body, options); } } diff --git a/src/resources/beta/threads/messages/files.ts b/src/resources/beta/threads/messages/files.ts index 4bbc06538..72c01bb97 100644 --- a/src/resources/beta/threads/messages/files.ts +++ b/src/resources/beta/threads/messages/files.ts @@ -16,7 +16,7 @@ export class Files extends APIResource { fileId: string, options?: Core.RequestOptions, ): Core.APIPromise { - return this.get(`/threads/${threadId}/messages/${messageId}/files/${fileId}`, { + return this._client.get(`/threads/${threadId}/messages/${messageId}/files/${fileId}`, { ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, }); @@ -45,7 +45,7 @@ export class Files extends APIResource { if (isRequestOptions(query)) { return this.list(threadId, messageId, {}, query); } - return this.getAPIList(`/threads/${threadId}/messages/${messageId}/files`, MessageFilesPage, { + return this._client.getAPIList(`/threads/${threadId}/messages/${messageId}/files`, MessageFilesPage, { query, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, diff --git a/src/resources/beta/threads/messages/messages.ts b/src/resources/beta/threads/messages/messages.ts index cf7bf35e5..40b436829 100644 --- a/src/resources/beta/threads/messages/messages.ts +++ b/src/resources/beta/threads/messages/messages.ts @@ -8,7 +8,7 @@ import * as FilesAPI from 'openai/resources/beta/threads/messages/files'; import { CursorPage, type CursorPageParams } from 'openai/pagination'; export class Messages extends APIResource { - files: FilesAPI.Files = new FilesAPI.Files(this.client); + files: FilesAPI.Files = new FilesAPI.Files(this._client); /** * Create a message. @@ -18,7 +18,7 @@ export class Messages extends APIResource { body: MessageCreateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this.post(`/threads/${threadId}/messages`, { + return this._client.post(`/threads/${threadId}/messages`, { body, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, @@ -33,7 +33,7 @@ export class Messages extends APIResource { messageId: string, options?: Core.RequestOptions, ): Core.APIPromise { - return this.get(`/threads/${threadId}/messages/${messageId}`, { + return this._client.get(`/threads/${threadId}/messages/${messageId}`, { ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, }); @@ -48,7 +48,7 @@ export class Messages extends APIResource { body: MessageUpdateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this.post(`/threads/${threadId}/messages/${messageId}`, { + return this._client.post(`/threads/${threadId}/messages/${messageId}`, { body, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, @@ -72,7 +72,7 @@ export class Messages extends APIResource { if (isRequestOptions(query)) { return this.list(threadId, {}, query); } - return this.getAPIList(`/threads/${threadId}/messages`, ThreadMessagesPage, { + return this._client.getAPIList(`/threads/${threadId}/messages`, ThreadMessagesPage, { query, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, diff --git a/src/resources/beta/threads/runs/runs.ts b/src/resources/beta/threads/runs/runs.ts index c2fc93a3c..f59fdff3f 100644 --- a/src/resources/beta/threads/runs/runs.ts +++ b/src/resources/beta/threads/runs/runs.ts @@ -9,13 +9,13 @@ import * as StepsAPI from 'openai/resources/beta/threads/runs/steps'; import { CursorPage, type CursorPageParams } from 'openai/pagination'; export class Runs extends APIResource { - steps: StepsAPI.Steps = new StepsAPI.Steps(this.client); + steps: StepsAPI.Steps = new StepsAPI.Steps(this._client); /** * Create a run. */ create(threadId: string, body: RunCreateParams, options?: Core.RequestOptions): Core.APIPromise { - return this.post(`/threads/${threadId}/runs`, { + return this._client.post(`/threads/${threadId}/runs`, { body, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, @@ -26,7 +26,7 @@ export class Runs extends APIResource { * Retrieves a run. */ retrieve(threadId: string, runId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.get(`/threads/${threadId}/runs/${runId}`, { + return this._client.get(`/threads/${threadId}/runs/${runId}`, { ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, }); @@ -41,7 +41,7 @@ export class Runs extends APIResource { body: RunUpdateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this.post(`/threads/${threadId}/runs/${runId}`, { + return this._client.post(`/threads/${threadId}/runs/${runId}`, { body, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, @@ -65,7 +65,7 @@ export class Runs extends APIResource { if (isRequestOptions(query)) { return this.list(threadId, {}, query); } - return this.getAPIList(`/threads/${threadId}/runs`, RunsPage, { + return this._client.getAPIList(`/threads/${threadId}/runs`, RunsPage, { query, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, @@ -76,7 +76,7 @@ export class Runs extends APIResource { * Cancels a run that is `in_progress`. */ cancel(threadId: string, runId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.post(`/threads/${threadId}/runs/${runId}/cancel`, { + return this._client.post(`/threads/${threadId}/runs/${runId}/cancel`, { ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, }); @@ -94,7 +94,7 @@ export class Runs extends APIResource { body: RunSubmitToolOutputsParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this.post(`/threads/${threadId}/runs/${runId}/submit_tool_outputs`, { + return this._client.post(`/threads/${threadId}/runs/${runId}/submit_tool_outputs`, { body, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, diff --git a/src/resources/beta/threads/runs/steps.ts b/src/resources/beta/threads/runs/steps.ts index 6f3b5624a..9a335a1aa 100644 --- a/src/resources/beta/threads/runs/steps.ts +++ b/src/resources/beta/threads/runs/steps.ts @@ -16,7 +16,7 @@ export class Steps extends APIResource { stepId: string, options?: Core.RequestOptions, ): Core.APIPromise { - return this.get(`/threads/${threadId}/runs/${runId}/steps/${stepId}`, { + return this._client.get(`/threads/${threadId}/runs/${runId}/steps/${stepId}`, { ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, }); @@ -45,7 +45,7 @@ export class Steps extends APIResource { if (isRequestOptions(query)) { return this.list(threadId, runId, {}, query); } - return this.getAPIList(`/threads/${threadId}/runs/${runId}/steps`, RunStepsPage, { + return this._client.getAPIList(`/threads/${threadId}/runs/${runId}/steps`, RunStepsPage, { query, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, diff --git a/src/resources/beta/threads/threads.ts b/src/resources/beta/threads/threads.ts index c147cefad..8bbe1804f 100644 --- a/src/resources/beta/threads/threads.ts +++ b/src/resources/beta/threads/threads.ts @@ -9,8 +9,8 @@ import * as MessagesAPI from 'openai/resources/beta/threads/messages/messages'; import * as RunsAPI from 'openai/resources/beta/threads/runs/runs'; export class Threads extends APIResource { - runs: RunsAPI.Runs = new RunsAPI.Runs(this.client); - messages: MessagesAPI.Messages = new MessagesAPI.Messages(this.client); + runs: RunsAPI.Runs = new RunsAPI.Runs(this._client); + messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client); /** * Create a thread. @@ -24,7 +24,7 @@ export class Threads extends APIResource { if (isRequestOptions(body)) { return this.create({}, body); } - return this.post('/threads', { + return this._client.post('/threads', { body, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, @@ -35,7 +35,7 @@ export class Threads extends APIResource { * Retrieves a thread. */ retrieve(threadId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.get(`/threads/${threadId}`, { + return this._client.get(`/threads/${threadId}`, { ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, }); @@ -45,7 +45,7 @@ export class Threads extends APIResource { * Modifies a thread. */ update(threadId: string, body: ThreadUpdateParams, options?: Core.RequestOptions): Core.APIPromise { - return this.post(`/threads/${threadId}`, { + return this._client.post(`/threads/${threadId}`, { body, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, @@ -56,7 +56,7 @@ export class Threads extends APIResource { * Delete a thread. */ del(threadId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.delete(`/threads/${threadId}`, { + return this._client.delete(`/threads/${threadId}`, { ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, }); @@ -66,7 +66,7 @@ export class Threads extends APIResource { * Create a thread and run it in one request. */ createAndRun(body: ThreadCreateAndRunParams, options?: Core.RequestOptions): Core.APIPromise { - return this.post('/threads/runs', { + return this._client.post('/threads/runs', { body, ...options, headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers }, diff --git a/src/resources/chat/chat.ts b/src/resources/chat/chat.ts index 007c9271a..63e857e9b 100644 --- a/src/resources/chat/chat.ts +++ b/src/resources/chat/chat.ts @@ -4,7 +4,7 @@ import { APIResource } from 'openai/resource'; import * as CompletionsAPI from 'openai/resources/chat/completions'; export class Chat extends APIResource { - completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this.client); + completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this._client); } export namespace Chat { diff --git a/src/resources/chat/completions.ts b/src/resources/chat/completions.ts index 57aa68ff4..3f83a7dd4 100644 --- a/src/resources/chat/completions.ts +++ b/src/resources/chat/completions.ts @@ -28,7 +28,7 @@ export class Completions extends APIResource { body: ChatCompletionCreateParams, options?: Core.RequestOptions, ): APIPromise | APIPromise> { - return this.post('/chat/completions', { body, ...options, stream: body.stream ?? false }) as + return this._client.post('/chat/completions', { body, ...options, stream: body.stream ?? false }) as | APIPromise | APIPromise>; } diff --git a/src/resources/completions.ts b/src/resources/completions.ts index c314e7cf8..0bee93131 100644 --- a/src/resources/completions.ts +++ b/src/resources/completions.ts @@ -23,7 +23,7 @@ export class Completions extends APIResource { body: CompletionCreateParams, options?: Core.RequestOptions, ): APIPromise | APIPromise> { - return this.post('/completions', { body, ...options, stream: body.stream ?? false }) as + return this._client.post('/completions', { body, ...options, stream: body.stream ?? false }) as | APIPromise | APIPromise>; } diff --git a/src/resources/edits.ts b/src/resources/edits.ts index a6512a1e9..0b7b4802b 100644 --- a/src/resources/edits.ts +++ b/src/resources/edits.ts @@ -14,7 +14,7 @@ export class Edits extends APIResource { * https://openai.com/blog/gpt-4-api-general-availability#deprecation-of-the-edits-api */ create(body: EditCreateParams, options?: Core.RequestOptions): Core.APIPromise { - return this.post('/edits', { body, ...options }); + return this._client.post('/edits', { body, ...options }); } } diff --git a/src/resources/embeddings.ts b/src/resources/embeddings.ts index 93637821d..7ace4589d 100644 --- a/src/resources/embeddings.ts +++ b/src/resources/embeddings.ts @@ -12,7 +12,7 @@ export class Embeddings extends APIResource { body: EmbeddingCreateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this.post('/embeddings', { body, ...options }); + return this._client.post('/embeddings', { body, ...options }); } } diff --git a/src/resources/files.ts b/src/resources/files.ts index 4dda2f7ba..8e3a759d9 100644 --- a/src/resources/files.ts +++ b/src/resources/files.ts @@ -24,14 +24,14 @@ export class Files extends APIResource { * storage limits. */ create(body: FileCreateParams, options?: Core.RequestOptions): Core.APIPromise { - return this.post('/files', multipartFormRequestOptions({ body, ...options })); + return this._client.post('/files', multipartFormRequestOptions({ body, ...options })); } /** * Returns information about a specific file. */ retrieve(fileId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.get(`/files/${fileId}`, options); + return this._client.get(`/files/${fileId}`, options); } /** @@ -46,21 +46,21 @@ export class Files extends APIResource { if (isRequestOptions(query)) { return this.list({}, query); } - return this.getAPIList('/files', FileObjectsPage, { query, ...options }); + return this._client.getAPIList('/files', FileObjectsPage, { query, ...options }); } /** * Delete a file. */ del(fileId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.delete(`/files/${fileId}`, options); + return this._client.delete(`/files/${fileId}`, options); } /** * Returns the contents of the specified file. */ content(fileId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.get(`/files/${fileId}/content`, { ...options, __binaryResponse: true }); + return this._client.get(`/files/${fileId}/content`, { ...options, __binaryResponse: true }); } /** @@ -69,7 +69,7 @@ export class Files extends APIResource { * @deprecated The `.content()` method should be used instead */ retrieveContent(fileId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.get(`/files/${fileId}/content`, { + return this._client.get(`/files/${fileId}/content`, { ...options, headers: { Accept: 'application/json', ...options?.headers }, }); diff --git a/src/resources/fine-tunes.ts b/src/resources/fine-tunes.ts index 59551452f..8e8193720 100644 --- a/src/resources/fine-tunes.ts +++ b/src/resources/fine-tunes.ts @@ -18,7 +18,7 @@ export class FineTunes extends APIResource { * [Learn more about fine-tuning](https://platform.openai.com/docs/guides/legacy-fine-tuning) */ create(body: FineTuneCreateParams, options?: Core.RequestOptions): Core.APIPromise { - return this.post('/fine-tunes', { body, ...options }); + return this._client.post('/fine-tunes', { body, ...options }); } /** @@ -27,21 +27,21 @@ export class FineTunes extends APIResource { * [Learn more about fine-tuning](https://platform.openai.com/docs/guides/legacy-fine-tuning) */ retrieve(fineTuneId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.get(`/fine-tunes/${fineTuneId}`, options); + return this._client.get(`/fine-tunes/${fineTuneId}`, options); } /** * List your organization's fine-tuning jobs */ list(options?: Core.RequestOptions): Core.PagePromise { - return this.getAPIList('/fine-tunes', FineTunesPage, options); + return this._client.getAPIList('/fine-tunes', FineTunesPage, options); } /** * Immediately cancel a fine-tune job. */ cancel(fineTuneId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.post(`/fine-tunes/${fineTuneId}/cancel`, options); + return this._client.post(`/fine-tunes/${fineTuneId}/cancel`, options); } /** @@ -67,7 +67,7 @@ export class FineTunes extends APIResource { query?: FineTuneListEventsParams | undefined, options?: Core.RequestOptions, ): APIPromise | APIPromise> { - return this.get(`/fine-tunes/${fineTuneId}/events`, { + return this._client.get(`/fine-tunes/${fineTuneId}/events`, { query, timeout: 86400000, ...options, diff --git a/src/resources/fine-tuning/fine-tuning.ts b/src/resources/fine-tuning/fine-tuning.ts index 3c0a5a852..5d2d27ac3 100644 --- a/src/resources/fine-tuning/fine-tuning.ts +++ b/src/resources/fine-tuning/fine-tuning.ts @@ -4,7 +4,7 @@ import { APIResource } from 'openai/resource'; import * as JobsAPI from 'openai/resources/fine-tuning/jobs'; export class FineTuning extends APIResource { - jobs: JobsAPI.Jobs = new JobsAPI.Jobs(this.client); + jobs: JobsAPI.Jobs = new JobsAPI.Jobs(this._client); } export namespace FineTuning { diff --git a/src/resources/fine-tuning/jobs.ts b/src/resources/fine-tuning/jobs.ts index ad5ef3e0b..9e013b27a 100644 --- a/src/resources/fine-tuning/jobs.ts +++ b/src/resources/fine-tuning/jobs.ts @@ -16,7 +16,7 @@ export class Jobs extends APIResource { * [Learn more about fine-tuning](https://platform.openai.com/docs/guides/fine-tuning) */ create(body: JobCreateParams, options?: Core.RequestOptions): Core.APIPromise { - return this.post('/fine_tuning/jobs', { body, ...options }); + return this._client.post('/fine_tuning/jobs', { body, ...options }); } /** @@ -25,7 +25,7 @@ export class Jobs extends APIResource { * [Learn more about fine-tuning](https://platform.openai.com/docs/guides/fine-tuning) */ retrieve(fineTuningJobId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.get(`/fine_tuning/jobs/${fineTuningJobId}`, options); + return this._client.get(`/fine_tuning/jobs/${fineTuningJobId}`, options); } /** @@ -43,14 +43,14 @@ export class Jobs extends APIResource { if (isRequestOptions(query)) { return this.list({}, query); } - return this.getAPIList('/fine_tuning/jobs', FineTuningJobsPage, { query, ...options }); + return this._client.getAPIList('/fine_tuning/jobs', FineTuningJobsPage, { query, ...options }); } /** * Immediately cancel a fine-tune job. */ cancel(fineTuningJobId: string, options?: Core.RequestOptions): Core.APIPromise { - return this.post(`/fine_tuning/jobs/${fineTuningJobId}/cancel`, options); + return this._client.post(`/fine_tuning/jobs/${fineTuningJobId}/cancel`, options); } /** @@ -73,7 +73,7 @@ export class Jobs extends APIResource { if (isRequestOptions(query)) { return this.listEvents(fineTuningJobId, {}, query); } - return this.getAPIList(`/fine_tuning/jobs/${fineTuningJobId}/events`, FineTuningJobEventsPage, { + return this._client.getAPIList(`/fine_tuning/jobs/${fineTuningJobId}/events`, FineTuningJobEventsPage, { query, ...options, }); diff --git a/src/resources/images.ts b/src/resources/images.ts index 36744cb38..4bc654903 100644 --- a/src/resources/images.ts +++ b/src/resources/images.ts @@ -13,21 +13,21 @@ export class Images extends APIResource { body: ImageCreateVariationParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this.post('/images/variations', multipartFormRequestOptions({ body, ...options })); + return this._client.post('/images/variations', multipartFormRequestOptions({ body, ...options })); } /** * Creates an edited or extended image given an original image and a prompt. */ edit(body: ImageEditParams, options?: Core.RequestOptions): Core.APIPromise { - return this.post('/images/edits', multipartFormRequestOptions({ body, ...options })); + return this._client.post('/images/edits', multipartFormRequestOptions({ body, ...options })); } /** * Creates an image given a prompt. */ generate(body: ImageGenerateParams, options?: Core.RequestOptions): Core.APIPromise { - return this.post('/images/generations', { body, ...options }); + return this._client.post('/images/generations', { body, ...options }); } } diff --git a/src/resources/models.ts b/src/resources/models.ts index 4954ab4dd..6c6c3379c 100644 --- a/src/resources/models.ts +++ b/src/resources/models.ts @@ -11,7 +11,7 @@ export class Models extends APIResource { * the owner and permissioning. */ retrieve(model: string, options?: Core.RequestOptions): Core.APIPromise { - return this.get(`/models/${model}`, options); + return this._client.get(`/models/${model}`, options); } /** @@ -19,7 +19,7 @@ export class Models extends APIResource { * one such as the owner and availability. */ list(options?: Core.RequestOptions): Core.PagePromise { - return this.getAPIList('/models', ModelsPage, options); + return this._client.getAPIList('/models', ModelsPage, options); } /** @@ -27,7 +27,7 @@ export class Models extends APIResource { * delete a model. */ del(model: string, options?: Core.RequestOptions): Core.APIPromise { - return this.delete(`/models/${model}`, options); + return this._client.delete(`/models/${model}`, options); } } diff --git a/src/resources/moderations.ts b/src/resources/moderations.ts index 21603ceea..5beda53ac 100644 --- a/src/resources/moderations.ts +++ b/src/resources/moderations.ts @@ -12,7 +12,7 @@ export class Moderations extends APIResource { body: ModerationCreateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this.post('/moderations', { body, ...options }); + return this._client.post('/moderations', { body, ...options }); } }