Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: re-export chat completion types at the top level, and work around webpack limitations #365

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 41 additions & 33 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import * as Core from './core';
import * as Pagination from './pagination';
import * as API from './resources/index';
import * as Errors from './error';
import { type Agent } from './_shims/index';
import * as Uploads from './uploads';
import * as API from 'openai/resources/index';

export interface ClientOptions {
/**
Expand Down Expand Up @@ -213,61 +213,69 @@ export namespace OpenAI {
export import CursorPageResponse = Pagination.CursorPageResponse;

export import Completions = API.Completions;
export import Completion = API.Completion;
export import CompletionChoice = API.CompletionChoice;
export import CompletionUsage = API.CompletionUsage;
export import CompletionCreateParams = API.CompletionCreateParams;
export import CompletionCreateParamsNonStreaming = API.CompletionCreateParamsNonStreaming;
export import CompletionCreateParamsStreaming = API.CompletionCreateParamsStreaming;
export type Completion = API.Completion;
export type CompletionChoice = API.CompletionChoice;
export type CompletionUsage = API.CompletionUsage;
export type CompletionCreateParams = API.CompletionCreateParams;
export type CompletionCreateParamsNonStreaming = API.CompletionCreateParamsNonStreaming;
export type CompletionCreateParamsStreaming = API.CompletionCreateParamsStreaming;

export import Chat = API.Chat;
export type ChatCompletion = API.ChatCompletion;
export type ChatCompletionChunk = API.ChatCompletionChunk;
export type ChatCompletionMessage = API.ChatCompletionMessage;
export type ChatCompletionMessageParam = API.ChatCompletionMessageParam;
export type ChatCompletionRole = API.ChatCompletionRole;
export type ChatCompletionCreateParams = API.ChatCompletionCreateParams;
export type ChatCompletionCreateParamsNonStreaming = API.ChatCompletionCreateParamsNonStreaming;
export type ChatCompletionCreateParamsStreaming = API.ChatCompletionCreateParamsStreaming;

export import Edits = API.Edits;
export import Edit = API.Edit;
export import EditCreateParams = API.EditCreateParams;
export type Edit = API.Edit;
export type EditCreateParams = API.EditCreateParams;

export import Embeddings = API.Embeddings;
export import CreateEmbeddingResponse = API.CreateEmbeddingResponse;
export import Embedding = API.Embedding;
export import EmbeddingCreateParams = API.EmbeddingCreateParams;
export type CreateEmbeddingResponse = API.CreateEmbeddingResponse;
export type Embedding = API.Embedding;
export type EmbeddingCreateParams = API.EmbeddingCreateParams;

export import Files = API.Files;
export import FileContent = API.FileContent;
export import FileDeleted = API.FileDeleted;
export import FileObject = API.FileObject;
export type FileContent = API.FileContent;
export type FileDeleted = API.FileDeleted;
export type FileObject = API.FileObject;
export import FileObjectsPage = API.FileObjectsPage;
export import FileCreateParams = API.FileCreateParams;
export type FileCreateParams = API.FileCreateParams;

export import Images = API.Images;
export import Image = API.Image;
export import ImagesResponse = API.ImagesResponse;
export import ImageCreateVariationParams = API.ImageCreateVariationParams;
export import ImageEditParams = API.ImageEditParams;
export import ImageGenerateParams = API.ImageGenerateParams;
export type Image = API.Image;
export type ImagesResponse = API.ImagesResponse;
export type ImageCreateVariationParams = API.ImageCreateVariationParams;
export type ImageEditParams = API.ImageEditParams;
export type ImageGenerateParams = API.ImageGenerateParams;

export import Audio = API.Audio;

export import Moderations = API.Moderations;
export import Moderation = API.Moderation;
export import ModerationCreateResponse = API.ModerationCreateResponse;
export import ModerationCreateParams = API.ModerationCreateParams;
export type Moderation = API.Moderation;
export type ModerationCreateResponse = API.ModerationCreateResponse;
export type ModerationCreateParams = API.ModerationCreateParams;

export import Models = API.Models;
export import Model = API.Model;
export import ModelDeleted = API.ModelDeleted;
export type Model = API.Model;
export type ModelDeleted = API.ModelDeleted;
export import ModelsPage = API.ModelsPage;

export import FineTuning = API.FineTuning;

export import FineTunes = API.FineTunes;
export import FineTune = API.FineTune;
export import FineTuneEvent = API.FineTuneEvent;
export import FineTuneEventsListResponse = API.FineTuneEventsListResponse;
export type FineTune = API.FineTune;
export type FineTuneEvent = API.FineTuneEvent;
export type FineTuneEventsListResponse = API.FineTuneEventsListResponse;
export import FineTunesPage = API.FineTunesPage;
export import FineTuneCreateParams = API.FineTuneCreateParams;
export import FineTuneListEventsParams = API.FineTuneListEventsParams;
export import FineTuneListEventsParamsNonStreaming = API.FineTuneListEventsParamsNonStreaming;
export import FineTuneListEventsParamsStreaming = API.FineTuneListEventsParamsStreaming;
export type FineTuneCreateParams = API.FineTuneCreateParams;
export type FineTuneListEventsParams = API.FineTuneListEventsParams;
export type FineTuneListEventsParamsNonStreaming = API.FineTuneListEventsParamsNonStreaming;
export type FineTuneListEventsParamsStreaming = API.FineTuneListEventsParamsStreaming;
}

export default OpenAI;
6 changes: 3 additions & 3 deletions src/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export interface PageResponse<Item> {
* Note: no pagination actually occurs yet, this is for forwards-compatibility.
*/
export class Page<Item> extends AbstractPage<Item> implements PageResponse<Item> {
object: string;

data: Array<Item>;

object: string;

constructor(client: APIClient, response: Response, body: PageResponse<Item>, options: FinalRequestOptions) {
super(client, response, body, options);

this.object = body.object;
this.data = body.data;
this.object = body.object;
}

getPaginatedItems(): Item[] {
Expand Down
22 changes: 10 additions & 12 deletions src/resources/audio/audio.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
// File generated from our OpenAPI spec by Stainless.

import { APIResource } from 'openai/resource';
import { Transcriptions } from './transcriptions';
import { Translations } from './translations';
import * as API from './index';
import * as TranscriptionsAPI from 'openai/resources/audio/transcriptions';
import * as TranslationsAPI from 'openai/resources/audio/translations';

export class Audio extends APIResource {
transcriptions: Transcriptions = new Transcriptions(this.client);
translations: Translations = new Translations(this.client);
transcriptions: TranscriptionsAPI.Transcriptions = new TranscriptionsAPI.Transcriptions(this.client);
translations: TranslationsAPI.Translations = new TranslationsAPI.Translations(this.client);
}

export namespace Audio {
export import Transcriptions = API.Transcriptions;
export import Transcription = API.Transcription;
export import TranscriptionCreateParams = API.TranscriptionCreateParams;

export import Translations = API.Translations;
export import Translation = API.Translation;
export import TranslationCreateParams = API.TranslationCreateParams;
export import Transcriptions = TranscriptionsAPI.Transcriptions;
export type Transcription = TranscriptionsAPI.Transcription;
export type TranscriptionCreateParams = TranscriptionsAPI.TranscriptionCreateParams;
export import Translations = TranslationsAPI.Translations;
export type Translation = TranslationsAPI.Translation;
export type TranslationCreateParams = TranslationsAPI.TranslationCreateParams;
}
6 changes: 3 additions & 3 deletions src/resources/audio/transcriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as Core from 'openai/core';
import { APIResource } from 'openai/resource';
import * as API from './index';
import * as TranscriptionsAPI from 'openai/resources/audio/transcriptions';
import { type Uploadable, multipartFormRequestOptions } from 'openai/core';

export class Transcriptions extends APIResource {
Expand Down Expand Up @@ -62,6 +62,6 @@ export interface TranscriptionCreateParams {
}

export namespace Transcriptions {
export import Transcription = API.Transcription;
export import TranscriptionCreateParams = API.TranscriptionCreateParams;
export type Transcription = TranscriptionsAPI.Transcription;
export type TranscriptionCreateParams = TranscriptionsAPI.TranscriptionCreateParams;
}
6 changes: 3 additions & 3 deletions src/resources/audio/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as Core from 'openai/core';
import { APIResource } from 'openai/resource';
import * as API from './index';
import * as TranslationsAPI from 'openai/resources/audio/translations';
import { type Uploadable, multipartFormRequestOptions } from 'openai/core';

export class Translations extends APIResource {
Expand Down Expand Up @@ -55,6 +55,6 @@ export interface TranslationCreateParams {
}

export namespace Translations {
export import Translation = API.Translation;
export import TranslationCreateParams = API.TranslationCreateParams;
export type Translation = TranslationsAPI.Translation;
export type TranslationCreateParams = TranslationsAPI.TranslationCreateParams;
}
31 changes: 15 additions & 16 deletions src/resources/chat/chat.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// File generated from our OpenAPI spec by Stainless.

import { APIResource } from 'openai/resource';
import { Completions } from './completions';
import * as API from './index';
import * as CompletionsAPI from 'openai/resources/chat/completions';

export class Chat extends APIResource {
completions: Completions = new Completions(this.client);
completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this.client);
}

export namespace Chat {
export import Completions = API.Completions;
export import ChatCompletion = API.ChatCompletion;
export import ChatCompletionChunk = API.ChatCompletionChunk;
export import ChatCompletionMessage = API.ChatCompletionMessage;
export import ChatCompletionMessageParam = API.ChatCompletionMessageParam;
export import ChatCompletionRole = API.ChatCompletionRole;
export import CreateChatCompletionRequestMessage = API.CreateChatCompletionRequestMessage;
export import ChatCompletionCreateParams = API.ChatCompletionCreateParams;
export import CompletionCreateParams = API.CompletionCreateParams;
export import ChatCompletionCreateParamsNonStreaming = API.ChatCompletionCreateParamsNonStreaming;
export import CompletionCreateParamsNonStreaming = API.CompletionCreateParamsNonStreaming;
export import ChatCompletionCreateParamsStreaming = API.ChatCompletionCreateParamsStreaming;
export import CompletionCreateParamsStreaming = API.CompletionCreateParamsStreaming;
export import Completions = CompletionsAPI.Completions;
export type ChatCompletion = CompletionsAPI.ChatCompletion;
export type ChatCompletionChunk = CompletionsAPI.ChatCompletionChunk;
export type ChatCompletionMessage = CompletionsAPI.ChatCompletionMessage;
export type ChatCompletionMessageParam = CompletionsAPI.ChatCompletionMessageParam;
export type ChatCompletionRole = CompletionsAPI.ChatCompletionRole;
export type CreateChatCompletionRequestMessage = CompletionsAPI.CreateChatCompletionRequestMessage;
export type ChatCompletionCreateParams = CompletionsAPI.ChatCompletionCreateParams;
export type CompletionCreateParams = CompletionsAPI.CompletionCreateParams;
export type ChatCompletionCreateParamsNonStreaming = CompletionsAPI.ChatCompletionCreateParamsNonStreaming;
export type CompletionCreateParamsNonStreaming = CompletionsAPI.CompletionCreateParamsNonStreaming;
export type ChatCompletionCreateParamsStreaming = CompletionsAPI.ChatCompletionCreateParamsStreaming;
export type CompletionCreateParamsStreaming = CompletionsAPI.CompletionCreateParamsStreaming;
}
42 changes: 22 additions & 20 deletions src/resources/chat/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import * as Core from 'openai/core';
import { APIPromise } from 'openai/core';
import { APIResource } from 'openai/resource';
import * as Completions_ from 'openai/resources/completions';
import * as API from './index';
import * as ChatCompletionsAPI from 'openai/resources/chat/completions';
import * as CompletionsAPI from 'openai/resources/completions';
import { Stream } from 'openai/streaming';

export class Completions extends APIResource {
Expand Down Expand Up @@ -67,7 +67,7 @@ export interface ChatCompletion {
/**
* Usage statistics for the completion request.
*/
usage?: Completions_.CompletionUsage;
usage?: CompletionsAPI.CompletionUsage;
}

export namespace ChatCompletion {
Expand All @@ -89,7 +89,7 @@ export namespace ChatCompletion {
/**
* A chat completion message generated by the model.
*/
message: ChatCompletionMessage;
message: ChatCompletionsAPI.ChatCompletionMessage;
}
}

Expand Down Expand Up @@ -140,7 +140,7 @@ export namespace ChatCompletionChunk {
* content was omitted due to a flag from our content filters, or `function_call`
* if the model called a function.
*/
finish_reason: 'stop' | 'length' | 'function_call' | null;
finish_reason: 'stop' | 'length' | 'function_call' | 'content_filter' | null;

/**
* The index of the choice in the list of choices.
Expand All @@ -167,7 +167,7 @@ export namespace ChatCompletionChunk {
/**
* The role of the author of this message.
*/
role?: ChatCompletionRole;
role?: ChatCompletionsAPI.ChatCompletionRole;
}

export namespace Delta {
Expand Down Expand Up @@ -459,8 +459,9 @@ export namespace ChatCompletionCreateParams {
description?: string;
}

export type ChatCompletionCreateParamsNonStreaming = API.ChatCompletionCreateParamsNonStreaming;
export type ChatCompletionCreateParamsStreaming = API.ChatCompletionCreateParamsStreaming;
export type ChatCompletionCreateParamsNonStreaming =
ChatCompletionsAPI.ChatCompletionCreateParamsNonStreaming;
export type ChatCompletionCreateParamsStreaming = ChatCompletionsAPI.ChatCompletionCreateParamsStreaming;
}

/**
Expand Down Expand Up @@ -503,16 +504,17 @@ export interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreat
export type CompletionCreateParamsStreaming = ChatCompletionCreateParamsStreaming;

export namespace Completions {
export import ChatCompletion = API.ChatCompletion;
export import ChatCompletionChunk = API.ChatCompletionChunk;
export import ChatCompletionMessage = API.ChatCompletionMessage;
export import ChatCompletionMessageParam = API.ChatCompletionMessageParam;
export import ChatCompletionRole = API.ChatCompletionRole;
export import CreateChatCompletionRequestMessage = API.CreateChatCompletionRequestMessage;
export import ChatCompletionCreateParams = API.ChatCompletionCreateParams;
export import CompletionCreateParams = API.CompletionCreateParams;
export import ChatCompletionCreateParamsNonStreaming = API.ChatCompletionCreateParamsNonStreaming;
export import CompletionCreateParamsNonStreaming = API.CompletionCreateParamsNonStreaming;
export import ChatCompletionCreateParamsStreaming = API.ChatCompletionCreateParamsStreaming;
export import CompletionCreateParamsStreaming = API.CompletionCreateParamsStreaming;
export type ChatCompletion = ChatCompletionsAPI.ChatCompletion;
export type ChatCompletionChunk = ChatCompletionsAPI.ChatCompletionChunk;
export type ChatCompletionMessage = ChatCompletionsAPI.ChatCompletionMessage;
export type ChatCompletionMessageParam = ChatCompletionsAPI.ChatCompletionMessageParam;
export type ChatCompletionRole = ChatCompletionsAPI.ChatCompletionRole;
export type CreateChatCompletionRequestMessage = ChatCompletionsAPI.CreateChatCompletionRequestMessage;
export type ChatCompletionCreateParams = ChatCompletionsAPI.ChatCompletionCreateParams;
export type CompletionCreateParams = ChatCompletionsAPI.CompletionCreateParams;
export type ChatCompletionCreateParamsNonStreaming =
ChatCompletionsAPI.ChatCompletionCreateParamsNonStreaming;
export type CompletionCreateParamsNonStreaming = ChatCompletionsAPI.CompletionCreateParamsNonStreaming;
export type ChatCompletionCreateParamsStreaming = ChatCompletionsAPI.ChatCompletionCreateParamsStreaming;
export type CompletionCreateParamsStreaming = ChatCompletionsAPI.CompletionCreateParamsStreaming;
}
18 changes: 9 additions & 9 deletions src/resources/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import * as Core from 'openai/core';
import { APIPromise } from 'openai/core';
import { APIResource } from 'openai/resource';
import * as API from './index';
import * as CompletionsAPI from 'openai/resources/completions';
import { Stream } from 'openai/streaming';

export class Completions extends APIResource {
Expand Down Expand Up @@ -276,8 +276,8 @@ export interface CompletionCreateParamsBase {
}

export namespace CompletionCreateParams {
export type CompletionCreateParamsNonStreaming = API.CompletionCreateParamsNonStreaming;
export type CompletionCreateParamsStreaming = API.CompletionCreateParamsStreaming;
export type CompletionCreateParamsNonStreaming = CompletionsAPI.CompletionCreateParamsNonStreaming;
export type CompletionCreateParamsStreaming = CompletionsAPI.CompletionCreateParamsStreaming;
}

export interface CompletionCreateParamsNonStreaming extends CompletionCreateParamsBase {
Expand Down Expand Up @@ -305,10 +305,10 @@ export interface CompletionCreateParamsStreaming extends CompletionCreateParamsB
}

export namespace Completions {
export import Completion = API.Completion;
export import CompletionChoice = API.CompletionChoice;
export import CompletionUsage = API.CompletionUsage;
export import CompletionCreateParams = API.CompletionCreateParams;
export import CompletionCreateParamsNonStreaming = API.CompletionCreateParamsNonStreaming;
export import CompletionCreateParamsStreaming = API.CompletionCreateParamsStreaming;
export type Completion = CompletionsAPI.Completion;
export type CompletionChoice = CompletionsAPI.CompletionChoice;
export type CompletionUsage = CompletionsAPI.CompletionUsage;
export type CompletionCreateParams = CompletionsAPI.CompletionCreateParams;
export type CompletionCreateParamsNonStreaming = CompletionsAPI.CompletionCreateParamsNonStreaming;
export type CompletionCreateParamsStreaming = CompletionsAPI.CompletionCreateParamsStreaming;
}
10 changes: 5 additions & 5 deletions src/resources/edits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import * as Core from 'openai/core';
import { APIResource } from 'openai/resource';
import * as Completions from 'openai/resources/completions';
import * as API from './index';
import * as EditsAPI from 'openai/resources/edits';
import * as CompletionsAPI from 'openai/resources/completions';

export class Edits extends APIResource {
/**
Expand Down Expand Up @@ -37,7 +37,7 @@ export interface Edit {
/**
* Usage statistics for the completion request.
*/
usage: Completions.CompletionUsage;
usage: CompletionsAPI.CompletionUsage;
}

export namespace Edit {
Expand Down Expand Up @@ -104,6 +104,6 @@ export interface EditCreateParams {
}

export namespace Edits {
export import Edit = API.Edit;
export import EditCreateParams = API.EditCreateParams;
export type Edit = EditsAPI.Edit;
export type EditCreateParams = EditsAPI.EditCreateParams;
}
Loading