Skip to main content

Completion API

All the following functions, types, interfaces are exported by the library.

badreftest

complete function

Gets the completion for a piece of text.

Signature:

function complete(options: CompletionOptions): Promise<Result<{
completion: string;
}, RequestError>>;

Parameters

ParameterType
optionsCompletionOptions

Returns:

Promise<Result<{ completion: string; }, RequestError>>

completeStream function

Gets a stream of completions for a piece of text.

Signature:

function completeStream(options: CompletionOptions): Promise<Result<AsyncGenerator<{
completion: string;
}>, RequestError>>;

Parameters

ParameterType
optionsCompletionOptions

Returns:

Promise<Result<AsyncGenerator<{ completion: string; }>, RequestError>>

completeMultipleChoices function

Gets multiple completions for a piece of text.

Signature:

declare function completeMultipleChoices(options: CompletionMultipleChoicesOptions): Promise<Result<{
choices: Array<{
completion: string;
}>;
}, RequestError>>;

Parameters

ParameterTypeDescription
optionsCompletionMultipleChoicesOptions

Returns:

Promise<Result<{ choices: Array<{ completion: string; }>; }, RequestError>>

CompletionOptions

Options for completion request

Signature:

interface CompletionOptions 

Properties

PropertyTypeDescription
extraParams?Record<string, unknown>(Optional) Allows extra model specific parameters. Consult with the documentation for which parameters are available for each model.
maxOutputTokens?number(Optional) The maximum number of tokens generated in the completion. The absolute maximum value is limited by model's context size.
modelCompletionModelSpecifies the model to use
promptstringThe string/text to complete
temperature?number(Optional) Sampling temperature between 0 and 1. The higher the value, the more likely the model will produce a completion that is more creative and imaginative.

CompletionMultipleChoicesOptions

Signature:

interface CompletionMultipleChoicesOptions extends CompletionOptions 

Extends: CompletionOptions

Properties

PropertyTypeDescription
choicesCountnumberNumber of completions to generate. Minimum 1, the maximum depends on the model, the returned choices will be automatically adjusted to fit the model. You should not treat this as a guarantee, what you will get is a number of choices upto choicesCount.

CompletionModel

Available models for text completion

Signature:

type CompletionModel = 'text-bison';
Was this helpful?