Skip to main content

Class: AbstractOpenAICompletionModel<SETTINGS>

Abstract completion model that calls an API that is compatible with the OpenAI completions API.

See

https://platform.openai.com/docs/api-reference/completions/create

Type parameters

NameType
SETTINGSextends AbstractOpenAICompletionModelSettings

Hierarchy

Accessors

modelInformation

get modelInformation(): ModelInformation

Returns

ModelInformation

Inherited from

AbstractModel.modelInformation

Defined in

packages/modelfusion/src/model-function/AbstractModel.ts:17


settingsForEvent

get settingsForEvent(): Partial<SETTINGS>

Returns

Partial<SETTINGS>

Inherited from

AbstractModel.settingsForEvent

Defined in

packages/modelfusion/src/model-function/AbstractModel.ts:24

Constructors

constructor

new AbstractOpenAICompletionModel<SETTINGS>(settings): AbstractOpenAICompletionModel<SETTINGS>

Type parameters

NameType
SETTINGSextends AbstractOpenAICompletionModelSettings

Parameters

NameType
settingsSETTINGS

Returns

AbstractOpenAICompletionModel<SETTINGS>

Overrides

AbstractModel&lt;SETTINGS&gt;.constructor

Defined in

packages/modelfusion/src/model-provider/openai/AbstractOpenAICompletionModel.ts:47

Methods

callAPI

callAPI<RESULT>(prompt, callOptions, options): Promise<RESULT>

Type parameters

Name
RESULT

Parameters

NameType
promptstring
callOptionsFunctionCallOptions
optionsObject
options.responseFormatOpenAITextResponseFormatType<RESULT>

Returns

Promise<RESULT>

Defined in

packages/modelfusion/src/model-provider/openai/AbstractOpenAICompletionModel.ts:51


doGenerateTexts

doGenerateTexts(prompt, options): Promise<{ rawResponse: { choices: { finish_reason?: null | "length" | "stop" | "content_filter" ; index: number ; logprobs?: any ; text: string }[] ; created: number ; id: string ; model: string ; object: "text_completion" ; system_fingerprint?: string ; usage: { completion_tokens: number ; prompt_tokens: number ; total_tokens: number } } ; textGenerationResults: { finishReason: TextGenerationFinishReason ; text: string = choice.text }[] ; usage: { completionTokens: number = rawResponse.usage.completion_tokens; promptTokens: number = rawResponse.usage.prompt_tokens; totalTokens: number = rawResponse.usage.total_tokens } }>

Parameters

NameType
promptstring
optionsFunctionCallOptions

Returns

Promise<{ rawResponse: { choices: { finish_reason?: null | "length" | "stop" | "content_filter" ; index: number ; logprobs?: any ; text: string }[] ; created: number ; id: string ; model: string ; object: "text_completion" ; system_fingerprint?: string ; usage: { completion_tokens: number ; prompt_tokens: number ; total_tokens: number } } ; textGenerationResults: { finishReason: TextGenerationFinishReason ; text: string = choice.text }[] ; usage: { completionTokens: number = rawResponse.usage.completion_tokens; promptTokens: number = rawResponse.usage.prompt_tokens; totalTokens: number = rawResponse.usage.total_tokens } }>

Defined in

packages/modelfusion/src/model-provider/openai/AbstractOpenAICompletionModel.ts:111


doStreamText

doStreamText(prompt, options): Promise<AsyncIterable<Delta<{ choices: { finish_reason?: null | "length" | "stop" | "content_filter" ; index: number ; text: string }[] ; created: number ; id: string ; model: string ; object: "text_completion" ; system_fingerprint?: string }>>>

Parameters

NameType
promptstring
optionsFunctionCallOptions

Returns

Promise<AsyncIterable<Delta<{ choices: { finish_reason?: null | "length" | "stop" | "content_filter" ; index: number ; text: string }[] ; created: number ; id: string ; model: string ; object: "text_completion" ; system_fingerprint?: string }>>>

Defined in

packages/modelfusion/src/model-provider/openai/AbstractOpenAICompletionModel.ts:160


extractTextDelta

extractTextDelta(delta): undefined | string

Parameters

NameType
deltaunknown

Returns

undefined | string

Defined in

packages/modelfusion/src/model-provider/openai/AbstractOpenAICompletionModel.ts:166


restoreGeneratedTexts

restoreGeneratedTexts(rawResponse): Object

Parameters

NameType
rawResponseunknown

Returns

Object

NameType
rawResponse{ choices: { finish_reason?: null | "length" | "stop" | "content_filter" ; index: number ; logprobs?: any ; text: string }[] ; created: number ; id: string ; model: string ; object: "text_completion" ; system_fingerprint?: string ; usage: { completion_tokens: number ; prompt_tokens: number ; total_tokens: number } }
rawResponse.choices{ finish_reason?: null | "length" | "stop" | "content_filter" ; index: number ; logprobs?: any ; text: string }[]
rawResponse.creatednumber
rawResponse.idstring
rawResponse.modelstring
rawResponse.object"text_completion"
rawResponse.system_fingerprint?string
rawResponse.usage{ completion_tokens: number ; prompt_tokens: number ; total_tokens: number }
rawResponse.usage.completion_tokensnumber
rawResponse.usage.prompt_tokensnumber
rawResponse.usage.total_tokensnumber
textGenerationResults{ finishReason: TextGenerationFinishReason ; text: string = choice.text }[]
usage{ completionTokens: number = rawResponse.usage.completion_tokens; promptTokens: number = rawResponse.usage.prompt_tokens; totalTokens: number = rawResponse.usage.total_tokens }
usage.completionTokensnumber
usage.promptTokensnumber
usage.totalTokensnumber

Defined in

packages/modelfusion/src/model-provider/openai/AbstractOpenAICompletionModel.ts:119


withJsonOutput

withJsonOutput(): this

Returns

this

Defined in

packages/modelfusion/src/model-provider/openai/AbstractOpenAICompletionModel.ts:178


withSettings

withSettings(additionalSettings): this

Parameters

NameType
additionalSettingsPartial<SETTINGS>

Returns

this

Inherited from

AbstractModel.withSettings

Defined in

packages/modelfusion/src/model-function/AbstractModel.ts:26

Properties

modelName

Readonly Abstract modelName: null | string

Inherited from

AbstractModel.modelName

Defined in

packages/modelfusion/src/model-function/AbstractModel.ts:14


provider

Readonly Abstract provider: string

Inherited from

AbstractModel.provider

Defined in

packages/modelfusion/src/model-function/AbstractModel.ts:13


settings

Readonly settings: SETTINGS

Inherited from

AbstractModel.settings

Defined in

packages/modelfusion/src/model-function/AbstractModel.ts:7