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
Name | Type |
---|---|
SETTINGS | extends AbstractOpenAICompletionModelSettings |
Hierarchy
-
AbstractModel
<SETTINGS
>↳
AbstractOpenAICompletionModel
Accessors
modelInformation
• get
modelInformation(): ModelInformation
Returns
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
Name | Type |
---|---|
SETTINGS | extends AbstractOpenAICompletionModelSettings |
Parameters
Name | Type |
---|---|
settings | SETTINGS |
Returns
AbstractOpenAICompletionModel
<SETTINGS
>
Overrides
AbstractModel<SETTINGS>.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
Name | Type |
---|---|
prompt | string |
callOptions | FunctionCallOptions |
options | Object |
options.responseFormat | OpenAITextResponseFormatType <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
Name | Type |
---|---|
prompt | string |
options | FunctionCallOptions |
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
Name | Type |
---|---|
prompt | string |
options | FunctionCallOptions |
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
Name | Type |
---|---|
delta | unknown |
Returns
undefined
| string
Defined in
packages/modelfusion/src/model-provider/openai/AbstractOpenAICompletionModel.ts:166
restoreGeneratedTexts
▸ restoreGeneratedTexts(rawResponse
): Object
Parameters
Name | Type |
---|---|
rawResponse | unknown |
Returns
Object
Name | Type |
---|---|
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.created | number |
rawResponse.id | string |
rawResponse.model | string |
rawResponse.object | "text_completion" |
rawResponse.system_fingerprint? | string |
rawResponse.usage | { completion_tokens : number ; prompt_tokens : number ; total_tokens : number } |
rawResponse.usage.completion_tokens | number |
rawResponse.usage.prompt_tokens | number |
rawResponse.usage.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 } |
usage.completionTokens | number |
usage.promptTokens | number |
usage.totalTokens | number |
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
Name | Type |
---|---|
additionalSettings | Partial <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