Skip to main content

$jsapi.chatHistoryInLlmFormat

The $jsapi.chatHistoryInLlmFormat() method returns the history of the dialog between the user and the bot in the current session.

Tovie Platform converts the entire dialog history into a special format for LLMs. For example, you can use the history in the $gpt.createChatCompletion method or the llmRequest reply type.

caution

The method is not available in ECMAScript 6.

Syntax

The method is called without arguments.

$jsapi.chatHistoryInLlmFormat();

Return value

The method returns an array of messages. The history includes user and bot messages from the current session:

[
{
"role": "assistant",
"content": "How can I help you?"
},
{
"role": "user",
"content": "Recommend a movie"
},
{
"role": "assistant",
"content": "What genre?"
},
{
"role": "user",
"content": "Comedy"
}
]

Here:

  • role is the role of the participant:

    • user is the user.

    • assistant is the Tovie Platform bot.

      note

      Tovie Platform converts the entire dialog history into a special format for LLMs. All bot messages have the assistant role, even if the bot did not use an LLM to respond.

  • content is the text of the message.

How to use

You can pass the history, for example, if you use llmRequest in the phone channel:

state: NoMatch
event!: noMatch
script:
$response.replies = $response.replies || []
$response.replies.push({
type: "llmRequest",
provider: "MLP_OPEN_AI",
model: "gpt-4o",
tokenSecret: "MY_LLM_TOKEN",
// History will be sent to LLM
messages: $jsapi.chatHistoryInLlmFormat()
});