UNPKG

gpt-token-utils

Version:

Isomorphic utilities for GPT-3 tokenization and prompt building.

101 lines (100 loc) 3.02 kB
/** * @copyright Sister Software. All rights reserved. * @author Teffen Ellis, et al. * @license * See LICENSE file in the project root for full license information. */ /** * The IDs of available model families. */ export declare const ModelFamilyIDs: { readonly Ada: "ada"; readonly Babbage: "babbage"; readonly Curie: "curie"; readonly Davinci: "davinci"; readonly ChatGPT: "chat-gpt"; readonly GPT4: "gpt-4"; readonly GPT4_32K: "gpt-4-32k"; }; /** * A model family is a group of models that share a common lineage or training data. */ export interface ModelFamily { familyID: string; /** * The number of tokens that can be used with this model in a single request. */ tokenLimit: number; /** * The number of spaces to merge into a single token. * * Codex models use a different set of encodings that handle whitespace more efficiently. */ mergeSpaces: number; pricing: ModelPricing; /** * The IDs of available models, matches the IDs used in the OpenAI API. */ modelIDs: string[]; /** * The ID of the preferred model in this family. */ preferredModelID?: string; } export type ModelPricingTypes = 'usage' | 'fineTunedUsage' | 'fineTunedTraining' | 'prompt' | 'completion'; /** * The pricing of a model in US dollars. * @see https://openai.com/pricing */ export interface ModelPricing { /** * The price of model usage per 1000 tokens. */ usage: number | null; /** * The price of fine-tuned model usage per 1000 tokens. */ fineTunedUsage: number | null; /** * The price of fine-tuned model training per 1000 tokens. */ fineTunedTraining: number | null; /** * The price of usage for the prompt endpoint per 1000 tokens. */ prompt: number | null; /** * The price of usage for the completion endpoint per 1000 tokens. */ completion: number | null; } export interface GetModelFamilyFn { ( /** * The ID of a model within a family, e.g. `"text-davinci-003"` * @returns The family that the model belongs to. */ modelID: string): ModelFamily; ( /** * The ID of a model family, e.g. `"davinci"` * @returns The family associated with the ID. */ familyID: string): ModelFamily; ( /** * A model family. This is useful for when you already have a model family object. * @returns The same family object that was passed in. */ modelFamily: ModelFamily): ModelFamily; (input: string | ModelFamily): ModelFamily; } export declare class ModelFamiliesMap { protected _familyMap: Map<string, ModelFamily>; protected _modelToFamilyMap: Map<string, ModelFamily>; addFamily(family: ModelFamily): void; getFamilyByFamilyID(familyID: string): ModelFamily | undefined; getFamilyByModelID(modelID: string): ModelFamily | undefined; get: GetModelFamilyFn; isModelInFamily(modelID: string, familyID: string): boolean; }