CLlmClient::GetFirstMessage Method  
 
BOOL GetFirstMessage(
  LPLLM_MESSAGE lpMessage,  
  LPLLM_RESPONSE lpResponse  
);

The GetFirstMessage method returns the first available message in the conversation history.

Parameters

lpMessage
A pointer to an LLM_MESSAGE structure that receives information about the client request. This parameter may be NULL, in which case no message information is returned.
lpResponse
A pointer to an LLM_RESPONSE structure that receives information about the server response. This parameter may be NULL, in which case no response information is returned.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call GetLastError. If there are no messages in the client history, the error code will be set to ST_ERROR_END_OF_MESSAGES.

Remarks

The GetFirstMessage method retrieves the first message and associated response from the client conversation history. This method is typically used in conjunction with the GetNextMessage method to enumerate all messages in the session.

If the lpMessage and/or lpResponse parameters are specified, their respective structures must be initialized with the dwSize member set to the size of the structure before calling this method. This enables the library to validate the structure version and maintain compatibility with future releases.

Messages are returned in chronological order, beginning with the oldest message in the client history. New messages are always appended to the end of the history, and if the history is trimmed, older messages are removed first. The order of messages is stable and reflects the sequence in which they were submitted.

If there are no messages in the client history, the method fails and sets the error code to ST_ERROR_END_OF_MESSAGES. Applications can use this condition to determine that no messages are available for enumeration.

Either the lpMessage or lpResponse parameter may be NULL if only one type of information is required. At least one of these parameters must be specified. If both parameters are NULL, the method fails and sets the error code to ST_ERROR_INVALID_PARAMETER.

Example

// Enumerate the message history and display message details
LLM_MESSAGE clientMessage = { sizeof(LLM_MESSAGE), 0 };
LLM_RESPONSE serverResponse = { sizeof(LLM_RESPONSE), 0 };

if (llmClient.GetFirstMessage(&clientMessage, &serverResponse))
{
    do
    {
        _tprintf(_T("\nMessage %u\n"), clientMessage.dwMessageId);
        _tprintf(_T("  Input Tokens:    %u\n"), clientMessage.nInputTokens);
        _tprintf(_T("  Content Length:  %u\n"), clientMessage.nContentLength);
        _tprintf(_T("  Content:         \"%s\"\n"), clientMessage.lpszContent);

        _tprintf(_T("\nResponse %u\n"), serverResponse.dwMessageId);
        _tprintf(_T("  Elapsed:         %u ms\n"), serverResponse.dwElapsed);
        _tprintf(_T("  Output Tokens:   %u\n"), serverResponse.nOutputTokens);
        _tprintf(_T("  Content Length:  %u\n"), serverResponse.nContentLength);
        _tprintf(_T("  Content:         \"%s\"\n"), serverResponse.lpszContent);
        _tprintf(_T("  Response ID:     %s\n"), (serverResponse.lpszResponseId ? serverResponse.lpszResponseId : _T("None")));
        _tprintf(_T("  Model Name:      %s\n"), (serverResponse.lpszModelName ? serverResponse.lpszModelName : _T("None")));
        _tprintf(_T("  Status Text:     %s\n"), (serverResponse.lpszStatusText ? serverResponse.lpszStatusText : _T("None")));
    }
    while (llmClient.GetNextMessage(&clientMessage, &serverResponse));
}

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