LlmImportHistory Function  
 
BOOL WINAPI LlmImportHistory(
  HCLIENT hClient,  
  LPCTSTR lpszFileName,  
  LONG nMessageCount,  
  LPLONG lpnImported  
);

The LlmImportHistory function imports a conversation history from a JSON-formatted file.

Parameters

hClient
A handle to the client session.
lpszFileName
A pointer to a null-terminated string which specifies the name of the import file. This parameter cannot be NULL or a zero-length string.
nMessageCount
The number of the most recent messages and responses which should be imported. If this value is zero, all messages in the file are imported.
lpnImported
A pointer to an integer which will receive the number of messages which were imported when the function returns. If this information is not required, this parameter may be NULL.

Return Value

If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To get extended error information, call LlmGetLastError.

Remarks

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.

Example

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);
}
        

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csllmv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also

LlmClearHistory, LlmExportHistory, LlmGetMessageCount, LlmSetHistorySize