Skip to main content

Chat API

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

chat function

Gets a single chat message completion for a conversation.

Signature:

function chat(options: ChatOptions): Promise<
Result<
{
message: ChatMessage;
},
RequestError
>
>;

Parameters

ParameterType
optionsChatOptions

Returns:

Promise<Result<{ message: ChatMessage }, RequestError>>

chatStream function

Gets a single chat message completion for a conversation. The result contains an iterator of messages, please note that this would be a *single message* that has the contents chunked up.

Signature:

function chatStream(options: ChatOptions): Promise<
Result<
AsyncGenerator<{
message: ChatMessage;
}>,
RequestError
>
>;

Parameters

ParameterType
optionsChatOptions

Returns:

Promise<Result<AsyncGenerator<{ message: ChatMessage; }>, RequestError>>

chatMultipleChoices function

Gets multiple chat completions for a conversation.

Signature:

function chatMultipleChoices(options: ChatMultipleChoicesOptions): Promise<
Result<
{
choices: Array<{
message: ChatMessage;
}>;
},
RequestError
>
>;

Parameters

ParameterType
optionsChatMultipleChoicesOptions

Returns:

Promise<Result<{ choices: Array<{ message: ChatMessage }> }, RequestError>>

ChatOptions

Options for chat request

Signature:

interface ChatOptions

Properties

PropertyTypeDescription
messagesArray<ChatMessage>Previous messages in the conversation.
modelChatModelSpecifies the model to use.
contextstringThis can be instructions for the model on how it should respond or information it uses to generate a response. This can also be used to restrict the model to a specific topic.
temperaturenumber(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.
maxOutputTokens?number(Optional) The maximum number of tokens generated in the chat completion. The absolute maximum value is limited by model's context size.
extraParams?Record<string, unknown>(Optional) Allows extra model specific parameters. Consult with the provider documentation for which parameters are available for each model.

ChatMultipleChoicesOptions

Signature:

interface ChatMultipleChoicesOptions extends ChatOptions

Extends: ChatOptions

Properties

PropertyTypeDescription
choicesCountnumberNumber of chat 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 up to choicesCount.

ChatMessage

A message in a chat conversation

Signature:

interface ChatMessage

Properties

PropertyTypeDescription
authorstringThe author of the message. Typically the completion infers the author from examples and previous messages provided in the options.
contentstringThe content of the message

ChatModel

Available models for chat completion

Signature:

type ChatModel = "chat-bison";
Was this helpful?