The LlmImportHistory function imports a previously exported
conversation history file and restores it as the active conversation
history for the client session. Imported messages and responses become
part of the current session history and are treated the same as messages
generated during the current session.
Importing conversation history replaces the existing history associated
with the client session. This function does not merge imported messages
with the current conversation history or append them to the existing
session. It is not necessary for your application to call
LlmClearHistory prior to calling this function.
If the lpszFileName parameter specifies a directory or
device name, the function 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. The file must exist
and the current process must have permission to read the file.
If the nMessageCount parameter is non-zero, only the most
recent messages and responses in the import file are restored. If the
specified count exceeds the number of available messages in the file,
all available messages are imported. If the total number of messages
to be imported exceeds the current history size, the function will
only import the most recent messages up to that limit. For example, if
the import file contains 20 messages and the current history size is
15, the most recent 15 messages will be imported.
The import file must contain valid UTF-8 encoded JSON data in a
format compatible with the LlmExportHistory function. If the
file does not appear to contain a valid conversation history, the
import operation fails before the current session history is cleared.
After the JSON data has been successfully parsed, the current session
history is cleared before the imported messages and responses are added
to the client session. If an error occurs while processing imported
messages or responses, the previous conversation history cannot be
restored and partial import data may remain in the current session.
If the import file contains malformed message or response data,
the LlmGetLastError function will return
ST_ERROR_INVALID_MESSAGE_FORMAT.
Because imported history files may contain sensitive or private
information, applications should take reasonable precautions to protect
them. Applications which allow users to import conversation history
should consider warning users before importing untrusted or unknown
files.
LONG nImported = 0;
// Replace the current conversation history with the
// messages stored in the import file
if (LlmImportHistory(hClient,
_T("%USERPROFILE%\\Documents\\conversation.json"),
0,
&nImported))
{
_tprintf(_T("Imported %ld messages\n"), nImported);
}
else
{
DWORD dwError = LlmGetLastError();
_tprintf(_T("Unable to import conversation history, error 0x%08lX\n"), dwError);
}