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.
Create an instance of the Chat class to begin:
const chat = new app.Chat();
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
.
Model Name | Code |
---|---|
GPT-4 |
|
GPT-4 0613 |
|
GPT-4 32k |
|
GPT-4 32k 0613 |
|
GPT-3.5 Turbo |
|
GPT-3.5 Turbo 0613 |
|
GPT-3.5 Turbo 16k |
|
GPT-3.5 Turbo 16k 0613 |
|
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);
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.
Use the send
method to send the messages and get a response:
chat.send().then(response => {
console.log(response.data.text);
});