CLlmClient::TrimHistory Method  
 
LONG TrimHistory(
  LONG nMessageCount,  
  LONG nMaxTokens  
);

The TrimHistory method removes older messages from the conversation history for the current client session.

Parameters

nMessageCount
The number of messages to remove from the beginning of the conversation history. If this value is zero, messages are only removed if required by the nMaxTokens parameter. If this value is equal to or greater than the number of messages in the history, the entire history is cleared.
nMaxTokens
The maximum number of input tokens that should remain in the conversation history. If this value is zero, token usage is not checked. If the current history exceeds this value, additional older messages may be deleted until the total input token count is below the specified limit.

Return Value

If the method succeeds, the return value is the number of messages deleted from the conversation history. If the method fails, the return value is LLM_ERROR. To get extended error information, call GetLastError.

If no messages are available to delete, the return value is zero.

Remarks

The TrimHistory method removes messages from the beginning of the conversation history. This can be used to reduce memory usage, discard older context, or limit how much previous conversation text is included with future requests.

The nMessageCount parameter specifies the minimum number of older messages to remove. If nMaxTokens is greater than zero, the method also checks the total number of input tokens currently stored in the message history. If the token count exceeds the specified limit, additional older messages will be removed until the total input token count is below the specified threshold.

When both parameters are specified, the method may remove more messages than requested by nMessageCount to reduce the token count below the limit specified by nMaxTokens. The return value always indicates the actual number of messages removed.

If the number of messages to remove is equal to or greater than the number of messages currently stored, the entire conversation history is cleared. This is equivalent to calling ClearHistory.

This method only removes the local message and response history maintained by the client session. It does not change the current provider, model, system prompt, connection settings or cached provider metadata.

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

See Also