ExportHistory Method  
 

The ExportHistory method exports the conversation history to a JSON-formatted file.

Syntax

object.ExportHistory( FileName, [MessageCount], [Exported] )

Parameters

FileName
A string which specifies the name of the file to be created or overwritten. The string may contain environment variables in the path by enclosing the variable name in percent symbols. This parameter is required and cannot be an empty string.
MessageCount
An optional Integer parameter which specifies the number of recent messages and responses which should be exported. If this parameter is omitted or the value is zero, all messages in the current conversation are exported.
Exported
An optional Integer parameter passed by reference which will receive the number of messages which were exported when the method returns. If this information is not required, this parameter may be omitted.

Return Value

A value of True is returned if the method succeeds. If the method fails, it will return False and the LastError property will contain the error code.

The ExportHistory method exports the current conversation history associated with the client session to a JSON-formatted file. The exported history includes both client messages and model responses stored in the current session history.

This method only exports conversation history currently stored in memory for the client session. It cannot be used if the conversation history has been disabled by setting the history size to zero.

If the FileName parameter specifies a directory or device name, the method will fail. It is permitted to use environment variables in the file name by surrounding the variable name with the percent symbol. If the file name contains any leading or trailing space characters, they will be removed. If the file already exists, the current process must have permission to overwrite the file. If the file has the read-only attribute set, the method will fail and the last error code will be set to tErrorAccessDenied.

If the MessageCount parameter is non-zero, the method exports only the most recent messages in the conversation history. Older messages are skipped. If the specified count exceeds the number of available messages, all available messages are exported. To export all messages in the conversation history, you can simply omit this parameter.

The exported file uses UTF-8 encoded JSON text and is intended to be human-readable. Applications should not depend on the exact formatting or internal structure of the file because future versions of the library may include additional metadata or fields. To help prevent data loss, the method writes the exported history to a temporary file and only replaces the destination file after the export operation has completed successfully. If the export fails, any existing file specified by the lpszFileName parameter is left unchanged.

The exported file is intended to provide a simple mechanism for persisting conversation state between application sessions. A previously exported history file can later be restored using the ImportHistory method.

Important: The conversation history may contain sensitive or private information. Applications should take reasonable precautions to protect exported history files, such as limiting access permissions or encrypting the exported file. Applications which allow users to export conversation history should consider informing users that the exported file may contain private information.

Example

Dim strFileName As String
Dim nExported As Long

strFileName = "%USERPROFILE%\Documents\conversation.json"

' Export the complete conversation history to a JSON file
If LlmClient1.ExportHistory(strFileName, 0, &nExported)) Then
    MsgBox "Exported " + CStr(nExported) + " messages", vbInformation
Else
    MsgBox "Unable to export the conversation history" + vbCrLf + _
           LlmClient1.LastErrorString, vbExclamation
End If

See Also

MessageCount Property, ClearHistory Method, ImportHistory Method, TrimHistory Method