Chat Class

The Chat class provides a simple, flexible way to execute chat completions to LLM. You can create instances of this class, set a model, adjust the temperature, add messages, and send the message to get a text response.

Creating an Instance

Create an instance of the Chat class to begin:

const chat = new app.Chat();

Setting a Model

You can set the model for the chat instance by calling the setModel method:

chat.setModel('gpt-3.5-turbo');

By default, the model is set to gpt-3.5-turbo.

Available models

Model Name Code
GPT-4
gpt-4
GPT-4 0613
gpt-4-0613
GPT-4 32k
gpt-4-32k
GPT-4 32k 0613
gpt-4-32k-0613
GPT-3.5 Turbo
gpt-3.5-turbo
GPT-3.5 Turbo 0613
gpt-3.5-turbo-0613
GPT-3.5 Turbo 16k
gpt-3.5-turbo-16k
GPT-3.5 Turbo 16k 0613
gpt-3.5-turbo-16k-0613

Setting Temperature

The temperature value is between 0 and 2. A higher value, for example, 0.9, will make the output more random, and the lower values, like 0.2, will make it more focused and deterministic.

Set the temperature by calling the setTemperature method:

chat.setTemperature(0.7);

Adding a Message

Use the addMessage method to add a message to the chat:

chat.addMessage('How to be productive?');

You can add messages with placeholders that will be replaced by the corresponding variables:

chat.addMessage('user', 'Translate "{text}" into {language}.', { text: 'Hi', language: 'French' });
        //Translate "Hi" into French.

Sending Messages (Create chat completion)

Use the send method to send the messages and get a response:

chat.send().then(response => {
        console.log(response.data.text);
        });